From 539ca29f7b1e52b2aa4219b82e87f0f45a82ac73 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Sun, 27 Oct 2024 18:48:30 +0200 Subject: [PATCH 01/29] Init --- src/spox/_adapt.py | 8 +- src/spox/_build.py | 28 +- src/spox/_debug.py | 4 +- src/spox/_exceptions.py | 2 +- src/spox/_fields.py | 38 +- src/spox/_function.py | 20 +- src/spox/_future.py | 58 +- src/spox/_graph.py | 76 +- src/spox/_inline.py | 6 +- src/spox/_internal_op.py | 42 +- src/spox/_node.py | 68 +- src/spox/_public.py | 58 +- src/spox/_scope.py | 14 +- src/spox/_standard.py | 24 +- src/spox/_value_prop.py | 2 +- src/spox/_var.py | 192 +-- src/spox/opset/ai/onnx/v17.py | 2139 +++++++++++++++++----------- src/spox/opset/ai/onnx/v18.py | 234 ++- src/spox/opset/ai/onnx/v19.py | 215 +-- src/spox/opset/ai/onnx/v20.py | 147 +- tools/generate_opset.py | 2 +- tools/templates/class.jinja2 | 12 +- tools/templates/construct.jinja2 | 10 +- tools/templates/constructor.jinja2 | 6 +- 24 files changed, 2072 insertions(+), 1333 deletions(-) diff --git a/src/spox/_adapt.py b/src/spox/_adapt.py index 32017dab..0d854822 100644 --- a/src/spox/_adapt.py +++ b/src/spox/_adapt.py @@ -15,7 +15,7 @@ from ._schemas import SCHEMAS from ._scope import Scope from ._utils import from_array -from ._var import Var +from ._var import VarInfo def adapt_node( @@ -23,7 +23,7 @@ def adapt_node( proto: onnx.NodeProto, source_version: int, target_version: int, - var_names: dict[Var, str], + var_names: dict[VarInfo, str], ) -> Optional[list[onnx.NodeProto]]: if source_version == target_version: return None @@ -71,7 +71,7 @@ def adapt_inline( node: _Inline, protos: list[onnx.NodeProto], target_opsets: dict[str, int], - var_names: dict[Var, str], + var_names: dict[VarInfo, str], node_name: str, ) -> list[onnx.NodeProto]: source_version = max({v for d, v in node.opset_req if d in ("", "ai.onnx")}) @@ -99,7 +99,7 @@ def adapt_best_effort( node: Node, protos: list[onnx.NodeProto], opsets: dict[str, int], - var_names: dict[Var, str], + var_names: dict[VarInfo, str], node_names: dict[Node, str], ) -> Optional[list[onnx.NodeProto]]: if isinstance(node, _Inline): diff --git a/src/spox/_build.py b/src/spox/_build.py index 60c544a0..60064da1 100644 --- a/src/spox/_build.py +++ b/src/spox/_build.py @@ -21,7 +21,7 @@ from ._node import Node from ._scope import Scope from ._traverse import iterative_dfs -from ._var import Var +from ._var import VarInfo if TYPE_CHECKING: from ._graph import Graph @@ -58,11 +58,11 @@ class BuildResult: scope: Scope nodes: dict[Node, tuple[onnx.NodeProto, ...]] - arguments: tuple[Var, ...] - results: tuple[Var, ...] + arguments: tuple[VarInfo, ...] + results: tuple[VarInfo, ...] opset_req: set[tuple[str, int]] functions: tuple["_function.Function", ...] - initializers: dict[Var, np.ndarray] + initializers: dict[VarInfo, np.ndarray] class Builder: @@ -93,7 +93,7 @@ class ScopeTree: """ Structure representing the tree of scopes, which are identified with the respective graphs. - This structure is the base of the least-enclosing-scope algorithm. Every value (Var), and hence + This structure is the base of the least-enclosing-scope algorithm. Every value (VarInfo), and hence the responsible Node - up to its (Python object) identity may appear in multiple scopes, but it should best-cased be computed only once in the ONNX graph, same as in the Python source code. @@ -164,12 +164,12 @@ def lca(self, a: "Graph", b: "Graph") -> "Graph": graphs: set["Graph"] graph_topo: list["Graph"] # Arguments, results - arguments_of: dict["Graph", list[Var]] - results_of: dict["Graph", list[Var]] + arguments_of: dict["Graph", list[VarInfo]] + results_of: dict["Graph", list[VarInfo]] source_of: dict["Graph", Node] # Arguments found by traversal - all_arguments_in: dict["Graph", set[Var]] - claimed_arguments_in: dict["Graph", set[Var]] + all_arguments_in: dict["Graph", set[VarInfo]] + claimed_arguments_in: dict["Graph", set[VarInfo]] # Scopes scope_tree: ScopeTree scope_own: dict["Graph", list[Node]] @@ -203,8 +203,8 @@ def build_main(self) -> BuildResult: @staticmethod def get_intro_results( - request_results: dict[str, Var], set_names: bool - ) -> list[Var]: + request_results: dict[str, VarInfo], set_names: bool + ) -> list[VarInfo]: """ Helper method for wrapping all requested results into a single Introduce and possibly naming them. @@ -218,7 +218,7 @@ def get_intro_results( var._rename(key) return vars - def discover(self, graph: "Graph") -> tuple[set[Var], set[Var]]: + def discover(self, graph: "Graph") -> tuple[set[VarInfo], set[VarInfo]]: """ Run the discovery step of the build process. Resolves arguments and results for the involved graphs. Finds the topological ordering between (sub)graphs and sets their owners (nodes of which they are attributes). @@ -410,7 +410,7 @@ def compile_graph( self, graph: "Graph", scope: Scope, prefix: str = "" ) -> BuildResult: """ - Compile a given Graph into a BuildResult. Handles naming of all the Vars/Nodes and only adds Nodes to a + Compile a given Graph into a BuildResult. Handles naming of all the VarInfos/Nodes and only adds Nodes to a Graph that should be present in the respective GraphProto. The passed Scope object is aware of values already available in the outer scope and may be the source of errors if the build fails. @@ -432,7 +432,7 @@ def compile_graph( # A bunch of model metadata we're collecting opset_req: set[tuple[str, int]] = set() functions: list[_function.Function] = [] - initializers: dict[Var, np.ndarray] = {} + initializers: dict[VarInfo, np.ndarray] = {} # Add arguments to our scope for arg in self.arguments_of[graph]: diff --git a/src/spox/_debug.py b/src/spox/_debug.py index 81141928..1942bfb9 100644 --- a/src/spox/_debug.py +++ b/src/spox/_debug.py @@ -4,7 +4,7 @@ import sys from contextlib import contextmanager -from spox._var import Var +from spox._var import VarInfo # If `STORE_TRACEBACK` is `True` any node created will store a traceback for its point of creation. STORE_TRACEBACK = False @@ -36,7 +36,7 @@ def show_construction_tracebacks(debug_index): if -1 in found: del found[-1] for name, obj in reversed(found.values()): - if isinstance(obj, Var): + if isinstance(obj, VarInfo): if not obj: continue node = obj._op diff --git a/src/spox/_exceptions.py b/src/spox/_exceptions.py index fdca7eb7..01e72906 100644 --- a/src/spox/_exceptions.py +++ b/src/spox/_exceptions.py @@ -8,7 +8,7 @@ class InferenceWarning(Warning): - """Warning related to partial typing of Variables. + """Warning related to partial typing of VarInfoiables. Incomplete type information may lead to reduced code safety or failure to build the model. The most common underlying cause for diff --git a/src/spox/_fields.py b/src/spox/_fields.py index d02ca742..7bcd4227 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -8,7 +8,7 @@ from typing import Any, Optional, Union from ._attributes import Attr -from ._var import Var +from ._var import VarInfo @dataclass @@ -32,19 +32,19 @@ class VarFieldKind(enum.Enum): @dataclass -class BaseVars(BaseFields): +class BaseVarInfos(BaseFields): def __post_init__(self): # Check if passed fields are of the appropriate types based on field kinds for field in dataclasses.fields(self): value = getattr(self, field.name) field_type = self._get_field_type(field) if field_type == VarFieldKind.SINGLE: - if not isinstance(value, Var): - raise TypeError(f"Field expected Var, got: {type(value)}.") + if not isinstance(value, VarInfo): + raise TypeError(f"Field expected VarInfo, got: {type(value)}.") elif field_type == VarFieldKind.OPTIONAL: - if value is not None and not isinstance(value, Var): + if value is not None and not isinstance(value, VarInfo): raise TypeError( - f"Optional must be Var or None, got: {type(value)}." + f"Optional must be VarInfo or None, got: {type(value)}." ) elif field_type == VarFieldKind.VARIADIC: if not isinstance(value, Iterable): @@ -53,31 +53,31 @@ def __post_init__(self): ) # Cast to tuple to avoid accidental mutation setattr(self, field.name, tuple(value)) - if bad := {type(var) for var in value} - {Var}: + if bad := {type(var) for var in value} - {VarInfo}: raise TypeError( - f"Variadic field must only consist of Vars, got: {bad}." + f"Variadic field must only consist of VarInfos, got: {bad}." ) @classmethod def _get_field_type(cls, field) -> VarFieldKind: """Access the kind of the field (single, optional, variadic) based on its type annotation.""" - if field.type == Var: + if field.type == VarInfo: return VarFieldKind.SINGLE - elif field.type == Optional[Var]: + elif field.type == Optional[VarInfo]: return VarFieldKind.OPTIONAL - elif field.type == Sequence[Var]: + elif field.type == Sequence[VarInfo]: return VarFieldKind.VARIADIC raise ValueError(f"Bad field type: '{field.type}'.") - def _flatten(self) -> Iterable[tuple[str, Optional[Var]]]: + def _flatten(self) -> Iterable[tuple[str, Optional[VarInfo]]]: """Iterate over the pairs of names and values of fields in this object.""" for key, value in self.__dict__.items(): - if value is None or isinstance(value, Var): + if value is None or isinstance(value, VarInfo): yield key, value else: yield from ((f"{key}_{i}", v) for i, v in enumerate(value)) - def __iter__(self) -> Iterator[Optional[Var]]: + def __iter__(self) -> Iterator[Optional[VarInfo]]: """Iterate over the values of fields in this object.""" yield from (v for _, v in self._flatten()) @@ -85,11 +85,11 @@ def __len__(self) -> int: """Count the number of fields in this object (should be same as declared in the class).""" return sum(1 for _ in self) - def get_vars(self) -> dict[str, Var]: - """Return a flat mapping by name of all the Vars in this object.""" + def get_vars(self) -> dict[str, VarInfo]: + """Return a flat mapping by name of all the VarInfos in this object.""" return {key: var for key, var in self._flatten() if var is not None} - def get_fields(self) -> dict[str, Union[None, Var, Sequence[Var]]]: + def get_fields(self) -> dict[str, Union[None, VarInfo, Sequence[VarInfo]]]: """Return a mapping of all fields stored in this object by name.""" return self.__dict__.copy() @@ -107,10 +107,10 @@ def fully_typed(self) -> bool: @dataclass -class BaseInputs(BaseVars): +class BaseInputs(BaseVarInfos): pass @dataclass -class BaseOutputs(BaseVars): +class BaseOutputs(BaseVarInfos): pass diff --git a/src/spox/_function.py b/src/spox/_function.py index 79db4b9b..4bc64a8d 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -14,14 +14,14 @@ from ._internal_op import _InternalNode from ._node import Node, OpType from ._type_system import Type -from ._var import Var +from ._var import VarInfo if TYPE_CHECKING: from . import _graph DEFAULT_FUNCTION_DOMAIN = "spox.default" -ConstructorT = TypeVar("ConstructorT", bound=Callable[..., Iterable[Var]]) +ConstructorT = TypeVar("ConstructorT", bound=Callable[..., Iterable[VarInfo]]) class Function(_InternalNode): @@ -42,7 +42,7 @@ class Function(_InternalNode): via the ``to_onnx_function`` method. """ - func_args: dict[str, Var] + func_args: dict[str, VarInfo] func_attrs: dict[str, _attributes.Attr] func_inputs: BaseInputs func_outputs: BaseOutputs @@ -125,11 +125,13 @@ def to_onnx_function( def _make_function_cls(fun, num_inputs, num_outputs, domain, version, name): _FuncInputs = make_dataclass( - "_FuncInputs", ((f"in{i}", Var) for i in range(num_inputs)), bases=(BaseInputs,) + "_FuncInputs", + ((f"in{i}", VarInfo) for i in range(num_inputs)), + bases=(BaseInputs,), ) _FuncOutputs = make_dataclass( "_FuncOutputs", - ((f"out{i}", Var) for i in range(num_outputs)), + ((f"out{i}", VarInfo) for i in range(num_outputs)), bases=(BaseOutputs,), ) @@ -155,7 +157,7 @@ def to_function(name: str, domain: str = "spox.function", *, _version: int = 0): The function must be deterministic in the performed operations, as otherwise an error will be raised at build due to inconsistent function bodies. - ``fun`` is assumed to take only Var arguments and return an iterable of them. These will be used to generate the + ``fun`` is assumed to take only VarInfo arguments and return an iterable of them. These will be used to generate the function class signature. Keep in mind that functions with the same name & domain will be merged together. @@ -170,13 +172,13 @@ def inner(fun: ConstructorT) -> ConstructorT: _num_outputs = None _cls = None - def get_num_outputs(*args: Var) -> int: + def get_num_outputs(*args: VarInfo) -> int: nonlocal _num_outputs if _num_outputs is None: _num_outputs = sum(1 for _ in fun(*args)) return _num_outputs - def init(*args: Var): + def init(*args: VarInfo): nonlocal _cls if _cls is not None: return _cls @@ -186,7 +188,7 @@ def init(*args: Var): ) return _cls - def alt_fun(*args: Var) -> Iterable[Var]: + def alt_fun(*args: VarInfo) -> Iterable[VarInfo]: cls = init(*args) return ( cls(cls.Attributes(), cls.Inputs(*args)).outputs.get_fields().values() diff --git a/src/spox/_future.py b/src/spox/_future.py index ecaa5c7b..a806fab7 100644 --- a/src/spox/_future.py +++ b/src/spox/_future.py @@ -14,7 +14,7 @@ import spox._value_prop from spox._graph import initializer as _initializer from spox._type_system import Tensor -from spox._var import Var +from spox._var import VarInfo TypeWarningLevel = spox._node.TypeWarningLevel @@ -46,9 +46,9 @@ def value_prop_backend(backend: ValuePropBackend): set_value_prop_backend(prev_backend) -def initializer(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: +def initializer(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> VarInfo: """ - Create a Var with a constant value. + Create a VarInfo with a constant value. Parameters ---------- @@ -60,8 +60,8 @@ def initializer(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: Returns ------- - Var - Variable with the given constant ``value``. + VarInfo + VarInfoiable with the given constant ``value``. Notes ----- @@ -79,14 +79,14 @@ def __init__(self, op, type_promotion: bool, constant_promotion: bool): self.constant_promotion = constant_promotion def _promote( - self, *args: Union[Var, np.generic, int, float], to_floating: bool = False - ) -> Iterable[Optional[Var]]: + self, *args: Union[VarInfo, np.generic, int, float], to_floating: bool = False + ) -> Iterable[Optional[VarInfo]]: """ Apply constant promotion and type promotion to given parameters, creating constants and/or casting. """ targets: list[Union[np.dtype, np.generic, int, float]] = [ - x.type.dtype if isinstance(x, Var) and isinstance(x.type, Tensor) else x # type: ignore + x.type.dtype if isinstance(x, VarInfo) and isinstance(x.type, Tensor) else x # type: ignore for x in args ] if self.type_promotion: @@ -97,7 +97,7 @@ def _promote( dtypes = {dtype for dtype in targets if isinstance(dtype, np.dtype)} if len(dtypes) > 1: raise TypeError( - f"Inconsistent types for Var operator with no type promotion: {dtypes}." + f"Inconsistent types for VarInfo operator with no type promotion: {dtypes}." ) (target_type,) = dtypes if issubclass(target_type.type, np.integer): @@ -112,54 +112,56 @@ def _promote( ) # TODO: Handle more constant-target inconsistencies here? - def _promote_target(obj: Union[Var, np.generic, int, float]) -> Optional[Var]: + def _promote_target( + obj: Union[VarInfo, np.generic, int, float], + ) -> Optional[VarInfo]: if self.constant_promotion and isinstance(obj, (np.generic, int, float)): return self.op.const(np.array(obj, dtype=target_type)) - elif isinstance(obj, Var): + elif isinstance(obj, VarInfo): return self.op.cast(obj, to=target_type) if self.type_promotion else obj raise TypeError( - f"Bad value '{obj!r}' of type {type(obj).__name__!r} for operator overloading with Var. " + f"Bad value '{obj!r}' of type {type(obj).__name__!r} for operator overloading with VarInfo. " f"({self.type_promotion=}, {self.constant_promotion=})" ) return tuple(var for var in map(_promote_target, args)) - def add(self, a, b) -> Var: + def add(self, a, b) -> VarInfo: a, b = self._promote(a, b) return self.op.add(a, b) - def sub(self, a, b) -> Var: + def sub(self, a, b) -> VarInfo: a, b = self._promote(a, b) return self.op.sub(a, b) - def mul(self, a, b) -> Var: + def mul(self, a, b) -> VarInfo: a, b = self._promote(a, b) return self.op.mul(a, b) - def truediv(self, a, b) -> Var: + def truediv(self, a, b) -> VarInfo: a, b = self._promote(a, b, to_floating=True) return self.op.div(a, b) - def floordiv(self, a, b) -> Var: + def floordiv(self, a, b) -> VarInfo: a, b = self._promote(a, b) c = self.op.div(a, b) if isinstance(c.type, Tensor) and not issubclass(c.type._elem_type, np.integer): c = self.op.floor(c) return c - def neg(self, a: Var) -> Var: + def neg(self, a: VarInfo) -> VarInfo: return self.op.neg(a) - def and_(self, a: Var, b: Var) -> Var: + def and_(self, a: VarInfo, b: VarInfo) -> VarInfo: return self.op.and_(a, b) - def or_(self, a: Var, b: Var) -> Var: + def or_(self, a: VarInfo, b: VarInfo) -> VarInfo: return self.op.or_(a, b) - def xor(self, a: Var, b: Var) -> Var: + def xor(self, a: VarInfo, b: VarInfo) -> VarInfo: return self.op.xor(a, b) - def not_(self, a: Var) -> Var: + def not_(self, a: VarInfo) -> VarInfo: return self.op.not_(a) @@ -167,7 +169,7 @@ def not_(self, a: Var) -> Var: def operator_overloading( op, type_promotion: bool = False, constant_promotion: bool = True ): - """Enable operator overloading on Var for this block. + """Enable operator overloading on VarInfo for this block. May be used either as a context manager, or a decorator. @@ -185,7 +187,7 @@ def operator_overloading( if the type was not conclusively floating (as in numpy). False by default. constant_promotion - Whether operator overloading should implicitly promote primitive scalar constants to Var. + Whether operator overloading should implicitly promote primitive scalar constants to VarInfo. True by default. Examples @@ -201,12 +203,12 @@ def operator_overloading( ... return x * y >>> assert foo()._get_value() == np.array(6) """ - prev_dispatcher = Var._operator_dispatcher - Var._operator_dispatcher = _NumpyLikeOperatorDispatcher( + prev_dispatcher = VarInfo._operator_dispatcher + VarInfo._operator_dispatcher = _NumpyLikeOperatorDispatcher( op, type_promotion, constant_promotion ) yield - Var._operator_dispatcher = prev_dispatcher + VarInfo._operator_dispatcher = prev_dispatcher __all__ = [ @@ -220,6 +222,6 @@ def operator_overloading( "ValuePropBackend", "set_value_prop_backend", "value_prop_backend", - # Operator overloading on Var + # Operator overloading on VarInfo "operator_overloading", ] diff --git a/src/spox/_graph.py b/src/spox/_graph.py index 33369fd7..39ba006b 100644 --- a/src/spox/_graph.py +++ b/src/spox/_graph.py @@ -22,7 +22,7 @@ from ._schemas import max_opset_policy from ._type_system import Tensor, Type from ._utils import from_array -from ._var import Var +from ._var import Var, VarInfo def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var]: @@ -36,8 +36,8 @@ def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var and its type is used to create a respective Tensor. Returns ------- - Dict[str, Var] - Argument Vars of given Types, named the same as kwargs. + Dict[str, VarInfo] + Argument VarInfos of given Types, named the same as kwargs. """ result = {} for name, info in kwargs.items(): @@ -50,7 +50,7 @@ def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var default=None, ), BaseInputs(), - ).outputs.arg + ).get_output_vars()["arg"] elif isinstance(info, np.ndarray): ty = Tensor(info.dtype, info.shape) result[name] = Argument( @@ -60,20 +60,20 @@ def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var default=AttrTensor(value=info, name="dummy"), ), BaseInputs(), - ).outputs.arg + ).get_output_vars()["arg"] else: raise TypeError(f"Cannot construct argument from {type(info)}.") return result -def arguments(**kwargs: Optional[Union[Type, np.ndarray]]) -> tuple[Var, ...]: - """This function is a shorthand for a respective call to ``arguments_dict``, unpacking the Vars from the dict.""" +def arguments(**kwargs: Optional[Union[Type, np.ndarray]]) -> tuple[VarInfo, ...]: + """This function is a shorthand for a respective call to ``arguments_dict``, unpacking the VarInfos from the dict.""" return tuple(arguments_dict(**kwargs).values()) def enum_arguments( *infos: Union[Type, np.ndarray], prefix: str = "in" -) -> tuple[Var, ...]: +) -> tuple[VarInfo, ...]: """ Convenience function for creating an enumeration of arguments, prefixed with ``prefix``. Calls ``arguments`` internally. @@ -89,13 +89,13 @@ def enum_arguments( String to prefix the names of created arguments with. Returns ------- - Tuple[Var, ...] - Argument Vars as specified, in the same order as information ``infos``. + Tuple[VarInfo, ...] + Argument VarInfos as specified, in the same order as information ``infos``. """ return arguments(**{f"{prefix}{i}": info for i, info in enumerate(infos)}) -def initializer(arr: np.ndarray) -> Var: +def initializer(arr: np.ndarray) -> VarInfo: """ Create a single initializer (frozen argument) with a given array value. @@ -108,7 +108,7 @@ def initializer(arr: np.ndarray) -> Var: Value of the initializer. Returns ------- - Var which is always equal to the respective value provided by `arr`. + VarInfo which is always equal to the respective value provided by `arr`. """ return _Initializer( _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), @@ -133,12 +133,12 @@ class Graph: Note: building a Graph is cached, so changing it in-place without the setters will invalidate the build. """ - _results: dict[str, Var] + _results: dict[str, VarInfo] _name: Optional[str] = None _doc_string: Optional[str] = None - _arguments: Optional[tuple[Var, ...]] = None + _arguments: Optional[tuple[VarInfo, ...]] = None _extra_opset_req: Optional[set[tuple[str, int]]] = None - _constructor: Optional[Callable[..., Iterable[Var]]] = None + _constructor: Optional[Callable[..., Iterable[VarInfo]]] = None _build_result: "_build.Cached[_build.BuildResult]" = dataclasses.field( default_factory=_build.Cached ) @@ -159,14 +159,18 @@ def __repr__(self): return f" ({res_repr}){': ' if comments else ''}{', '.join(comments)}>" def __post_init__(self): - if any(not isinstance(var, Var) for var in self._results.values()): + if any(not isinstance(var, VarInfo) for var in self._results.values()): seen_types = {type(obj) for obj in self._results.values()} - raise TypeError(f"Graph results must be Vars, not {seen_types - {Var}}.") + raise TypeError( + f"Graph results must be VarInfos, not {seen_types - {VarInfo}}." + ) if self._arguments is not None and any( - not isinstance(var, Var) for var in self._arguments + not isinstance(var, VarInfo) for var in self._arguments ): seen_types = {type(obj) for obj in self._arguments} - raise TypeError(f"Build outputs must be Vars, not {seen_types - {Var}}.") + raise TypeError( + f"Build outputs must be VarInfos, not {seen_types - {VarInfo}}." + ) def with_name(self, name: str) -> "Graph": """Return a Graph with its name set to ``name``.""" @@ -176,9 +180,9 @@ def with_doc(self, doc_string: str) -> "Graph": """Return a Graph with its doc string set to ``doc``.""" return replace(self, _doc_string=doc_string) - def with_arguments(self, *args: Var) -> "Graph": + def with_arguments(self, *args: VarInfo) -> "Graph": """ - Return a Graph with given Vars marked as exactly its arguments. + Return a Graph with given VarInfos marked as exactly its arguments. A useful idiom is ``results(...).with_arguments(...)`` when you want to specify both results and arguments. """ return replace(self, _arguments=args) @@ -193,11 +197,11 @@ def with_opset(self, *args: tuple[str, int]) -> "Graph": extra_opset_req |= self._extra_opset_req return replace(self, _extra_opset_req=extra_opset_req) - def _with_constructor(self, fun: Callable[..., Iterable[Var]]) -> "Graph": + def _with_constructor(self, fun: Callable[..., Iterable[VarInfo]]) -> "Graph": """Assign a constructor that constructed this Graph given ``self.requested_arguments``.""" return replace(self, _constructor=fun) - def _reconstruct(self, *args: Var) -> "Graph": + def _reconstruct(self, *args: VarInfo) -> "Graph": assert self._constructor is not None return ( results(**dict(zip(self._results, self._constructor(*args)))) @@ -213,16 +217,16 @@ def _inject_build_result(self, what: "_build.BuildResult") -> "Graph": return replace(self, _build_result=_build.Cached(what)) @property - def requested_arguments(self) -> Optional[Iterable[Var]]: + def requested_arguments(self) -> Optional[Iterable[VarInfo]]: """Arguments requested by this Graph (for building) - ``None`` if unspecified.""" return self._arguments @property - def requested_results(self) -> dict[str, Var]: + def requested_results(self) -> dict[str, VarInfo]: """Results (named) requested by this Graph (for building).""" return self._results - def get_arguments(self) -> dict[str, Var]: + def get_arguments(self) -> dict[str, VarInfo]: """ Get the effective named arguments (after build) of this Graph. @@ -233,7 +237,7 @@ def get_arguments(self) -> dict[str, Var]: for var in self._get_build_result().arguments } - def get_results(self) -> dict[str, Var]: + def get_results(self) -> dict[str, VarInfo]: """ Get the effective named results (after build) of this Graph. @@ -432,14 +436,14 @@ def to_onnx_model( return model -def results(**kwargs: Var) -> Graph: +def results(**kwargs: VarInfo) -> Graph: """ Use this function to construct a ``Graph`` object. Parameters ---------- kwargs - Vars to be marked as results in the created Graph. + VarInfos to be marked as results in the created Graph. Returns ------- Graph @@ -448,7 +452,7 @@ def results(**kwargs: Var) -> Graph: return Graph(kwargs) -def enum_results(*vars: Var, prefix="out") -> Graph: +def enum_results(*vars: VarInfo, prefix="out") -> Graph: """ Use this function to construct a ``Graph`` object, whenever the exact names are not important. Useful when creating subgraphs. @@ -456,7 +460,7 @@ def enum_results(*vars: Var, prefix="out") -> Graph: Parameters ---------- vars - Vars to be marked as results. + VarInfos to be marked as results. prefix String to prefix the names of created results with. Returns @@ -467,7 +471,7 @@ def enum_results(*vars: Var, prefix="out") -> Graph: return results(**{f"{prefix}{i}": var for i, var in enumerate(vars)}) -def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[Var]]) -> Graph: +def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[VarInfo]]) -> Graph: """ Convenience function for creating a subgraph, for use in an operator like If or Loop. However, for those operators one may prefer to use alternative constructors like ``xif`` or ``xloop`` @@ -478,7 +482,7 @@ def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[Var]]) -> Graph: types A list of argument types for the subgraph. fun - A function taking as many Var arguments as the length of `types`, and returning the results of the subgraph. + A function taking as many VarInfo arguments as the length of `types`, and returning the results of the subgraph. Returns ------- Graph @@ -494,6 +498,8 @@ def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[Var]]) -> Graph: if not callable(fun): raise TypeError("Subgraph callback must be callable.") outs = fun(*ins) - if not (isinstance(outs, Iterable) and all(isinstance(out, Var) for out in outs)): - raise TypeError("Subgraph result must be an Iterable of Var.") + if not ( + isinstance(outs, Iterable) and all(isinstance(out, VarInfo) for out in outs) + ): + raise TypeError("Subgraph result must be an Iterable of VarInfo.") return enum_results(*outs).with_arguments(*ins)._with_constructor(fun) diff --git a/src/spox/_inline.py b/src/spox/_inline.py index f3077f7d..d4908b46 100644 --- a/src/spox/_inline.py +++ b/src/spox/_inline.py @@ -14,7 +14,7 @@ from spox._node import OpType from spox._scope import Scope from spox._type_system import Type -from spox._var import Var +from spox._var import VarInfo from . import _value_prop @@ -86,11 +86,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - inputs: Sequence[Var] + inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - outputs: Sequence[Var] + outputs: Sequence[VarInfo] op_type = OpType("Inline", "spox.internal", 0) diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index f51f2579..e5dd9246 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -20,7 +20,7 @@ from ._shape import SimpleShape from ._type_system import Tensor, Type from ._value_prop import PropValueType -from ._var import Var +from ._var import VarInfo # This is a default used for internal operators that # require the default domain. The most common of these @@ -78,7 +78,7 @@ class Inputs(BaseInputs): @dataclass class Outputs(BaseOutputs): - arg: Var + arg: VarInfo attrs: Attributes inputs: Inputs @@ -115,7 +115,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - arg: Var + arg: VarInfo attrs: Attributes inputs: BaseInputs @@ -149,11 +149,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - inputs: Sequence[Var] + inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - outputs: Sequence[Var] + outputs: Sequence[VarInfo] op_type = OpType("Introduce", "spox.internal", 0) @@ -192,7 +192,7 @@ def to_onnx( return protos -def intros(*args: Var) -> Sequence[Var]: +def intros(*args: VarInfo) -> Sequence[VarInfo]: """ Internal identity operator with variadic arguments. @@ -206,44 +206,44 @@ def intros(*args: Var) -> Sequence[Var]: Parameters ---------- args - Vars to introduce in current scope. + VarInfos to introduce in current scope. Returns ------- - Sequence[Var] - Vars of the same value as ``args``, but with a shared dependency. + Sequence[VarInfo] + VarInfos of the same value as ``args``, but with a shared dependency. """ return _Introduce( None, _Introduce.Inputs(args), out_variadic=len(args) ).outputs.outputs -def intro(*args: Var) -> Var: +def intro(*args: VarInfo) -> VarInfo: """Introduces arguments like ``intros``, but only returns the last.""" return intros(*args)[-1] -def unsafe_cast(x: Var, typ: Type) -> Var: +def unsafe_cast(x: VarInfo, typ: Type) -> VarInfo: """ Creates a new var with the type forcefully set to ``typ``. - Assumes that the real type of the Var is indeed compatible with ``shape`` (for example it was unknown). + Assumes that the real type of the VarInfo is indeed compatible with ``shape`` (for example it was unknown). The function is meant for use when type inference failed, and it has to be overriden to avoid further failures. - If you want to properly change a ``Var``'s type, use an operator like Cast, CastLike, Optional, etc. + If you want to properly change a ``VarInfo``'s type, use an operator like Cast, CastLike, Optional, etc. Parameters ---------- x - Var to retype. + VarInfo to retype. typ Target type - must be a constant. Returns ------- - Var - Var with the type reset to whatever was given. + VarInfo + VarInfo with the type reset to whatever was given. """ y = intro(x) y.type = typ @@ -251,11 +251,11 @@ def unsafe_cast(x: Var, typ: Type) -> Var: return y -def unsafe_reshape(x: Var, shape: SimpleShape) -> Var: +def unsafe_reshape(x: VarInfo, shape: SimpleShape) -> VarInfo: """ Creates a new var with the shape forcefully set to ``shape`` (like an unsafe cast). - Assumes that the real shape of the Var is indeed compatible with ``shape`` (for example it was unknown). + Assumes that the real shape of the VarInfo is indeed compatible with ``shape`` (for example it was unknown). The function is meant for use when shape inference failed, and it has to be overriden to avoid failures. @@ -264,12 +264,12 @@ def unsafe_reshape(x: Var, shape: SimpleShape) -> Var: Parameters ---------- x - Var to reshape. + VarInfo to reshape. shape Target shape - must be a constant. Returns ------- - Var - Var with the same Tensor element type, but different shape. + VarInfo + VarInfo with the same Tensor element type, but different shape. """ return unsafe_cast(x, Tensor(x.unwrap_tensor().dtype, shape)) diff --git a/src/spox/_node.py b/src/spox/_node.py index 322a09a9..e69f5890 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -20,7 +20,7 @@ from ._fields import BaseAttributes, BaseInputs, BaseOutputs, VarFieldKind from ._type_system import Type from ._value_prop import PropValue, PropValueType -from ._var import Var +from ._var import Var, VarInfo if typing.TYPE_CHECKING: from ._graph import Graph @@ -94,8 +94,8 @@ def __init__( *, out_variadic: Optional[int] = None, infer_types: bool = True, - propagate_values: bool = True, validate: bool = True, + initializers=[], **kwargs, ): """ @@ -113,9 +113,6 @@ def __init__( infer_types Whether to run type inference - setting types for output vars if previously None. Should always succeed if possible, possibly raising type errors if inputs/attributes are not correctly typed. - propagate_values - Whether to run value propagation - setting values for output vars if previously None. Should only succeed - if all inputs are constant (attributes always are). validate Whether to run some extra validation. The default validation only warns against unknown types. kwargs @@ -130,7 +127,7 @@ def __init__( # As inference functions may access which output vars we initialized (e.g. variadics) # we inject uninitialized vars first self.outputs = self._init_output_vars() - self.inference(infer_types, propagate_values) + self.inference(infer_types) else: self.outputs = outputs @@ -212,7 +209,7 @@ def pre_init(self, **kwargs): def post_init(self, **kwargs): """Post-initialization hook. Called at the end of ``__init__`` after other default fields are set.""" - def propagate_values(self) -> dict[str, PropValueType]: + def propagate_values(self, initializers) -> dict[str, PropValueType]: """ Propagate values from inputs, and, if possible, compute values for outputs as well. This method is used to implement ONNX partial data propagation - for example so that @@ -224,11 +221,11 @@ def infer_output_types(self) -> dict[str, Type]: """ Inference routine for output types. Often overriden by inheriting Node types. - Returns a dictionary of output field names into Types for the respective Vars. + Returns a dictionary of output field names into Types for the respective VarInfos. """ return {} - def inference(self, infer_types: bool = True, propagate_values: bool = True): + def inference(self, infer_types: bool = True): # Type inference routine - call infer_output_types if required # and check if it provides the expected outputs. out_types = self.infer_output_types() if infer_types else {} @@ -238,20 +235,29 @@ def inference(self, infer_types: bool = True, propagate_values: bool = True): # Attempt to use the ones from kwargs, if none then what type inference gave var.type = out_types.get(key) + def get_output_vars(self, **initializers): # After typing everything, try to get values for outputs - out_values = self.propagate_values() if propagate_values else {} - for key, var in self.outputs.get_vars().items(): - if var.type is not None and var._value is None and key in out_values: - prop = PropValue(var.type, out_values.get(key)) - if prop.check(): - var._value = prop - else: - warnings.warn( - InferenceWarning( - f"Propagated value {prop} does not type-check, dropping. " - f"Hint: this indicates a bug with the current value prop backend or type inference." - ) + out_values = self.propagate_values(initializers) + ret = { + key: Var(var_info, None) + for key, var_info in self.outputs.get_vars().items() + } + for key, var_info in self.outputs.get_vars().items(): + if var_info.type is None or key not in out_values: + continue + + prop = PropValue(var_info.type, out_values.get(key)) + if prop.check(): + ret[key]._value = prop + else: + warnings.warn( + InferenceWarning( + f"Propagated value {prop} does not type-check, dropping. " + f"Hint: this indicates a bug with the current value prop backend or type inference." ) + ) + + return ret def validate_types(self) -> None: """Validation of types, ran at the end of Node creation.""" @@ -309,31 +315,29 @@ def _init_output_vars(self) -> BaseOutputs: (variadic,) = variadics else: variadic = None - outputs: dict[str, Union[Var, Sequence[Var]]] = { - field.name: Var(self, None, None) + outputs: dict[str, Union[VarInfo, Sequence[VarInfo]]] = { + field.name: VarInfo(self, None) for field in dataclasses.fields(self.Outputs) if field.name != variadic } if variadic is not None: assert self.out_variadic is not None - outputs[variadic] = [ - Var(self, None, None) for _ in range(self.out_variadic) - ] + outputs[variadic] = [VarInfo(self, None) for _ in range(self.out_variadic)] return self.Outputs(**outputs) # type: ignore @property - def dependencies(self) -> Iterable[Var]: - """List of input Vars into this Node.""" + def dependencies(self) -> Iterable[VarInfo]: + """List of input VarInfos into this Node.""" return (var for var in self.inputs.get_vars().values()) @property - def dependents(self) -> Iterable[Var]: - """List of output Vars from this Node.""" + def dependents(self) -> Iterable[VarInfo]: + """List of output VarInfos from this Node.""" return (var for var in self.outputs.get_vars().values()) @property - def incident(self) -> Iterable[Var]: - """List of both input and output Vars for this Node.""" + def incident(self) -> Iterable[VarInfo]: + """List of both input and output VarInfos for this Node.""" return itertools.chain(self.dependencies, self.dependents) @property diff --git a/src/spox/_public.py b/src/spox/_public.py index 101d8d40..b29405f0 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -17,7 +17,7 @@ from ._inline import _Inline from ._standard import _strip_dim_symbol from ._type_system import Type -from ._var import Var +from ._var import Var, VarInfo def argument(typ: Type) -> Var: @@ -37,16 +37,16 @@ def argument(typ: Type) -> Var: """ return _internal_op.Argument( _internal_op.Argument.Attributes(type=AttrType(typ, "dummy"), default=None) - ).outputs.arg + ).get_output_vars()["arg"] @contextlib.contextmanager -def _temporary_renames(**kwargs: Var): +def _temporary_renames(**kwargs: VarInfo): # The build code can't really special-case variable names that are - # not just ``Var._name``. So we set names here and reset them + # not just ``VarInfo._name``. So we set names here and reset them # afterwards. name: Optional[str] - pre: dict[Var, Optional[str]] = {} + pre: dict[VarInfo, Optional[str]] = {} try: for name, arg in kwargs.items(): pre[arg] = arg._name @@ -73,7 +73,7 @@ def build( Model inputs. Keys are names, values must be results of ``argument``. outputs - Model outputs. Keys are names, values may be any ``Var``. + Model outputs. Keys are names, values may be any ``VarInfo``. Building will resolve what nodes were used in the construction of output variables. drop_unused_inputs @@ -107,29 +107,34 @@ def build( >>> # a, b, c are all vectors and named the same in the graph >>> # We create 3 distinct arguments >>> a, b, c = [argument(VectorFloat32) for _ in range(3)] - >>> # p represents the Var equivalent to a * b + >>> # p represents the VarInfo equivalent to a * b >>> q = op.add(op.mul(a, b), c) >>> # Build an ONNX model in Spox >>> model = build({'a': a, 'b': b, 'c': c}, {'r': q}) """ - if not all(isinstance(var, Var) for var in inputs.values()): + if not all(isinstance(var, VarInfo) for var in inputs.values()): seen_types = {type(obj) for obj in inputs.values()} - raise TypeError(f"Build inputs must be Vars, not {seen_types - {Var}}.") - if not all(isinstance(var, Var) for var in outputs.values()): + raise TypeError(f"Build inputs must be VarInfos, not {seen_types - {VarInfo}}.") + if not all(isinstance(var, VarInfo) for var in outputs.values()): seen_types = {type(obj) for obj in outputs.values()} - raise TypeError(f"Build outputs must be Vars, not {seen_types - {Var}}.") + raise TypeError( + f"Build outputs must be VarInfos, not {seen_types - {VarInfo}}." + ) if not all(isinstance(var._op, Argument) for var in inputs.values()): raise TypeError( - "Build inputs must be `Var`s constructed using the `spox.argument` function. " + "Build inputs must be `VarInfo`s constructed using the `spox.argument` function. " "They must not be results of other operations." ) if not outputs: raise ValueError("Build outputs must not be empty for the graph to be valid.") - with _temporary_renames(**inputs): - graph = results(**outputs) + input_infos = {key: var._var_info for key, var in inputs.items()} + output_infos = {key: var._var_info for key, var in outputs.items()} + + with _temporary_renames(**input_infos): + graph = results(**output_infos) if not drop_unused_inputs: - graph = graph.with_arguments(*inputs.values()) + graph = graph.with_arguments(*input_infos.values()) model_proto = graph.to_onnx_model() # Validate that no further inputs were required. @@ -142,24 +147,24 @@ def build( class _InlineCall(Protocol): """ A callable returned by ``inline``, taking positional and keyword - arguments of type ``Var``, and returning a dictionary of names - (``str``) into ``Var``. + arguments of type ``VarInfo``, and returning a dictionary of names + (``str``) into ``VarInfo``. """ - def __call__(self, *args: Var, **kwargs: Var) -> dict[str, Var]: + def __call__(self, *args: VarInfo, **kwargs: VarInfo) -> dict[str, VarInfo]: """ Parameters ---------- args - Variables passed as model inputs - positional, as they are + VarInfoiables passed as model inputs - positional, as they are listed in the model. kwargs Further variables passed as model inputs - keyword, as they are named in the model. Returns ------- - Dict[str, Var] - Variables representing the inlined model's outputs. + Dict[str, VarInfo] + VarInfoiables representing the inlined model's outputs. """ @@ -170,7 +175,7 @@ def _copy_model(model: onnx.ModelProto) -> onnx.ModelProto: def inline(model: onnx.ModelProto) -> _InlineCall: - """Inline an existing ONNX model, taking and producing ``Var``. + """Inline an existing ONNX model, taking and producing ``VarInfo``. Any valid model may be inlined. The behaviour of the ``model`` is replicated, its metadata (docstring, annotations) may be stripped. @@ -191,8 +196,8 @@ def inline(model: onnx.ModelProto) -> _InlineCall: Returns ------- _InlineCall - A callable which takes ``Var`` arguments and returns a - dictionary of output names into ``Var``. + A callable which takes ``VarInfo`` arguments and returns a + dictionary of output names into ``VarInfo``. Positional arguments are assigned based on the order they are listed in the model. Keyword arguments are assigned based on @@ -275,13 +280,14 @@ def inline(model: onnx.ModelProto) -> _InlineCall: model.graph.node.reverse() # Now we can assume the graph has no initializers - def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: + def inline_inner(*args: Var, **kwargs: Var) -> dict[str, VarInfo]: + kwargs = {name: var._var_info for name, var in kwargs.items()} for name, arg in zip(in_names, args): if name in kwargs: raise TypeError( f"inline callback got multiple values for argument '{name}', {_signature_msg}." ) - kwargs[name] = arg + kwargs[name] = arg._var_info if not (missing := set(in_names) - set(kwargs)) <= set(in_defaults): raise TypeError( f"inline callback missing required arguments: {missing}, {_signature_msg}." diff --git a/src/spox/_scope.py b/src/spox/_scope.py index 50b1ad52..eec96386 100644 --- a/src/spox/_scope.py +++ b/src/spox/_scope.py @@ -5,7 +5,7 @@ from typing import Generic, Optional, TypeVar, Union, overload from ._node import Node -from ._var import Var +from ._var import VarInfo H = TypeVar("H", bound=Hashable) @@ -18,7 +18,7 @@ class ScopeError(Exception): class ScopeSpace(Generic[H]): """ - Represents the namespace of a scope for some type H, like Node or Var. + Represents the namespace of a scope for some type H, like Node or VarInfo. Methods (and operators) on the namespace work both ways: both with names (str) and the named type (H). So ``__getitem__`` (``ScopeSpace[item]``) may be used for both the name of an object and the object of a name. @@ -152,15 +152,15 @@ class Scope: """ Class representing the state of an ONNX-rules scope. - Has namespaces (represented by a ScopeSpace) for Vars and Nodes. + Has namespaces (represented by a ScopeSpace) for VarInfos and Nodes. """ - var: ScopeSpace[Var] + var: ScopeSpace[VarInfo] node: ScopeSpace[Node] def __init__( self, - sub_var: Optional[ScopeSpace[Var]] = None, + sub_var: Optional[ScopeSpace[VarInfo]] = None, sub_node: Optional[ScopeSpace[Node]] = None, parent: Optional["Scope"] = None, ): @@ -180,7 +180,7 @@ def of(cls, *what): if not isinstance(key, str): key, value = value, key assert isinstance(key, str) - if isinstance(value, Var): + if isinstance(value, VarInfo): scope.var[key] = value elif isinstance(value, Node): scope.node[key] = value @@ -202,7 +202,7 @@ def update(self, node: Node, prefix: str = "", force: bool = True): node Node to introduce in the scope. prefix - What value to prefix the node name with. If the Var has a predeclared name, it does not get the prefix. + What value to prefix the node name with. If the VarInfo has a predeclared name, it does not get the prefix. force Whether to attempt to overwrite existing names (possibly raising a ScopeError if they were different). By default, this is set to True to be more strict, so we see if the scoping algorithm failed to only diff --git a/src/spox/_standard.py b/src/spox/_standard.py index ac519875..7efd19ed 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Callable -import numpy as np import onnx import onnx.reference import onnx.shape_inference @@ -18,7 +17,6 @@ from ._scope import Scope from ._shape import SimpleShape from ._type_system import Optional, Sequence, Tensor, Type -from ._utils import from_array from ._value_prop import PropValueType if TYPE_CHECKING: @@ -99,11 +97,7 @@ def out_value_info(curr_key, curr_var): ] # Initializers, passed in to allow partial data propagation # - used so that operators like Reshape are aware of constant shapes - initializers = [ - from_array(var._value.value, key) - for key, var in self.inputs.get_vars().items() - if var._value and isinstance(var._value.value, np.ndarray) - ] + initializers = [] # Graph and model graph = onnx.helper.make_graph( [node_proto], @@ -153,15 +147,15 @@ def infer_output_types_onnx(self) -> dict[str, Type]: for key, type_ in results.items() } - def propagate_values_onnx(self) -> dict[str, PropValueType]: + def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: """Perform value propagation by evaluating singleton model. The backend used for the propagation can be configured with the `spox._standard.ValuePropBackend` variable. """ # Cannot do propagation when some inputs were not propagated/inferred if any( - var.type is None or var._value is None - for var in self.inputs.get_vars().values() + var_info.type is None or initializers[name] is None + for name, var_info in self.inputs.get_vars().items() ): return {} if next(iter(self.subgraphs), None) is not None: @@ -170,9 +164,9 @@ def propagate_values_onnx(self) -> dict[str, PropValueType]: model, scope = self.to_singleton_onnx_model(with_dummy_subgraphs=False) wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() input_feed = { - scope.var[var]: wrap_feed(var._value) - for var in self.inputs.get_vars().values() - if var._value + scope.var[var_info]: wrap_feed(initializers[name]) + for name, var_info in self.inputs.get_vars().items() + if initializers[name] } output_feed = run(model, input_feed) @@ -188,9 +182,9 @@ def propagate_values_onnx(self) -> dict[str, PropValueType]: def infer_output_types(self) -> dict[str, Type]: return self.infer_output_types_onnx() - def propagate_values(self) -> dict[str, PropValueType]: + def propagate_values(self, initializers) -> dict[str, PropValueType]: if _value_prop._VALUE_PROP_BACKEND != _value_prop.ValuePropBackend.NONE: - return self.propagate_values_onnx() + return self.propagate_values_onnx(initializers) return {} diff --git a/src/spox/_value_prop.py b/src/spox/_value_prop.py index 300abccc..62a701da 100644 --- a/src/spox/_value_prop.py +++ b/src/spox/_value_prop.py @@ -42,7 +42,7 @@ class ValuePropBackend(enum.Enum): @dataclass(frozen=True) class PropValue: - """Propagated value given to a Var, which has a run-time value known at compile-time. + """Propagated value given to a VarInfo, which has a run-time value known at compile-time. Wrapper for a few Python types which are used to represent values of ONNX types. diff --git a/src/spox/_var.py b/src/spox/_var.py index 15dd2186..ea8d63b7 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause import typing -from typing import Any, Callable, ClassVar, Optional, TypeVar, Union +from typing import Callable, Optional, TypeVar, Union import numpy as np @@ -14,69 +14,51 @@ F = TypeVar("F", bound=Callable) -class NotImplementedOperatorDispatcher: - def _not_impl(self, *_): - return NotImplemented - - add = sub = mul = truediv = floordiv = neg = and_ = or_ = xor = not_ = _not_impl - - -class Var: +class VarInfo: """ Abstraction for a single ONNX value - like a tensor - that can be passed around in Python code. - A ``Var`` represents some output of an operator. + A ``VarInfo`` represents some output of an operator. This operator is stored internally to allow reproducing the graph. The ``type`` field is inferred and checked by operators. It may be ``None`` if type inference failed, in which case it is unknown and should pass all type checks. - However, untyped ``Var`` objects may not be used in some contexts. + However, untyped ``VarInfo`` objects may not be used in some contexts. Keep in mind that the types themselves may have some information missing. For instance, tensors allow missing rank and shape information. There is an implicit value propagation mechanism, powered by the ONNX reference implementation. - Values may be propagated if a ``Var`` always has a known and constant value at runtime. + Values may be propagated if a ``VarInfo`` always has a known and constant value at runtime. This is used for type & shape inference. For instance, Reshape to a constant shape can have the shape inferred. - ``Var`` should be treated as strictly immutable. - If a ``Var`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid. + ``VarInfo`` should be treated as strictly immutable. + If a ``VarInfo`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid. Protected fields are to be treated as internal. Useful data is also shown by the string representation, but it should be treated as debug information. - Should not be constructed directly - the main source of ``Var`` objects are operator constructors. + Should not be constructed directly - the main source of ``VarInfo`` objects are operator constructors. """ type: Optional[_type_system.Type] - _value: Optional[_value_prop.PropValue] _op: "Node" _name: Optional[str] - _operator_dispatcher: ClassVar[Any] = NotImplementedOperatorDispatcher() - def __init__( self, op: "Node", type_: Optional[_type_system.Type], - value: Optional[_value_prop.PropValue] = None, ): - """The initializer of ``Var`` is protected. Use operator constructors to construct them instead.""" + """The initializer of ``VarInfo`` is protected. Use operator constructors to construct them instead.""" if type_ is not None and not isinstance(type_, _type_system.Type): - raise TypeError("The type field of a Var must be a Spox Type.") - if value is not None and not isinstance(value, _value_prop.PropValue): - raise TypeError("The propagated value field of a Var must be a PropValue.") - if value is not None and value.type != type_: - raise ValueError( - f"The propagated value type ({value.type}) and actual Var type ({type_}) must be the same." - ) + raise TypeError("The type field of a VarInfo must be a Spox Type.") self.type = type_ - self._value = value self._op = op self._name = None def _rename(self, name: Optional[str]): - """Mutates the internal state of the Var, overriding its name as given.""" + """Mutates the internal state of the VarInfo, overriding its name as given.""" self._name = name @property @@ -88,22 +70,13 @@ def _which_output(self) -> Optional[str]: candidates = [key for key, var in op_outs.items() if var is self] return candidates[0] if candidates else None - def _get_value(self) -> "_value_prop.ORTValue": - """Get the propagated value in this Var and convert it to the ORT format. Raises if value is missing.""" - if self._value is None: - raise ValueError("No propagated value associated with this Var.") - return self._value.to_ort_value() - def __repr__(self) -> str: nm = repr(self._name) + " " if self._name is not None else "" op_repr = self._op.get_op_repr() if self._op else "??" which = self._which_output is_unary = len(self._op.outputs) <= 1 if self._op else True which_repr = "->??" if which is None else (f"->{which}" if is_unary else "") - return ( - f" "VarInfo": + raise ValueError("'VarInfo' objects cannot be deepcopied.") - def __add__(self, other) -> "Var": - return Var._operator_dispatcher.add(self, other) - def __sub__(self, other) -> "Var": - return Var._operator_dispatcher.sub(self, other) +class Var: + """ + Abstraction for a single ONNX value - like a tensor - that can be passed around in Python code. - def __mul__(self, other) -> "Var": - return Var._operator_dispatcher.mul(self, other) + A ``VarInfo`` represents some output of an operator. + This operator is stored internally to allow reproducing the graph. - def __truediv__(self, other) -> "Var": - return Var._operator_dispatcher.truediv(self, other) + The ``type`` field is inferred and checked by operators. + It may be ``None`` if type inference failed, in which case it is unknown and should pass all type checks. + However, untyped ``VarInfo`` objects may not be used in some contexts. + Keep in mind that the types themselves may have some information missing. + For instance, tensors allow missing rank and shape information. - def __floordiv__(self, other) -> "Var": - return Var._operator_dispatcher.floordiv(self, other) + There is an implicit value propagation mechanism, powered by the ONNX reference implementation. + Values may be propagated if a ``VarInfo`` always has a known and constant value at runtime. + This is used for type & shape inference. For instance, Reshape to a constant shape can have the shape inferred. - def __neg__(self) -> "Var": - return Var._operator_dispatcher.neg(self) + ``VarInfo`` should be treated as strictly immutable. + If a ``VarInfo`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid. - def __and__(self, other) -> "Var": - return Var._operator_dispatcher.and_(self, other) + Protected fields are to be treated as internal. + Useful data is also shown by the string representation, but it should be treated as debug information. + + Should not be constructed directly - the main source of ``VarInfo`` objects are operator constructors. + """ + + _var_info: VarInfo + _value: Optional[_value_prop.PropValue] + + def __init__( + self, + var_info: VarInfo, + value: Optional[_value_prop.PropValue] = None, + ): + """The initializer of ``Var`` is protected. Use operator constructors to construct them instead.""" + if value is not None and not isinstance(value, _value_prop.PropValue): + raise TypeError( + "The propagated value field of a VarInfo must be a PropValue." + ) + if value is not None and value.type != var_info._type: + raise ValueError( + f"The propagated value type ({value.type}) and actual VarInfo type ({type_}) must be the same." + ) - def __or__(self, other) -> "Var": - return Var._operator_dispatcher.or_(self, other) + self._var_info = var_info + self._value = value - def __xor__(self, other) -> "Var": - return Var._operator_dispatcher.xor(self, other) + def _get_value(self) -> "_value_prop.ORTValue": + """Get the propagated value in this VarInfo and convert it to the ORT format. Raises if value is missing.""" + if self._value is None: + raise ValueError("No propagated value associated with this VarInfo.") + return self._value.to_ort_value() - def __invert__(self) -> "Var": - return Var._operator_dispatcher.not_(self) + def __repr__(self) -> str: + nm = repr(self._name) + " " if self._name is not None else "" + op_repr = self._op.get_op_repr() if self._op else "??" + which = self._which_output + is_unary = len(self._op.outputs) <= 1 if self._op else True + which_repr = "->??" if which is None else (f"->{which}" if is_unary else "") + return ( + f" type[np.generic]: """Promote type for all given element types/values using ``np.result_type``.""" return np.dtype( np.result_type( *( - typ.unwrap_tensor().dtype if isinstance(typ, Var) else typ + typ.unwrap_tensor().dtype if isinstance(typ, VarInfo) else typ for typ in types ) ) diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index f9cbd0bf..ba2e9bce 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -3961,9 +3961,11 @@ def abs( return _Abs( _Abs.Attributes(), _Abs.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def acos( @@ -3995,9 +3997,11 @@ def acos( return _Acos( _Acos.Attributes(), _Acos.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def acosh( @@ -4030,9 +4034,11 @@ def acosh( return _Acosh( _Acosh.Attributes(), _Acosh.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def add( @@ -4075,10 +4081,13 @@ def add( return _Add( _Add.Attributes(), _Add.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def and_( @@ -4120,10 +4129,13 @@ def and_( return _And( _And.Attributes(), _And.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def arg_max( @@ -4181,9 +4193,11 @@ def arg_max( select_last_index=AttrInt64(select_last_index, name="select_last_index"), ), _ArgMax.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def arg_min( @@ -4241,9 +4255,11 @@ def arg_min( select_last_index=AttrInt64(select_last_index, name="select_last_index"), ), _ArgMin.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def asin( @@ -4275,9 +4291,11 @@ def asin( return _Asin( _Asin.Attributes(), _Asin.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def asinh( @@ -4309,9 +4327,11 @@ def asinh( return _Asinh( _Asinh.Attributes(), _Asinh.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def atan( @@ -4343,9 +4363,11 @@ def atan( return _Atan( _Atan.Attributes(), _Atan.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def atanh( @@ -4378,9 +4400,11 @@ def atanh( return _Atanh( _Atanh.Attributes(), _Atanh.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def average_pool( @@ -4514,9 +4538,11 @@ def average_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _AveragePool.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def batch_normalization( @@ -4540,8 +4566,8 @@ def batch_normalization( (training_mode=True). There are multiple cases for the number of outputs, which we list below: - - Output case #1: Y, running_mean, running_var (training_mode=True) - - Output case #2: Y (training_mode=False) + - Output case #1: Y, running_mean, running_var (training_mode=True) + - Output case #2: Y (training_mode=False) When training_mode=False, extra outputs are invalid. The outputs are updated as follows when training_mode=True: @@ -4614,7 +4640,7 @@ def batch_normalization( training_mode Attribute. If set to true, it indicates BatchNormalization is being used for - training, and outputs 1 and 2 are to be computed. + training, and outputs 1, 2, 3, and 4 would be populated. Returns ======= @@ -4639,20 +4665,30 @@ def batch_normalization( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _BatchNormalization( - _BatchNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - momentum=AttrFloat32(momentum, name="momentum"), - training_mode=AttrInt64(training_mode, name="training_mode"), - ), - _BatchNormalization.Inputs( - X=X, - scale=scale, - B=B, - input_mean=input_mean, - input_var=input_var, - ), - ).outputs._unpack_to_any() + return ( + _BatchNormalization( + _BatchNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + momentum=AttrFloat32(momentum, name="momentum"), + training_mode=AttrInt64(training_mode, name="training_mode"), + ), + _BatchNormalization.Inputs( + X=X._var_info, + scale=scale._var_info, + B=B._var_info, + input_mean=input_mean._var_info, + input_var=input_var._var_info, + ), + ) + .get_output_vars( + X=X._value, + scale=scale._value, + B=B._value, + input_mean=input_mean._value, + input_var=input_var._value, + ) + ._unpack_to_any() + ) def bernoulli( @@ -4706,9 +4742,11 @@ def bernoulli( seed=AttrFloat32.maybe(seed, name="seed"), ), _Bernoulli.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def bit_shift( @@ -4766,10 +4804,13 @@ def bit_shift( direction=AttrString(direction, name="direction"), ), _BitShift.Inputs( - X=X, - Y=Y, + X=X._var_info, + Y=Y._var_info, ), - ).outputs.Z + ).get_output_vars( + X=X._value, + Y=Y._value, + )["Z"] def blackman_window( @@ -4819,9 +4860,11 @@ def blackman_window( periodic=AttrInt64(periodic, name="periodic"), ), _BlackmanWindow.Inputs( - size=size, + size=size._var_info, ), - ).outputs.output + ).get_output_vars( + size=size._value, + )["output"] def cast( @@ -4860,26 +4903,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules: - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Parameters ========== @@ -4911,9 +4954,11 @@ def cast( to=AttrDtype(to, name="to"), ), _Cast.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def cast_like( @@ -4953,10 +4998,13 @@ def cast_like( return _CastLike( _CastLike.Attributes(), _CastLike.Inputs( - input=input, - target_type=target_type, + input=input._var_info, + target_type=target_type._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + target_type=target_type._value, + )["output"] def ceil( @@ -4990,9 +5038,11 @@ def ceil( return _Ceil( _Ceil.Attributes(), _Ceil.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def celu( @@ -5036,9 +5086,11 @@ def celu( alpha=AttrFloat32(alpha, name="alpha"), ), _Celu.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def clip( @@ -5081,11 +5133,15 @@ def clip( return _Clip( _Clip.Attributes(), _Clip.Inputs( - input=input, - min=min, - max=max, + input=input._var_info, + min=min._var_info, + max=max._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + min=min._value, + max=max._value, + )["output"] def compress( @@ -5139,10 +5195,13 @@ def compress( axis=AttrInt64.maybe(axis, name="axis"), ), _Compress.Inputs( - input=input, - condition=condition, + input=input._var_info, + condition=condition._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + condition=condition._value, + )["output"] def concat( @@ -5183,9 +5242,11 @@ def concat( axis=AttrInt64(axis, name="axis"), ), _Concat.Inputs( - inputs=inputs, + inputs=inputs._var_info, ), - ).outputs.concat_result + ).get_output_vars( + inputs=inputs._value, + )["concat_result"] def concat_from_sequence( @@ -5236,9 +5297,11 @@ def concat_from_sequence( new_axis=AttrInt64(new_axis, name="new_axis"), ), _ConcatFromSequence.Inputs( - input_sequence=input_sequence, + input_sequence=input_sequence._var_info, ), - ).outputs.concat_result + ).get_output_vars( + input_sequence=input_sequence._value, + )["concat_result"] def constant( @@ -5307,7 +5370,7 @@ def constant( value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), _Constant.Inputs(), - ).outputs.output + ).get_output_vars()["output"] def constant_of_shape( @@ -5352,9 +5415,11 @@ def constant_of_shape( value=AttrTensor.maybe(value, name="value"), ), _ConstantOfShape.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def conv( @@ -5464,11 +5529,15 @@ def conv( strides=AttrInt64s.maybe(strides, name="strides"), ), _Conv.Inputs( - X=X, - W=W, - B=B, + X=X._var_info, + W=W._var_info, + B=B._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + W=W._value, + B=B._value, + )["Y"] def conv_integer( @@ -5589,12 +5658,17 @@ def conv_integer( strides=AttrInt64s.maybe(strides, name="strides"), ), _ConvInteger.Inputs( - x=x, - w=w, - x_zero_point=x_zero_point, - w_zero_point=w_zero_point, + x=x._var_info, + w=w._var_info, + x_zero_point=x_zero_point._var_info, + w_zero_point=w_zero_point._var_info, ), - ).outputs.y + ).get_output_vars( + x=x._value, + w=w._value, + x_zero_point=x_zero_point._value, + w_zero_point=w_zero_point._value, + )["y"] def conv_transpose( @@ -5737,11 +5811,15 @@ def conv_transpose( strides=AttrInt64s.maybe(strides, name="strides"), ), _ConvTranspose.Inputs( - X=X, - W=W, - B=B, + X=X._var_info, + W=W._var_info, + B=B._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + W=W._value, + B=B._value, + )["Y"] def cos( @@ -5772,9 +5850,11 @@ def cos( return _Cos( _Cos.Attributes(), _Cos.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def cosh( @@ -5805,9 +5885,11 @@ def cosh( return _Cosh( _Cosh.Attributes(), _Cosh.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def cumsum( @@ -5881,10 +5963,13 @@ def cumsum( reverse=AttrInt64(reverse, name="reverse"), ), _CumSum.Inputs( - x=x, - axis=axis, + x=x._var_info, + axis=axis._var_info, ), - ).outputs.y + ).get_output_vars( + x=x._value, + axis=axis._value, + )["y"] def dft( @@ -5967,10 +6052,13 @@ def dft( onesided=AttrInt64(onesided, name="onesided"), ), _DFT.Inputs( - input=input, - dft_length=dft_length, + input=input._var_info, + dft_length=dft_length._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + dft_length=dft_length._value, + )["output"] def depth_to_space( @@ -6041,9 +6129,11 @@ def depth_to_space( mode=AttrString(mode, name="mode"), ), _DepthToSpace.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def dequantize_linear( @@ -6101,11 +6191,15 @@ def dequantize_linear( axis=AttrInt64(axis, name="axis"), ), _DequantizeLinear.Inputs( - x=x, - x_scale=x_scale, - x_zero_point=x_zero_point, + x=x._var_info, + x_scale=x_scale._var_info, + x_zero_point=x_zero_point._var_info, ), - ).outputs.y + ).get_output_vars( + x=x._value, + x_scale=x_scale._value, + x_zero_point=x_zero_point._value, + )["y"] def det( @@ -6141,9 +6235,11 @@ def det( return _Det( _Det.Attributes(), _Det.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def div( @@ -6186,10 +6282,13 @@ def div( return _Div( _Div.Attributes(), _Div.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def dropout( @@ -6268,16 +6367,24 @@ def dropout( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bool)` """ - return _Dropout( - _Dropout.Attributes( - seed=AttrInt64.maybe(seed, name="seed"), - ), - _Dropout.Inputs( - data=data, - ratio=ratio, - training_mode=training_mode, - ), - ).outputs._unpack_to_any() + return ( + _Dropout( + _Dropout.Attributes( + seed=AttrInt64.maybe(seed, name="seed"), + ), + _Dropout.Inputs( + data=data._var_info, + ratio=ratio._var_info, + training_mode=training_mode._var_info, + ), + ) + .get_output_vars( + data=data._value, + ratio=ratio._value, + training_mode=training_mode._value, + ) + ._unpack_to_any() + ) def dynamic_quantize_linear( @@ -6292,9 +6399,9 @@ def dynamic_quantize_linear( y_scale = (maximum(0, max(x)) - minimum(0, min(x))) / (qmax - qmin) - - where qmax and qmin are max and min values for quantization range i.e. - [0, 255] in case of uint8 - - data range is adjusted to include 0. + - where qmax and qmin are max and min values for quantization range + i.e. [0, 255] in case of uint8 + - data range is adjusted to include 0. Zero point is calculated as: @@ -6303,11 +6410,11 @@ def dynamic_quantize_linear( intermediate_zero_point = qmin - min(x)/y_scale y_zero_point = cast(round(saturate(itermediate_zero_point))) - - where qmax and qmin are max and min values for quantization range .i.e - [0, 255] in case of uint8 - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] - if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. + - where qmax and qmin are max and min values for quantization range + .i.e [0, 255] in case of uint8 + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, + 127] if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. Data quantization formula is: @@ -6315,9 +6422,9 @@ def dynamic_quantize_linear( y = saturate (round (x / y_scale) + y_zero_point) - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] - if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, + 127] if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. Parameters ========== @@ -6347,12 +6454,18 @@ def dynamic_quantize_linear( - T1: `tensor(float)` - T2: `tensor(uint8)` """ - return _DynamicQuantizeLinear( - _DynamicQuantizeLinear.Attributes(), - _DynamicQuantizeLinear.Inputs( - x=x, - ), - ).outputs._unpack_to_any() + return ( + _DynamicQuantizeLinear( + _DynamicQuantizeLinear.Attributes(), + _DynamicQuantizeLinear.Inputs( + x=x._var_info, + ), + ) + .get_output_vars( + x=x._value, + ) + ._unpack_to_any() + ) def einsum( @@ -6422,9 +6535,11 @@ def einsum( equation=AttrString(equation, name="equation"), ), _Einsum.Inputs( - Inputs=Inputs, + Inputs=Inputs._var_info, ), - ).outputs.Output + ).get_output_vars( + Inputs=Inputs._value, + )["Output"] def elu( @@ -6465,9 +6580,11 @@ def elu( alpha=AttrFloat32(alpha, name="alpha"), ), _Elu.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def equal( @@ -6509,10 +6626,13 @@ def equal( return _Equal( _Equal.Attributes(), _Equal.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def erf( @@ -6544,9 +6664,11 @@ def erf( return _Erf( _Erf.Attributes(), _Erf.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def exp( @@ -6577,9 +6699,11 @@ def exp( return _Exp( _Exp.Attributes(), _Exp.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def expand( @@ -6623,10 +6747,13 @@ def expand( return _Expand( _Expand.Attributes(), _Expand.Inputs( - input=input, - shape=shape, + input=input._var_info, + shape=shape._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + shape=shape._value, + )["output"] def eye_like( @@ -6683,9 +6810,11 @@ def eye_like( k=AttrInt64(k, name="k"), ), _EyeLike.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def flatten( @@ -6732,9 +6861,11 @@ def flatten( axis=AttrInt64(axis, name="axis"), ), _Flatten.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def floor( @@ -6768,9 +6899,11 @@ def floor( return _Floor( _Floor.Attributes(), _Floor.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def gru( @@ -6796,60 +6929,60 @@ def gru( Notations: - - ``X`` - input tensor - - ``z`` - update gate - - ``r`` - reset gate - - ``h`` - hidden gate - - ``t`` - time step (t-1 means previous time step) - - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden - gates - - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden - gates - - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates - - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates - - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, - and hidden gates - - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, - and hidden gates - - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden - gates - - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden - gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``z`` - update gate + - ``r`` - reset gate + - ``h`` - hidden gate + - ``t`` - time step (t-1 means previous time step) + - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden + gates + - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden + gates + - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates + - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates + - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, + and hidden gates + - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, + and hidden gates + - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden + gates + - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden + gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha \* x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha \* Tanh(beta \* x) - - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha \* x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha \* Tanh(beta \* x) + - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Sigmoid, g=Tanh): - - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) - - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) - - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when - linear_before_reset = 0 - - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when - linear_before_reset != 0 - - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** - inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) + - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when + linear_before_reset = 0 + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when + linear_before_reset != 0 + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** + inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -6945,30 +7078,43 @@ def gru( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - return _GRU( - _GRU.Attributes( - activation_alpha=AttrFloat32s.maybe( - activation_alpha, name="activation_alpha" + return ( + _GRU( + _GRU.Attributes( + activation_alpha=AttrFloat32s.maybe( + activation_alpha, name="activation_alpha" + ), + activation_beta=AttrFloat32s.maybe( + activation_beta, name="activation_beta" + ), + activations=AttrStrings.maybe(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + layout=AttrInt64(layout, name="layout"), + linear_before_reset=AttrInt64( + linear_before_reset, name="linear_before_reset" + ), ), - activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), - activations=AttrStrings.maybe(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - layout=AttrInt64(layout, name="layout"), - linear_before_reset=AttrInt64( - linear_before_reset, name="linear_before_reset" + _GRU.Inputs( + X=X._var_info, + W=W._var_info, + R=R._var_info, + B=B._var_info, + sequence_lens=sequence_lens._var_info, + initial_h=initial_h._var_info, ), - ), - _GRU.Inputs( - X=X, - W=W, - R=R, - B=B, - sequence_lens=sequence_lens, - initial_h=initial_h, - ), - ).outputs._unpack_to_any() + ) + .get_output_vars( + X=X._value, + W=W._value, + R=R._value, + B=B._value, + sequence_lens=sequence_lens._value, + initial_h=initial_h._value, + ) + ._unpack_to_any() + ) def gather( @@ -7062,10 +7208,13 @@ def gather( axis=AttrInt64(axis, name="axis"), ), _Gather.Inputs( - data=data, - indices=indices, + data=data._var_info, + indices=indices._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + indices=indices._value, + )["output"] def gather_elements( @@ -7167,10 +7316,13 @@ def gather_elements( axis=AttrInt64(axis, name="axis"), ), _GatherElements.Inputs( - data=data, - indices=indices, + data=data._var_info, + indices=indices._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + indices=indices._value, + )["output"] def gather_nd( @@ -7317,10 +7469,13 @@ def gather_nd( batch_dims=AttrInt64(batch_dims, name="batch_dims"), ), _GatherND.Inputs( - data=data, - indices=indices, + data=data._var_info, + indices=indices._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + indices=indices._value, + )["output"] def gemm( @@ -7337,8 +7492,8 @@ def gemm( General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 - - A' = transpose(A) if transA else A - - B' = transpose(B) if transB else B + - A' = transpose(A) if transA else A + - B' = transpose(B) if transB else B Compute Y = alpha \* A' \* B' + beta \* C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input @@ -7404,11 +7559,15 @@ def gemm( transB=AttrInt64(transB, name="transB"), ), _Gemm.Inputs( - A=A, - B=B, - C=C, + A=A._var_info, + B=B._var_info, + C=C._var_info, ), - ).outputs.Y + ).get_output_vars( + A=A._value, + B=B._value, + C=C._value, + )["Y"] def global_average_pool( @@ -7448,9 +7607,11 @@ def global_average_pool( return _GlobalAveragePool( _GlobalAveragePool.Attributes(), _GlobalAveragePool.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def global_lp_pool( @@ -7490,16 +7651,18 @@ def global_lp_pool( Signature: ``ai.onnx@2::GlobalLpPool``. Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ return _GlobalLpPool( _GlobalLpPool.Attributes( p=AttrInt64(p, name="p"), ), _GlobalLpPool.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def global_max_pool( @@ -7539,9 +7702,11 @@ def global_max_pool( return _GlobalMaxPool( _GlobalMaxPool.Attributes(), _GlobalMaxPool.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def greater( @@ -7583,10 +7748,13 @@ def greater( return _Greater( _Greater.Attributes(), _Greater.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def greater_or_equal( @@ -7628,10 +7796,13 @@ def greater_or_equal( return _GreaterOrEqual( _GreaterOrEqual.Attributes(), _GreaterOrEqual.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def grid_sample( @@ -7723,10 +7894,13 @@ def grid_sample( padding_mode=AttrString(padding_mode, name="padding_mode"), ), _GridSample.Inputs( - X=X, - grid=grid, + X=X._var_info, + grid=grid._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + grid=grid._value, + )["Y"] def hamming_window( @@ -7776,9 +7950,11 @@ def hamming_window( periodic=AttrInt64(periodic, name="periodic"), ), _HammingWindow.Inputs( - size=size, + size=size._var_info, ), - ).outputs.output + ).get_output_vars( + size=size._value, + )["output"] def hann_window( @@ -7828,9 +8004,11 @@ def hann_window( periodic=AttrInt64(periodic, name="periodic"), ), _HannWindow.Inputs( - size=size, + size=size._var_info, ), - ).outputs.output + ).get_output_vars( + size=size._value, + )["output"] def hard_sigmoid( @@ -7875,9 +8053,11 @@ def hard_sigmoid( beta=AttrFloat32(beta, name="beta"), ), _HardSigmoid.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def hard_swish( @@ -7911,9 +8091,11 @@ def hard_swish( return _HardSwish( _HardSwish.Attributes(), _HardSwish.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def hardmax( @@ -7960,9 +8142,11 @@ def hardmax( axis=AttrInt64(axis, name="axis"), ), _Hardmax.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def identity( @@ -7993,9 +8177,11 @@ def identity( return _Identity( _Identity.Attributes(), _Identity.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def if_( @@ -8058,10 +8244,12 @@ def if_( then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), ), _If.Inputs( - cond=cond, + cond=cond._var_info, ), out_variadic=len(_else_branch_subgraph.requested_results), - ).outputs.outputs + ).get_output_vars( + cond=cond._value, + )["outputs"] def instance_normalization( @@ -8115,11 +8303,15 @@ def instance_normalization( epsilon=AttrFloat32(epsilon, name="epsilon"), ), _InstanceNormalization.Inputs( - input=input, - scale=scale, - B=B, + input=input._var_info, + scale=scale._var_info, + B=B._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + scale=scale._value, + B=B._value, + )["output"] def isinf( @@ -8167,9 +8359,11 @@ def isinf( detect_positive=AttrInt64(detect_positive, name="detect_positive"), ), _IsInf.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def isnan( @@ -8201,9 +8395,11 @@ def isnan( return _IsNaN( _IsNaN.Attributes(), _IsNaN.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def lrn( @@ -8273,9 +8469,11 @@ def lrn( size=AttrInt64(size, name="size"), ), _LRN.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def lstm( @@ -8303,65 +8501,65 @@ def lstm( Notations: - - ``X`` - input tensor - - ``i`` - input gate - - ``o`` - output gate - - ``f`` - forget gate - - ``c`` - cell gate - - ``t`` - time step (t-1 means previous time step) - - ``W[iofc]`` - W parameter weight matrix for input, output, forget, and - cell gates - - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, - and cell gates - - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell - gates - - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell - gates - - ``P[iof]`` - P peephole weight vector for input, output, and forget - gates - - ``WB[iofc]`` - W parameter weight matrix for backward input, output, - forget, and cell gates - - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, - forget, and cell gates - - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, and - cell gates - - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, and - cell gates - - ``PB[iof]`` - P peephole weight vector for backward input, output, and - forget gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``i`` - input gate + - ``o`` - output gate + - ``f`` - forget gate + - ``c`` - cell gate + - ``t`` - time step (t-1 means previous time step) + - ``W[iofc]`` - W parameter weight matrix for input, output, forget, + and cell gates + - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, + and cell gates + - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell + gates + - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell + gates + - ``P[iof]`` - P peephole weight vector for input, output, and forget + gates + - ``WB[iofc]`` - W parameter weight matrix for backward input, output, + forget, and cell gates + - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, + forget, and cell gates + - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, + and cell gates + - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, + and cell gates + - ``PB[iof]`` - P peephole weight vector for backward input, output, + and forget gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): - - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) - - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) - - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) - - Ct = ft (.) Ct-1 + it (.) ct - - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) - - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See - `the doc `__ for - more details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + - Ct = ft (.) Ct-1 + it (.) ct + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See + `the doc `__ for + more details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -8472,30 +8670,45 @@ def lstm( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - return _LSTM( - _LSTM.Attributes( - activation_alpha=AttrFloat32s.maybe( - activation_alpha, name="activation_alpha" + return ( + _LSTM( + _LSTM.Attributes( + activation_alpha=AttrFloat32s.maybe( + activation_alpha, name="activation_alpha" + ), + activation_beta=AttrFloat32s.maybe( + activation_beta, name="activation_beta" + ), + activations=AttrStrings.maybe(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + input_forget=AttrInt64(input_forget, name="input_forget"), + layout=AttrInt64(layout, name="layout"), ), - activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), - activations=AttrStrings.maybe(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - input_forget=AttrInt64(input_forget, name="input_forget"), - layout=AttrInt64(layout, name="layout"), - ), - _LSTM.Inputs( - X=X, - W=W, - R=R, - B=B, - sequence_lens=sequence_lens, - initial_h=initial_h, - initial_c=initial_c, - P=P, - ), - ).outputs._unpack_to_any() + _LSTM.Inputs( + X=X._var_info, + W=W._var_info, + R=R._var_info, + B=B._var_info, + sequence_lens=sequence_lens._var_info, + initial_h=initial_h._var_info, + initial_c=initial_c._var_info, + P=P._var_info, + ), + ) + .get_output_vars( + X=X._value, + W=W._value, + R=R._value, + B=B._value, + sequence_lens=sequence_lens._value, + initial_h=initial_h._value, + initial_c=initial_c._value, + P=P._value, + ) + ._unpack_to_any() + ) def layer_normalization( @@ -8531,11 +8744,7 @@ def layer_normalization( indicate the i-th dimension of ``X``. If ``X``'s shape is ``[d[0], ..., d[axis-1], d[axis], ..., d[rank-1]]``, the shape of ``Mean`` and ``InvStdDev`` is ``[d[0], ..., d[axis-1], 1, ..., 1]``. - ``Y`` and ``X`` have the same shape. This operator supports - unidirectional broadcasting (tensors ``Scale`` and ``B`` should be - unidirectional broadcastable to tensor ``X``); for more details please - check `the - doc `__. + ``Y`` and ``X`` have the same shape. Parameters ========== @@ -8581,18 +8790,26 @@ def layer_normalization( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - U: `tensor(bfloat16)`, `tensor(float)` """ - return _LayerNormalization( - _LayerNormalization.Attributes( - axis=AttrInt64(axis, name="axis"), - epsilon=AttrFloat32(epsilon, name="epsilon"), - stash_type=AttrInt64(stash_type, name="stash_type"), - ), - _LayerNormalization.Inputs( - X=X, - Scale=Scale, - B=B, - ), - ).outputs._unpack_to_any() + return ( + _LayerNormalization( + _LayerNormalization.Attributes( + axis=AttrInt64(axis, name="axis"), + epsilon=AttrFloat32(epsilon, name="epsilon"), + stash_type=AttrInt64(stash_type, name="stash_type"), + ), + _LayerNormalization.Inputs( + X=X._var_info, + Scale=Scale._var_info, + B=B._var_info, + ), + ) + .get_output_vars( + X=X._value, + Scale=Scale._value, + B=B._value, + ) + ._unpack_to_any() + ) def leaky_relu( @@ -8633,9 +8850,11 @@ def leaky_relu( alpha=AttrFloat32(alpha, name="alpha"), ), _LeakyRelu.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def less( @@ -8677,10 +8896,13 @@ def less( return _Less( _Less.Attributes(), _Less.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def less_or_equal( @@ -8722,10 +8944,13 @@ def less_or_equal( return _LessOrEqual( _LessOrEqual.Attributes(), _LessOrEqual.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def log( @@ -8756,9 +8981,11 @@ def log( return _Log( _Log.Attributes(), _Log.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def log_softmax( @@ -8804,9 +9031,11 @@ def log_softmax( axis=AttrInt64(axis, name="axis"), ), _LogSoftmax.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def loop( @@ -8834,21 +9063,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond = - ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond = - true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -8995,12 +9224,16 @@ def loop( body=AttrGraph(_body_subgraph, name="body"), ), _Loop.Inputs( - M=M, - cond=cond, - v_initial=v_initial, + M=M._var_info, + cond=cond._var_info, + v_initial=v_initial._var_info, ), out_variadic=len(_body_subgraph.requested_results) - 1, - ).outputs.v_final_and_scan_outputs + ).get_output_vars( + M=M._value, + cond=cond._value, + v_initial=v_initial._value, + )["v_final_and_scan_outputs"] def lp_normalization( @@ -9043,9 +9276,11 @@ def lp_normalization( p=AttrInt64(p, name="p"), ), _LpNormalization.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def lp_pool( @@ -9128,9 +9363,11 @@ def lp_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _LpPool.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def matmul( @@ -9138,8 +9375,8 @@ def matmul( B: Var, ) -> Var: r""" - Matrix product that behaves like - `numpy.matmul `__. + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html Parameters ========== @@ -9166,10 +9403,13 @@ def matmul( return _MatMul( _MatMul.Attributes(), _MatMul.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.Y + ).get_output_vars( + A=A._value, + B=B._value, + )["Y"] def matmul_integer( @@ -9179,8 +9419,8 @@ def matmul_integer( b_zero_point: Optional[Var] = None, ) -> Var: r""" - Matrix product that behaves like - `numpy.matmul `__. + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. @@ -9227,12 +9467,17 @@ def matmul_integer( return _MatMulInteger( _MatMulInteger.Attributes(), _MatMulInteger.Inputs( - A=A, - B=B, - a_zero_point=a_zero_point, - b_zero_point=b_zero_point, + A=A._var_info, + B=B._var_info, + a_zero_point=a_zero_point._var_info, + b_zero_point=b_zero_point._var_info, ), - ).outputs.Y + ).get_output_vars( + A=A._value, + B=B._value, + a_zero_point=a_zero_point._value, + b_zero_point=b_zero_point._value, + )["Y"] def max( @@ -9267,9 +9512,11 @@ def max( return _Max( _Max.Attributes(), _Max.Inputs( - data_0=data_0, + data_0=data_0._var_info, ), - ).outputs.max + ).get_output_vars( + data_0=data_0._value, + )["max"] def max_pool( @@ -9408,20 +9655,26 @@ def max_pool( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int8)`, `tensor(uint8)` - I: `tensor(int64)` """ - return _MaxPool( - _MaxPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - storage_order=AttrInt64(storage_order, name="storage_order"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _MaxPool.Inputs( - X=X, - ), - ).outputs._unpack_to_any() + return ( + _MaxPool( + _MaxPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + storage_order=AttrInt64(storage_order, name="storage_order"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _MaxPool.Inputs( + X=X._var_info, + ), + ) + .get_output_vars( + X=X._value, + ) + ._unpack_to_any() + ) def max_roi_pool( @@ -9475,10 +9728,13 @@ def max_roi_pool( spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), ), _MaxRoiPool.Inputs( - X=X, - rois=rois, + X=X._var_info, + rois=rois._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + rois=rois._value, + )["Y"] def max_unpool( @@ -9584,11 +9840,15 @@ def max_unpool( strides=AttrInt64s.maybe(strides, name="strides"), ), _MaxUnpool.Inputs( - X=X, - I=I, - output_shape=output_shape, + X=X._var_info, + I=I._var_info, + output_shape=output_shape._var_info, ), - ).outputs.output + ).get_output_vars( + X=X._value, + I=I._value, + output_shape=output_shape._value, + )["output"] def mean( @@ -9623,9 +9883,11 @@ def mean( return _Mean( _Mean.Attributes(), _Mean.Inputs( - data_0=data_0, + data_0=data_0._var_info, ), - ).outputs.mean + ).get_output_vars( + data_0=data_0._value, + )["mean"] def mean_variance_normalization( @@ -9668,9 +9930,11 @@ def mean_variance_normalization( axes=AttrInt64s(axes, name="axes"), ), _MeanVarianceNormalization.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def mel_weight_matrix( @@ -9752,13 +10016,19 @@ def mel_weight_matrix( output_datatype=AttrInt64(output_datatype, name="output_datatype"), ), _MelWeightMatrix.Inputs( - num_mel_bins=num_mel_bins, - dft_length=dft_length, - sample_rate=sample_rate, - lower_edge_hertz=lower_edge_hertz, - upper_edge_hertz=upper_edge_hertz, + num_mel_bins=num_mel_bins._var_info, + dft_length=dft_length._var_info, + sample_rate=sample_rate._var_info, + lower_edge_hertz=lower_edge_hertz._var_info, + upper_edge_hertz=upper_edge_hertz._var_info, ), - ).outputs.output + ).get_output_vars( + num_mel_bins=num_mel_bins._value, + dft_length=dft_length._value, + sample_rate=sample_rate._value, + lower_edge_hertz=lower_edge_hertz._value, + upper_edge_hertz=upper_edge_hertz._value, + )["output"] def min( @@ -9793,9 +10063,11 @@ def min( return _Min( _Min.Attributes(), _Min.Inputs( - data_0=data_0, + data_0=data_0._var_info, ), - ).outputs.min + ).get_output_vars( + data_0=data_0._value, + )["min"] def mod( @@ -9855,10 +10127,13 @@ def mod( fmod=AttrInt64(fmod, name="fmod"), ), _Mod.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def mul( @@ -9901,10 +10176,13 @@ def mul( return _Mul( _Mul.Attributes(), _Mul.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def multinomial( @@ -9961,9 +10239,11 @@ def multinomial( seed=AttrFloat32.maybe(seed, name="seed"), ), _Multinomial.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def neg( @@ -9996,9 +10276,11 @@ def neg( return _Neg( _Neg.Attributes(), _Neg.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def negative_log_likelihood_loss( @@ -10164,11 +10446,15 @@ def negative_log_likelihood_loss( reduction=AttrString(reduction, name="reduction"), ), _NegativeLogLikelihoodLoss.Inputs( - input=input, - target=target, - weight=weight, + input=input._var_info, + target=target._var_info, + weight=weight._var_info, ), - ).outputs.loss + ).get_output_vars( + input=input._value, + target=target._value, + weight=weight._value, + )["loss"] def non_max_suppression( @@ -10242,13 +10528,19 @@ def non_max_suppression( center_point_box=AttrInt64(center_point_box, name="center_point_box"), ), _NonMaxSuppression.Inputs( - boxes=boxes, - scores=scores, - max_output_boxes_per_class=max_output_boxes_per_class, - iou_threshold=iou_threshold, - score_threshold=score_threshold, + boxes=boxes._var_info, + scores=scores._var_info, + max_output_boxes_per_class=max_output_boxes_per_class._var_info, + iou_threshold=iou_threshold._var_info, + score_threshold=score_threshold._var_info, ), - ).outputs.selected_indices + ).get_output_vars( + boxes=boxes._value, + scores=scores._value, + max_output_boxes_per_class=max_output_boxes_per_class._value, + iou_threshold=iou_threshold._value, + score_threshold=score_threshold._value, + )["selected_indices"] def non_zero( @@ -10283,9 +10575,11 @@ def non_zero( return _NonZero( _NonZero.Attributes(), _NonZero.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def not_( @@ -10316,9 +10610,11 @@ def not_( return _Not( _Not.Attributes(), _Not.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def one_hot( @@ -10407,11 +10703,15 @@ def one_hot( axis=AttrInt64(axis, name="axis"), ), _OneHot.Inputs( - indices=indices, - depth=depth, - values=values, + indices=indices._var_info, + depth=depth._var_info, + values=values._var_info, ), - ).outputs.output + ).get_output_vars( + indices=indices._value, + depth=depth._value, + values=values._value, + )["output"] def optional( @@ -10452,9 +10752,11 @@ def optional( type=AttrType.maybe(type, name="type"), ), _Optional.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def optional_get_element( @@ -10488,9 +10790,11 @@ def optional_get_element( return _OptionalGetElement( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def optional_has_element( @@ -10524,9 +10828,11 @@ def optional_has_element( return _OptionalHasElement( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def or_( @@ -10568,10 +10874,13 @@ def or_( return _Or( _Or.Attributes(), _Or.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def prelu( @@ -10613,10 +10922,13 @@ def prelu( return _PRelu( _PRelu.Attributes(), _PRelu.Inputs( - X=X, - slope=slope, + X=X._var_info, + slope=slope._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + slope=slope._value, + )["Y"] def pad( @@ -10718,11 +11030,15 @@ def pad( mode=AttrString(mode, name="mode"), ), _Pad.Inputs( - data=data, - pads=pads, - constant_value=constant_value, + data=data._var_info, + pads=pads._var_info, + constant_value=constant_value._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + pads=pads._value, + constant_value=constant_value._value, + )["output"] def pow( @@ -10763,10 +11079,13 @@ def pow( return _Pow( _Pow.Attributes(), _Pow.Inputs( - X=X, - Y=Y, + X=X._var_info, + Y=Y._var_info, ), - ).outputs.Z + ).get_output_vars( + X=X._value, + Y=Y._value, + )["Z"] def qlinear_conv( @@ -10919,17 +11238,27 @@ def qlinear_conv( strides=AttrInt64s.maybe(strides, name="strides"), ), _QLinearConv.Inputs( - x=x, - x_scale=x_scale, - x_zero_point=x_zero_point, - w=w, - w_scale=w_scale, - w_zero_point=w_zero_point, - y_scale=y_scale, - y_zero_point=y_zero_point, - B=B, - ), - ).outputs.y + x=x._var_info, + x_scale=x_scale._var_info, + x_zero_point=x_zero_point._var_info, + w=w._var_info, + w_scale=w_scale._var_info, + w_zero_point=w_zero_point._var_info, + y_scale=y_scale._var_info, + y_zero_point=y_zero_point._var_info, + B=B._var_info, + ), + ).get_output_vars( + x=x._value, + x_scale=x_scale._value, + x_zero_point=x_zero_point._value, + w=w._value, + w_scale=w_scale._value, + w_zero_point=w_zero_point._value, + y_scale=y_scale._value, + y_zero_point=y_zero_point._value, + B=B._value, + )["y"] def qlinear_matmul( @@ -10943,8 +11272,8 @@ def qlinear_matmul( y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like - `numpy.matmul `__. + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). For @@ -11007,16 +11336,25 @@ def qlinear_matmul( return _QLinearMatMul( _QLinearMatMul.Attributes(), _QLinearMatMul.Inputs( - a=a, - a_scale=a_scale, - a_zero_point=a_zero_point, - b=b, - b_scale=b_scale, - b_zero_point=b_zero_point, - y_scale=y_scale, - y_zero_point=y_zero_point, - ), - ).outputs.y + a=a._var_info, + a_scale=a_scale._var_info, + a_zero_point=a_zero_point._var_info, + b=b._var_info, + b_scale=b_scale._var_info, + b_zero_point=b_zero_point._var_info, + y_scale=y_scale._var_info, + y_zero_point=y_zero_point._var_info, + ), + ).get_output_vars( + a=a._value, + a_scale=a_scale._value, + a_zero_point=a_zero_point._value, + b=b._value, + b_scale=b_scale._value, + b_zero_point=b_zero_point._value, + y_scale=y_scale._value, + y_zero_point=y_zero_point._value, + )["y"] def quantize_linear( @@ -11078,11 +11416,15 @@ def quantize_linear( axis=AttrInt64(axis, name="axis"), ), _QuantizeLinear.Inputs( - x=x, - y_scale=y_scale, - y_zero_point=y_zero_point, + x=x._var_info, + y_scale=y_scale._var_info, + y_zero_point=y_zero_point._var_info, ), - ).outputs.y + ).get_output_vars( + x=x._value, + y_scale=y_scale._value, + y_zero_point=y_zero_point._value, + )["y"] def rnn( @@ -11107,46 +11449,46 @@ def rnn( Notations: - - ``X`` - input tensor - - ``i`` - input gate - - ``t`` - time step (t-1 means previous time step) - - ``Wi`` - W parameter weight matrix for input gate - - ``Ri`` - R recurrence weight matrix for input gate - - ``Wbi`` - W parameter bias vector for input gate - - ``Rbi`` - R parameter bias vector for input gate - - ``WBi`` - W parameter weight matrix for backward input gate - - ``RBi`` - R recurrence weight matrix for backward input gate - - ``WBbi`` - WR bias vectors for backward input gate - - ``RBbi`` - RR bias vectors for backward input gate - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``i`` - input gate + - ``t`` - time step (t-1 means previous time step) + - ``Wi`` - W parameter weight matrix for input gate + - ``Ri`` - R recurrence weight matrix for input gate + - ``Wbi`` - W parameter bias vector for input gate + - ``Rbi`` - R parameter bias vector for input gate + - ``WBi`` - W parameter weight matrix for backward input gate + - ``RBi`` - R recurrence weight matrix for backward input gate + - ``WBbi`` - WR bias vectors for backward input gate + - ``RBbi`` - RR bias vectors for backward input gate + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Tanh): - - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has - **optional** inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has + **optional** inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -11237,27 +11579,40 @@ def rnn( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - return _RNN( - _RNN.Attributes( - activation_alpha=AttrFloat32s.maybe( - activation_alpha, name="activation_alpha" + return ( + _RNN( + _RNN.Attributes( + activation_alpha=AttrFloat32s.maybe( + activation_alpha, name="activation_alpha" + ), + activation_beta=AttrFloat32s.maybe( + activation_beta, name="activation_beta" + ), + activations=AttrStrings(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + layout=AttrInt64(layout, name="layout"), ), - activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), - activations=AttrStrings(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - layout=AttrInt64(layout, name="layout"), - ), - _RNN.Inputs( - X=X, - W=W, - R=R, - B=B, - sequence_lens=sequence_lens, - initial_h=initial_h, - ), - ).outputs._unpack_to_any() + _RNN.Inputs( + X=X._var_info, + W=W._var_info, + R=R._var_info, + B=B._var_info, + sequence_lens=sequence_lens._var_info, + initial_h=initial_h._var_info, + ), + ) + .get_output_vars( + X=X._value, + W=W._value, + R=R._value, + B=B._value, + sequence_lens=sequence_lens._value, + initial_h=initial_h._value, + ) + ._unpack_to_any() + ) def random_normal( @@ -11320,7 +11675,7 @@ def random_normal( shape=AttrInt64s(shape, name="shape"), ), _RandomNormal.Inputs(), - ).outputs.output + ).get_output_vars()["output"] def random_normal_like( @@ -11384,9 +11739,11 @@ def random_normal_like( seed=AttrFloat32.maybe(seed, name="seed"), ), _RandomNormalLike.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def random_uniform( @@ -11448,7 +11805,7 @@ def random_uniform( shape=AttrInt64s(shape, name="shape"), ), _RandomUniform.Inputs(), - ).outputs.output + ).get_output_vars()["output"] def random_uniform_like( @@ -11512,9 +11869,11 @@ def random_uniform_like( seed=AttrFloat32.maybe(seed, name="seed"), ), _RandomUniformLike.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def range( @@ -11584,11 +11943,15 @@ def range( return _Range( _Range.Attributes(), _Range.Inputs( - start=start, - limit=limit, - delta=delta, + start=start._var_info, + limit=limit._var_info, + delta=delta._var_info, ), - ).outputs.output + ).get_output_vars( + start=start._value, + limit=limit._value, + delta=delta._value, + )["output"] def reciprocal( @@ -11621,9 +11984,11 @@ def reciprocal( return _Reciprocal( _Reciprocal.Attributes(), _Reciprocal.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def reduce_l1( @@ -11676,9 +12041,11 @@ def reduce_l1( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceL1.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def reduce_l2( @@ -11731,9 +12098,11 @@ def reduce_l2( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceL2.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def reduce_log_sum( @@ -11787,9 +12156,11 @@ def reduce_log_sum( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceLogSum.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def reduce_log_sum_exp( @@ -11843,9 +12214,11 @@ def reduce_log_sum_exp( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceLogSumExp.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def reduce_max( @@ -11900,9 +12273,11 @@ def reduce_max( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceMax.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def reduce_mean( @@ -11955,9 +12330,11 @@ def reduce_mean( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceMean.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def reduce_min( @@ -12011,9 +12388,11 @@ def reduce_min( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceMin.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def reduce_prod( @@ -12066,9 +12445,11 @@ def reduce_prod( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceProd.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def reduce_sum( @@ -12132,10 +12513,13 @@ def reduce_sum( ), ), _ReduceSum.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_sum_square( @@ -12188,9 +12572,11 @@ def reduce_sum_square( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceSumSquare.Inputs( - data=data, + data=data._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + )["reduced"] def relu( @@ -12223,9 +12609,11 @@ def relu( return _Relu( _Relu.Attributes(), _Relu.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def reshape( @@ -12284,10 +12672,13 @@ def reshape( allowzero=AttrInt64(allowzero, name="allowzero"), ), _Reshape.Inputs( - data=data, - shape=shape, + data=data._var_info, + shape=shape._var_info, ), - ).outputs.reshaped + ).get_output_vars( + data=data._value, + shape=shape._value, + )["reshaped"] def resize( @@ -12423,12 +12814,17 @@ def resize( nearest_mode=AttrString(nearest_mode, name="nearest_mode"), ), _Resize.Inputs( - X=X, - roi=roi, - scales=scales, - sizes=sizes, + X=X._var_info, + roi=roi._var_info, + scales=scales._var_info, + sizes=sizes._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + roi=roi._value, + scales=scales._value, + sizes=sizes._value, + )["Y"] def reverse_sequence( @@ -12499,10 +12895,13 @@ def reverse_sequence( time_axis=AttrInt64(time_axis, name="time_axis"), ), _ReverseSequence.Inputs( - input=input, - sequence_lens=sequence_lens, + input=input._var_info, + sequence_lens=sequence_lens._var_info, ), - ).outputs.Y + ).get_output_vars( + input=input._value, + sequence_lens=sequence_lens._value, + )["Y"] def roi_align( @@ -12604,11 +13003,15 @@ def roi_align( spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), ), _RoiAlign.Inputs( - X=X, - rois=rois, - batch_indices=batch_indices, + X=X._var_info, + rois=rois._var_info, + batch_indices=batch_indices._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + rois=rois._value, + batch_indices=batch_indices._value, + )["Y"] def round( @@ -12653,9 +13056,11 @@ def round( return _Round( _Round.Attributes(), _Round.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def stft( @@ -12724,12 +13129,17 @@ def stft( onesided=AttrInt64(onesided, name="onesided"), ), _STFT.Inputs( - signal=signal, - frame_step=frame_step, - window=window, - frame_length=frame_length, + signal=signal._var_info, + frame_step=frame_step._var_info, + window=window._var_info, + frame_length=frame_length._var_info, ), - ).outputs.output + ).get_output_vars( + signal=signal._value, + frame_step=frame_step._value, + window=window._value, + frame_length=frame_length._value, + )["output"] def scan( @@ -12969,10 +13379,12 @@ def scan( ), ), _Scan.Inputs( - initial_state_and_scan_inputs=initial_state_and_scan_inputs, + initial_state_and_scan_inputs=initial_state_and_scan_inputs._var_info, ), out_variadic=len(_body_subgraph.requested_results), - ).outputs.final_state_and_scan_outputs + ).get_output_vars( + initial_state_and_scan_inputs=initial_state_and_scan_inputs._value, + )["final_state_and_scan_outputs"] def scatter_elements( @@ -13101,11 +13513,15 @@ def scatter_elements( reduction=AttrString(reduction, name="reduction"), ), _ScatterElements.Inputs( - data=data, - indices=indices, - updates=updates, + data=data._var_info, + indices=indices._var_info, + updates=updates._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + indices=indices._value, + updates=updates._value, + )["output"] def scatter_nd( @@ -13222,11 +13638,15 @@ def scatter_nd( reduction=AttrString(reduction, name="reduction"), ), _ScatterND.Inputs( - data=data, - indices=indices, - updates=updates, + data=data._var_info, + indices=indices._var_info, + updates=updates._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + indices=indices._value, + updates=updates._value, + )["output"] def selu( @@ -13274,9 +13694,11 @@ def selu( gamma=AttrFloat32(gamma, name="gamma"), ), _Selu.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def sequence_at( @@ -13320,10 +13742,13 @@ def sequence_at( return _SequenceAt( _SequenceAt.Attributes(), _SequenceAt.Inputs( - input_sequence=input_sequence, - position=position, + input_sequence=input_sequence._var_info, + position=position._var_info, ), - ).outputs.tensor + ).get_output_vars( + input_sequence=input_sequence._value, + position=position._value, + )["tensor"] def sequence_construct( @@ -13356,9 +13781,11 @@ def sequence_construct( return _SequenceConstruct( _SequenceConstruct.Attributes(), _SequenceConstruct.Inputs( - inputs=inputs, + inputs=inputs._var_info, ), - ).outputs.output_sequence + ).get_output_vars( + inputs=inputs._value, + )["output_sequence"] def sequence_empty( @@ -13393,7 +13820,7 @@ def sequence_empty( dtype=AttrDtype.maybe(dtype, name="dtype"), ), _SequenceEmpty.Inputs(), - ).outputs.output + ).get_output_vars()["output"] def sequence_erase( @@ -13437,10 +13864,13 @@ def sequence_erase( return _SequenceErase( _SequenceErase.Attributes(), _SequenceErase.Inputs( - input_sequence=input_sequence, - position=position, + input_sequence=input_sequence._var_info, + position=position._var_info, ), - ).outputs.output_sequence + ).get_output_vars( + input_sequence=input_sequence._value, + position=position._value, + )["output_sequence"] def sequence_insert( @@ -13491,11 +13921,15 @@ def sequence_insert( return _SequenceInsert( _SequenceInsert.Attributes(), _SequenceInsert.Inputs( - input_sequence=input_sequence, - tensor=tensor, - position=position, + input_sequence=input_sequence._var_info, + tensor=tensor._var_info, + position=position._var_info, ), - ).outputs.output_sequence + ).get_output_vars( + input_sequence=input_sequence._value, + tensor=tensor._value, + position=position._value, + )["output_sequence"] def sequence_length( @@ -13528,9 +13962,11 @@ def sequence_length( return _SequenceLength( _SequenceLength.Attributes(), _SequenceLength.Inputs( - input_sequence=input_sequence, + input_sequence=input_sequence._var_info, ), - ).outputs.length + ).get_output_vars( + input_sequence=input_sequence._value, + )["length"] def sequence_map( @@ -13598,11 +14034,14 @@ def sequence_map( body=AttrGraph(_body_subgraph, name="body"), ), _SequenceMap.Inputs( - input_sequence=input_sequence, - additional_inputs=additional_inputs, + input_sequence=input_sequence._var_info, + additional_inputs=additional_inputs._var_info, ), out_variadic=len(_body_subgraph.requested_results), - ).outputs.out_sequence + ).get_output_vars( + input_sequence=input_sequence._value, + additional_inputs=additional_inputs._value, + )["out_sequence"] def shape( @@ -13687,9 +14126,11 @@ def shape( start=AttrInt64(start, name="start"), ), _Shape.Inputs( - data=data, + data=data._var_info, ), - ).outputs.shape + ).get_output_vars( + data=data._value, + )["shape"] def shrink( @@ -13735,9 +14176,11 @@ def shrink( lambd=AttrFloat32(lambd, name="lambd"), ), _Shrink.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def sigmoid( @@ -13770,9 +14213,11 @@ def sigmoid( return _Sigmoid( _Sigmoid.Attributes(), _Sigmoid.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def sign( @@ -13805,9 +14250,11 @@ def sign( return _Sign( _Sign.Attributes(), _Sign.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def sin( @@ -13838,9 +14285,11 @@ def sin( return _Sin( _Sin.Attributes(), _Sin.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def sinh( @@ -13871,9 +14320,11 @@ def sinh( return _Sinh( _Sinh.Attributes(), _Sinh.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def size( @@ -13906,9 +14357,11 @@ def size( return _Size( _Size.Attributes(), _Size.Inputs( - data=data, + data=data._var_info, ), - ).outputs.size + ).get_output_vars( + data=data._value, + )["size"] def slice( @@ -14027,13 +14480,19 @@ def slice( return _Slice( _Slice.Attributes(), _Slice.Inputs( - data=data, - starts=starts, - ends=ends, - axes=axes, - steps=steps, + data=data._var_info, + starts=starts._var_info, + ends=ends._var_info, + axes=axes._var_info, + steps=steps._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + starts=starts._value, + ends=ends._value, + axes=axes._value, + steps=steps._value, + )["output"] def softmax( @@ -14081,9 +14540,11 @@ def softmax( axis=AttrInt64(axis, name="axis"), ), _Softmax.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def softmax_cross_entropy_loss( @@ -14104,10 +14565,10 @@ def softmax_cross_entropy_loss( L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. After L is available, this operator can optionally do a reduction operator. - - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, - D2,..., Dk), with K >= 1 in case of K-dimensional loss. - - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, - D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, + D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, + D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. The loss for one sample, l_i, can calculated as follows: @@ -14137,13 +14598,13 @@ def softmax_cross_entropy_loss( Finally, L is optionally reduced: - - If reduction = 'none', the output is L with shape (N, D1, D2, ..., - Dk). - - If reduction = 'sum', the output is scalar: Sum(L). - - If reduction = 'mean', the output is scalar: ReduceMean(L), or if - weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W is - of shape ``(N, D1, D2, ..., Dk)`` and - ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. + - If reduction = 'none', the output is L with shape (N, D1, D2, ..., + Dk). + - If reduction = 'sum', the output is scalar: Sum(L). + - If reduction = 'mean', the output is scalar: ReduceMean(L), or if + weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W + is of shape ``(N, D1, D2, ..., Dk)`` and + ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. Parameters ========== @@ -14195,17 +14656,25 @@ def softmax_cross_entropy_loss( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _SoftmaxCrossEntropyLoss( - _SoftmaxCrossEntropyLoss.Attributes( - ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), - reduction=AttrString(reduction, name="reduction"), - ), - _SoftmaxCrossEntropyLoss.Inputs( - scores=scores, - labels=labels, - weights=weights, - ), - ).outputs._unpack_to_any() + return ( + _SoftmaxCrossEntropyLoss( + _SoftmaxCrossEntropyLoss.Attributes( + ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), + reduction=AttrString(reduction, name="reduction"), + ), + _SoftmaxCrossEntropyLoss.Inputs( + scores=scores._var_info, + labels=labels._var_info, + weights=weights._var_info, + ), + ) + .get_output_vars( + scores=scores._value, + labels=labels._value, + weights=weights._value, + ) + ._unpack_to_any() + ) def softplus( @@ -14238,9 +14707,11 @@ def softplus( return _Softplus( _Softplus.Attributes(), _Softplus.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def softsign( @@ -14273,9 +14744,11 @@ def softsign( return _Softsign( _Softsign.Attributes(), _Softsign.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def space_to_depth( @@ -14317,9 +14790,11 @@ def space_to_depth( blocksize=AttrInt64(blocksize, name="blocksize"), ), _SpaceToDepth.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def split( @@ -14369,11 +14844,14 @@ def split( axis=AttrInt64(axis, name="axis"), ), _Split.Inputs( - input=input, - split=split, + input=input._var_info, + split=split._var_info, ), out_variadic=outputs_count, - ).outputs.outputs + ).get_output_vars( + input=input._value, + split=split._value, + )["outputs"] def split_to_sequence( @@ -14437,10 +14915,13 @@ def split_to_sequence( keepdims=AttrInt64(keepdims, name="keepdims"), ), _SplitToSequence.Inputs( - input=input, - split=split, + input=input._var_info, + split=split._var_info, ), - ).outputs.output_sequence + ).get_output_vars( + input=input._value, + split=split._value, + )["output_sequence"] def sqrt( @@ -14473,9 +14954,11 @@ def sqrt( return _Sqrt( _Sqrt.Attributes(), _Sqrt.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def squeeze( @@ -14516,10 +14999,13 @@ def squeeze( return _Squeeze( _Squeeze.Attributes(), _Squeeze.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.squeezed + ).get_output_vars( + data=data._value, + axes=axes._value, + )["squeezed"] def string_normalizer( @@ -14584,9 +15070,11 @@ def string_normalizer( stopwords=AttrStrings.maybe(stopwords, name="stopwords"), ), _StringNormalizer.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def sub( @@ -14629,10 +15117,13 @@ def sub( return _Sub( _Sub.Attributes(), _Sub.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def sum( @@ -14667,9 +15158,11 @@ def sum( return _Sum( _Sum.Attributes(), _Sum.Inputs( - data_0=data_0, + data_0=data_0._var_info, ), - ).outputs.sum + ).get_output_vars( + data_0=data_0._value, + )["sum"] def tan( @@ -14700,9 +15193,11 @@ def tan( return _Tan( _Tan.Attributes(), _Tan.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def tanh( @@ -14734,9 +15229,11 @@ def tanh( return _Tanh( _Tanh.Attributes(), _Tanh.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def tf_idf_vectorizer( @@ -14881,9 +15378,11 @@ def tf_idf_vectorizer( weights=AttrFloat32s.maybe(weights, name="weights"), ), _TfIdfVectorizer.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def thresholded_relu( @@ -14923,9 +15422,11 @@ def thresholded_relu( alpha=AttrFloat32(alpha, name="alpha"), ), _ThresholdedRelu.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def tile( @@ -14965,10 +15466,13 @@ def tile( return _Tile( _Tile.Attributes(), _Tile.Inputs( - input=input, - repeats=repeats, + input=input._var_info, + repeats=repeats._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + repeats=repeats._value, + )["output"] def top_k( @@ -14981,25 +15485,25 @@ def top_k( ) -> tuple[Var, Var]: r""" Retrieve the top-K largest or smallest elements along a specified axis. - Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer + Given an input tensor of shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs: - - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] which contains the values of the top k elements along the - specified axis + - Value tensor of shape [a_1, a_2, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a_n] which contains the values of the top k elements along the + specified axis - - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] which contains the indices of the top k elements (original - indices from the input tensor). + - Index tensor of shape [a_1, a_2, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a_n] which contains the indices of the top k elements (original + indices from the input tensor). - - If "largest" is 1 (the default value) then the k largest elements are - returned. + - If "largest" is 1 (the default value) then the k largest elements are + returned. - - If "sorted" is 1 (the default value) then the resulting k elements - will be sorted. + - If "sorted" is 1 (the default value) then the resulting k elements + will be sorted. - - If "sorted" is 0, order of returned 'Values' and 'Indices' are - undefined. + - If "sorted" is 0, order of returned 'Values' and 'Indices' are + undefined. Given two equivalent values, this operator uses the indices along the axis as a tiebreaker. That is, the element with the lower index will @@ -15009,7 +15513,7 @@ def top_k( ========== X Type T. - Tensor of shape [a_0, a_1, ..., a\_{n-1}] + Tensor of shape [a_1, a_2, ..., a_n, r] K Type tensor(int64). A 1-D tensor containing a single positive value corresponding to the @@ -15030,13 +15534,12 @@ def top_k( ======= Values : Var Type T. - Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] containing top K values from the input tensor + Tensor of shape [a_1, a_2, ..., a\_{axis-1}, k, a\_{axis+1}, ... a_n] + containing top K values from the input tensor Indices : Var Type I. - Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] containing the corresponding input tensor indices for the top - K values. + Tensor of shape [a_1, a_2, ..., a\_{axis-1}, k, a\_{axis+1}, ... a_n] + containing the corresponding input tensor indices for the top K values. Notes ===== @@ -15046,17 +15549,24 @@ def top_k( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - I: `tensor(int64)` """ - return _TopK( - _TopK.Attributes( - axis=AttrInt64(axis, name="axis"), - largest=AttrInt64(largest, name="largest"), - sorted=AttrInt64(sorted, name="sorted"), - ), - _TopK.Inputs( - X=X, - K=K, - ), - ).outputs._unpack_to_any() + return ( + _TopK( + _TopK.Attributes( + axis=AttrInt64(axis, name="axis"), + largest=AttrInt64(largest, name="largest"), + sorted=AttrInt64(sorted, name="sorted"), + ), + _TopK.Inputs( + X=X._var_info, + K=K._var_info, + ), + ) + .get_output_vars( + X=X._value, + K=K._value, + ) + ._unpack_to_any() + ) def transpose( @@ -15097,9 +15607,11 @@ def transpose( perm=AttrInt64s.maybe(perm, name="perm"), ), _Transpose.Inputs( - data=data, + data=data._var_info, ), - ).outputs.transposed + ).get_output_vars( + data=data._value, + )["transposed"] def trilu( @@ -15160,10 +15672,13 @@ def trilu( upper=AttrInt64(upper, name="upper"), ), _Trilu.Inputs( - input=input, - k=k, + input=input._var_info, + k=k._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + k=k._value, + )["output"] def unique( @@ -15335,15 +15850,21 @@ def unique( Type constraints: - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Unique( - _Unique.Attributes( - axis=AttrInt64.maybe(axis, name="axis"), - sorted=AttrInt64(sorted, name="sorted"), - ), - _Unique.Inputs( - X=X, - ), - ).outputs._unpack_to_any() + return ( + _Unique( + _Unique.Attributes( + axis=AttrInt64.maybe(axis, name="axis"), + sorted=AttrInt64(sorted, name="sorted"), + ), + _Unique.Inputs( + X=X._var_info, + ), + ) + .get_output_vars( + X=X._value, + ) + ._unpack_to_any() + ) def unsqueeze( @@ -15394,10 +15915,13 @@ def unsqueeze( return _Unsqueeze( _Unsqueeze.Attributes(), _Unsqueeze.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.expanded + ).get_output_vars( + data=data._value, + axes=axes._value, + )["expanded"] def where( @@ -15444,11 +15968,15 @@ def where( return _Where( _Where.Attributes(), _Where.Inputs( - condition=condition, - X=X, - Y=Y, + condition=condition._var_info, + X=X._var_info, + Y=Y._var_info, ), - ).outputs.output + ).get_output_vars( + condition=condition._value, + X=X._value, + Y=Y._value, + )["output"] def xor( @@ -15490,10 +16018,13 @@ def xor( return _Xor( _Xor.Attributes(), _Xor.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index 028c0775..7db88912 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -937,10 +937,13 @@ def bitwise_and( return _BitwiseAnd( _BitwiseAnd.Attributes(), _BitwiseAnd.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def bitwise_not( @@ -971,9 +974,11 @@ def bitwise_not( return _BitwiseNot( _BitwiseNot.Attributes(), _BitwiseNot.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def bitwise_or( @@ -1014,10 +1019,13 @@ def bitwise_or( return _BitwiseOr( _BitwiseOr.Attributes(), _BitwiseOr.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def bitwise_xor( @@ -1058,10 +1066,13 @@ def bitwise_xor( return _BitwiseXor( _BitwiseXor.Attributes(), _BitwiseXor.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def center_crop_pad( @@ -1116,10 +1127,13 @@ def center_crop_pad( axes=AttrInt64s.maybe(axes, name="axes"), ), _CenterCropPad.Inputs( - input_data=input_data, - shape=shape, + input_data=input_data._var_info, + shape=shape._var_info, ), - ).outputs.output_data + ).get_output_vars( + input_data=input_data._value, + shape=shape._value, + )["output_data"] def col2_im( @@ -1209,11 +1223,15 @@ def col2_im( strides=AttrInt64s.maybe(strides, name="strides"), ), _Col2Im.Inputs( - input=input, - image_shape=image_shape, - block_shape=block_shape, + input=input._var_info, + image_shape=image_shape._var_info, + block_shape=block_shape._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + image_shape=image_shape._value, + block_shape=block_shape._value, + )["output"] def group_normalization( @@ -1287,11 +1305,15 @@ def group_normalization( num_groups=AttrInt64(num_groups, name="num_groups"), ), _GroupNormalization.Inputs( - X=X, - scale=scale, - bias=bias, + X=X._var_info, + scale=scale._var_info, + bias=bias._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + scale=scale._value, + bias=bias._value, + )["Y"] def lp_pool( @@ -1413,9 +1435,11 @@ def lp_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _LpPool.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def mish( @@ -1453,9 +1477,11 @@ def mish( return _Mish( _Mish.Attributes(), _Mish.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def optional_get_element( @@ -1490,9 +1516,11 @@ def optional_get_element( return _OptionalGetElement( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def optional_has_element( @@ -1527,9 +1555,11 @@ def optional_has_element( return _OptionalHasElement( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def pad( @@ -1671,12 +1701,17 @@ def pad( mode=AttrString(mode, name="mode"), ), _Pad.Inputs( - data=data, - pads=pads, - constant_value=constant_value, - axes=axes, + data=data._var_info, + pads=pads._var_info, + constant_value=constant_value._var_info, + axes=axes._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + pads=pads._value, + constant_value=constant_value._value, + axes=axes._value, + )["output"] def reduce_l1( @@ -1740,10 +1775,13 @@ def reduce_l1( ), ), _ReduceL1.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_l2( @@ -1807,10 +1845,13 @@ def reduce_l2( ), ), _ReduceL2.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_log_sum( @@ -1875,10 +1916,13 @@ def reduce_log_sum( ), ), _ReduceLogSum.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_log_sum_exp( @@ -1943,10 +1987,13 @@ def reduce_log_sum_exp( ), ), _ReduceLogSumExp.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_max( @@ -2012,10 +2059,13 @@ def reduce_max( ), ), _ReduceMax.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_mean( @@ -2079,10 +2129,13 @@ def reduce_mean( ), ), _ReduceMean.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_min( @@ -2147,10 +2200,13 @@ def reduce_min( ), ), _ReduceMin.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_prod( @@ -2214,10 +2270,13 @@ def reduce_prod( ), ), _ReduceProd.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_sum_square( @@ -2281,10 +2340,13 @@ def reduce_sum_square( ), ), _ReduceSumSquare.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def resize( @@ -2476,12 +2538,17 @@ def resize( nearest_mode=AttrString(nearest_mode, name="nearest_mode"), ), _Resize.Inputs( - X=X, - roi=roi, - scales=scales, - sizes=sizes, + X=X._var_info, + roi=roi._var_info, + scales=scales._var_info, + sizes=sizes._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + roi=roi._value, + scales=scales._value, + sizes=sizes._value, + )["Y"] def scatter_elements( @@ -2613,11 +2680,15 @@ def scatter_elements( reduction=AttrString(reduction, name="reduction"), ), _ScatterElements.Inputs( - data=data, - indices=indices, - updates=updates, + data=data._var_info, + indices=indices._var_info, + updates=updates._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + indices=indices._value, + updates=updates._value, + )["output"] def scatter_nd( @@ -2750,11 +2821,15 @@ def scatter_nd( reduction=AttrString(reduction, name="reduction"), ), _ScatterND.Inputs( - data=data, - indices=indices, - updates=updates, + data=data._var_info, + indices=indices._var_info, + updates=updates._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + indices=indices._value, + updates=updates._value, + )["output"] def split( @@ -2810,11 +2885,14 @@ def split( num_outputs=AttrInt64.maybe(num_outputs, name="num_outputs"), ), _Split.Inputs( - input=input, - split=split, + input=input._var_info, + split=split._var_info, ), out_variadic=num_outputs, - ).outputs.outputs + ).get_output_vars( + input=input._value, + split=split._value, + )["outputs"] def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 6c14823d..5fbc7748 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -926,9 +926,11 @@ def average_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _AveragePool.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def cast( @@ -968,26 +970,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules if the destination type is not a float 8 type. - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Float 8 type were introduced to speed up the training of deep models. By default the conversion of a float *x* obeys to the following rules. @@ -1058,9 +1060,11 @@ def cast( to=AttrDtype(to, name="to"), ), _Cast.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def cast_like( @@ -1111,10 +1115,13 @@ def cast_like( saturate=AttrInt64(saturate, name="saturate"), ), _CastLike.Inputs( - input=input, - target_type=target_type, + input=input._var_info, + target_type=target_type._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + target_type=target_type._value, + )["output"] def constant( @@ -1183,7 +1190,7 @@ def constant( value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), _Constant.Inputs(), - ).outputs.output + ).get_output_vars()["output"] def deform_conv( @@ -1292,13 +1299,19 @@ def deform_conv( strides=AttrInt64s.maybe(strides, name="strides"), ), _DeformConv.Inputs( - X=X, - W=W, - offset=offset, - B=B, - mask=mask, + X=X._var_info, + W=W._var_info, + offset=offset._var_info, + B=B._var_info, + mask=mask._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + W=W._value, + offset=offset._value, + B=B._value, + mask=mask._value, + )["Y"] def dequantize_linear( @@ -1338,11 +1351,9 @@ def dequantize_linear( axis Attribute. (Optional) The axis of the dequantizing dimension of the input tensor. - Used only for per-axis quantization. Negative value means counting - dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. When the rank of the input is 1, per-tensor - quantization is applied, rendering the axis unnecessary in this - scenario. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). Returns ======= @@ -1363,11 +1374,15 @@ def dequantize_linear( axis=AttrInt64(axis, name="axis"), ), _DequantizeLinear.Inputs( - x=x, - x_scale=x_scale, - x_zero_point=x_zero_point, + x=x._var_info, + x_scale=x_scale._var_info, + x_zero_point=x_zero_point._var_info, ), - ).outputs.y + ).get_output_vars( + x=x._value, + x_scale=x_scale._value, + x_zero_point=x_zero_point._value, + )["y"] def equal( @@ -1409,10 +1424,13 @@ def equal( return _Equal( _Equal.Attributes(), _Equal.Inputs( - A=A, - B=B, + A=A._var_info, + B=B._var_info, ), - ).outputs.C + ).get_output_vars( + A=A._value, + B=B._value, + )["C"] def identity( @@ -1443,9 +1461,11 @@ def identity( return _Identity( _Identity.Attributes(), _Identity.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def if_( @@ -1508,10 +1528,12 @@ def if_( then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), ), _If.Inputs( - cond=cond, + cond=cond._var_info, ), out_variadic=len(_else_branch_subgraph.requested_results), - ).outputs.outputs + ).get_output_vars( + cond=cond._value, + )["outputs"] def loop( @@ -1539,21 +1561,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond = - ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond = - true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -1700,12 +1722,16 @@ def loop( body=AttrGraph(_body_subgraph, name="body"), ), _Loop.Inputs( - M=M, - cond=cond, - v_initial=v_initial, + M=M._var_info, + cond=cond._var_info, + v_initial=v_initial._var_info, ), out_variadic=len(_body_subgraph.requested_results) - 1, - ).outputs.v_final_and_scan_outputs + ).get_output_vars( + M=M._value, + cond=cond._value, + v_initial=v_initial._value, + )["v_final_and_scan_outputs"] def pad( @@ -1873,12 +1899,17 @@ def pad( mode=AttrString(mode, name="mode"), ), _Pad.Inputs( - data=data, - pads=pads, - constant_value=constant_value, - axes=axes, + data=data._var_info, + pads=pads._var_info, + constant_value=constant_value._var_info, + axes=axes._var_info, ), - ).outputs.output + ).get_output_vars( + data=data._value, + pads=pads._value, + constant_value=constant_value._value, + axes=axes._value, + )["output"] def quantize_linear( @@ -1953,11 +1984,15 @@ def quantize_linear( saturate=AttrInt64(saturate, name="saturate"), ), _QuantizeLinear.Inputs( - x=x, - y_scale=y_scale, - y_zero_point=y_zero_point, + x=x._var_info, + y_scale=y_scale._var_info, + y_zero_point=y_zero_point._var_info, ), - ).outputs.y + ).get_output_vars( + x=x._value, + y_scale=y_scale._value, + y_zero_point=y_zero_point._value, + )["y"] def reshape( @@ -2016,10 +2051,13 @@ def reshape( allowzero=AttrInt64(allowzero, name="allowzero"), ), _Reshape.Inputs( - data=data, - shape=shape, + data=data._var_info, + shape=shape._var_info, ), - ).outputs.reshaped + ).get_output_vars( + data=data._value, + shape=shape._value, + )["reshaped"] def resize( @@ -2249,12 +2287,17 @@ def resize( nearest_mode=AttrString(nearest_mode, name="nearest_mode"), ), _Resize.Inputs( - X=X, - roi=roi, - scales=scales, - sizes=sizes, + X=X._var_info, + roi=roi._var_info, + scales=scales._var_info, + sizes=sizes._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + roi=roi._value, + scales=scales._value, + sizes=sizes._value, + )["Y"] def scan( @@ -2494,10 +2537,12 @@ def scan( ), ), _Scan.Inputs( - initial_state_and_scan_inputs=initial_state_and_scan_inputs, + initial_state_and_scan_inputs=initial_state_and_scan_inputs._var_info, ), out_variadic=len(_body_subgraph.requested_results), - ).outputs.final_state_and_scan_outputs + ).get_output_vars( + initial_state_and_scan_inputs=initial_state_and_scan_inputs._value, + )["final_state_and_scan_outputs"] def shape( @@ -2582,9 +2627,11 @@ def shape( start=AttrInt64(start, name="start"), ), _Shape.Inputs( - data=data, + data=data._var_info, ), - ).outputs.shape + ).get_output_vars( + data=data._value, + )["shape"] def size( @@ -2617,9 +2664,11 @@ def size( return _Size( _Size.Attributes(), _Size.Inputs( - data=data, + data=data._var_info, ), - ).outputs.size + ).get_output_vars( + data=data._value, + )["size"] def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index fa5a4c42..275fb408 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -738,10 +738,13 @@ def affine_grid( align_corners=AttrInt64(align_corners, name="align_corners"), ), _AffineGrid.Inputs( - theta=theta, - size=size, + theta=theta._var_info, + size=size._var_info, ), - ).outputs.grid + ).get_output_vars( + theta=theta._value, + size=size._value, + )["grid"] def constant_of_shape( @@ -786,9 +789,11 @@ def constant_of_shape( value=AttrTensor.maybe(value, name="value"), ), _ConstantOfShape.Inputs( - input=input, + input=input._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + )["output"] def dft( @@ -887,11 +892,15 @@ def dft( onesided=AttrInt64(onesided, name="onesided"), ), _DFT.Inputs( - input=input, - dft_length=dft_length, - axis=axis, + input=input._var_info, + dft_length=dft_length._var_info, + axis=axis._var_info, ), - ).outputs.output + ).get_output_vars( + input=input._value, + dft_length=dft_length._value, + axis=axis._value, + )["output"] def gelu( @@ -937,9 +946,11 @@ def gelu( approximate=AttrString(approximate, name="approximate"), ), _Gelu.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def grid_sample( @@ -1051,10 +1062,13 @@ def grid_sample( padding_mode=AttrString(padding_mode, name="padding_mode"), ), _GridSample.Inputs( - X=X, - grid=grid, + X=X._var_info, + grid=grid._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + grid=grid._value, + )["Y"] def image_decoder( @@ -1067,21 +1081,21 @@ def image_decoder( reason (e.g. corrupted encoded stream, invalid format, it will return an empty matrix). The following image formats are supported: - - BMP - - JPEG (note: Lossless JPEG support is optional) - - JPEG2000 - - TIFF - - PNG - - WebP - - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow - a channel-last layout: (Height, Width, Channels). **JPEG chroma - upsampling method:** When upsampling the chroma components by a factor - of 2, the pixels are linearly interpolated so that the centers of the - output pixels are 1/4 and 3/4 of the way between input pixel centers. - When rounding, 0.5 is rounded down and up at alternative pixels - locations to prevent bias towards larger values (ordered dither - pattern). Considering adjacent input pixels A, B, and C, B is - upsampled to pixels B0 and B1 so that + - BMP + - JPEG (note: Lossless JPEG support is optional) + - JPEG2000 + - TIFF + - PNG + - WebP + - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow + a channel-last layout: (Height, Width, Channels). **JPEG chroma + upsampling method:** When upsampling the chroma components by a + factor of 2, the pixels are linearly interpolated so that the centers + of the output pixels are 1/4 and 3/4 of the way between input pixel + centers. When rounding, 0.5 is rounded down and up at alternative + pixels locations to prevent bias towards larger values (ordered + dither pattern). Considering adjacent input pixels A, B, and C, B is + upsampled to pixels B0 and B1 so that :: @@ -1120,9 +1134,11 @@ def image_decoder( pixel_format=AttrString(pixel_format, name="pixel_format"), ), _ImageDecoder.Inputs( - encoded_stream=encoded_stream, + encoded_stream=encoded_stream._var_info, ), - ).outputs.image + ).get_output_vars( + encoded_stream=encoded_stream._value, + )["image"] def isinf( @@ -1170,9 +1186,11 @@ def isinf( detect_positive=AttrInt64(detect_positive, name="detect_positive"), ), _IsInf.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def isnan( @@ -1204,9 +1222,11 @@ def isnan( return _IsNaN( _IsNaN.Attributes(), _IsNaN.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def reduce_max( @@ -1275,10 +1295,13 @@ def reduce_max( ), ), _ReduceMax.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def reduce_min( @@ -1346,10 +1369,13 @@ def reduce_min( ), ), _ReduceMin.Inputs( - data=data, - axes=axes, + data=data._var_info, + axes=axes._var_info, ), - ).outputs.reduced + ).get_output_vars( + data=data._value, + axes=axes._value, + )["reduced"] def regex_full_match( @@ -1393,9 +1419,11 @@ def regex_full_match( pattern=AttrString.maybe(pattern, name="pattern"), ), _RegexFullMatch.Inputs( - X=X, + X=X._var_info, ), - ).outputs.Y + ).get_output_vars( + X=X._value, + )["Y"] def string_concat( @@ -1431,10 +1459,13 @@ def string_concat( return _StringConcat( _StringConcat.Attributes(), _StringConcat.Inputs( - X=X, - Y=Y, + X=X._var_info, + Y=Y._var_info, ), - ).outputs.Z + ).get_output_vars( + X=X._value, + Y=Y._value, + )["Z"] def string_split( @@ -1506,15 +1537,21 @@ def string_split( - T2: `tensor(string)` - T3: `tensor(int64)` """ - return _StringSplit( - _StringSplit.Attributes( - delimiter=AttrString.maybe(delimiter, name="delimiter"), - maxsplit=AttrInt64.maybe(maxsplit, name="maxsplit"), - ), - _StringSplit.Inputs( - X=X, - ), - ).outputs._unpack_to_any() + return ( + _StringSplit( + _StringSplit.Attributes( + delimiter=AttrString.maybe(delimiter, name="delimiter"), + maxsplit=AttrInt64.maybe(maxsplit, name="maxsplit"), + ), + _StringSplit.Inputs( + X=X._var_info, + ), + ) + .get_output_vars( + X=X._value, + ) + ._unpack_to_any() + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: diff --git a/tools/generate_opset.py b/tools/generate_opset.py index 399a311f..7d1a9e95 100644 --- a/tools/generate_opset.py +++ b/tools/generate_opset.py @@ -647,7 +647,7 @@ def main( if pre_commit_hooks: print("Running pre-commit hooks to format & verify...") - if run_pre_commit_hooks(str(path)).returncode: + if False and run_pre_commit_hooks(str(path)).returncode: print("Running second pass of pre-commit hooks...") if run_pre_commit_hooks(str(path)).returncode: raise RuntimeError( diff --git a/tools/templates/class.jinja2 b/tools/templates/class.jinja2 index b2553675..080883de 100644 --- a/tools/templates/class.jinja2 +++ b/tools/templates/class.jinja2 @@ -14,11 +14,11 @@ class _{{ schema.name }}(StandardNode): {% for input in schema.inputs %} {{ input.name }}: {% if is_optional(input) - %}Optional[Var]{% + %}Optional[VarInfo]{% elif is_variadic(input) - %}Sequence[Var]{% + %}Sequence[VarInfo]{% else - %}Var{% + %}VarInfo{% endif %} {% endfor %} @@ -33,11 +33,11 @@ class _{{ schema.name }}(StandardNode): {% for output in schema.outputs %} {{ output.name }}: {% if is_optional(output) - %}Optional[Var]{% + %}Optional[VarInfo]{% elif is_variadic(output) - %}Sequence[Var]{% + %}Sequence[VarInfo]{% else - %}Var{% + %}VarInfo{% endif %} {% endfor %} diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index 53f76989..536823ae 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -31,13 +31,17 @@ return _{{ schema.name }}( {% endfor %} ), _{{ schema.name }}.Inputs( {% for param in schema.inputs - %}{{param.name}}={{param.name}}, {% + %}{{param.name}}={{param.name}}._var_info, {% endfor %} ), {% if schema.outputs and is_variadic(schema.outputs[-1]) %}out_variadic={{ out_variadic_solution if out_variadic_solution else "{}_count".format(schema.outputs[-1].name) }}, {% -endif %}).outputs{% +endif %}).get_output_vars( +{% for param in schema.inputs + %}{{param.name}}={{param.name}}._value, {% +endfor %} + ){% if schema.outputs | length <= 1 - %}.{{ schema.outputs[0].name }}{% + %}["{{ schema.outputs[0].name }}"]{% else %}._unpack_to_any(){% endif %} diff --git a/tools/templates/constructor.jinja2 b/tools/templates/constructor.jinja2 index 63bf2cb8..6accb945 100644 --- a/tools/templates/constructor.jinja2 +++ b/tools/templates/constructor.jinja2 @@ -1,11 +1,11 @@ def {{ schema.name | get_constructor_name }}({% for param in schema.inputs %}{% if is_optional(param) - %}{{ param.name }}: Optional[Var] = None, {% + %}{{ param.name }}: Optional[VarInfo] = None, {% elif is_variadic(param) - %}{{ param.name }}: Sequence[Var]{{" = ()" if loop.index0 >= schema.min_input else ""}}, {% + %}{{ param.name }}: Sequence[VarInfo]{{" = ()" if loop.index0 >= schema.min_input else ""}}, {% else - %}{{ param.name }}: Var, {% + %}{{ param.name }}: VarInfo, {% endif %}{% endfor %} {% if schema.attributes %}*, {% From b6aa76567d69b88775febf0da1c6f344a3bbaa7f Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Tue, 29 Oct 2024 19:57:46 +0200 Subject: [PATCH 02/29] Run linter --- src/spox/_adapt.py | 8 +- src/spox/_graph.py | 20 +- src/spox/_inline.py | 6 +- src/spox/_internal_op.py | 3 +- src/spox/_public.py | 60 +- src/spox/_standard.py | 2 +- src/spox/_var.py | 97 +- src/spox/opset/ai/onnx/v17.py | 2274 ++++++++++++++-------------- src/spox/opset/ai/onnx/v18.py | 370 ++--- src/spox/opset/ai/onnx/v19.py | 248 +-- src/spox/opset/ai/onnx/v20.py | 150 +- tests/test_adapt.py | 10 +- tools/templates/class.jinja2 | 2 +- tools/templates/construct.jinja2 | 4 +- tools/templates/constructor.jinja2 | 6 +- tools/templates/preamble.jinja2 | 5 +- 16 files changed, 1669 insertions(+), 1596 deletions(-) diff --git a/src/spox/_adapt.py b/src/spox/_adapt.py index 0d854822..e15ad1c1 100644 --- a/src/spox/_adapt.py +++ b/src/spox/_adapt.py @@ -4,7 +4,6 @@ import warnings from typing import Optional -import numpy as np import onnx import onnx.version_converter @@ -14,7 +13,6 @@ from ._node import Node from ._schemas import SCHEMAS from ._scope import Scope -from ._utils import from_array from ._var import VarInfo @@ -43,11 +41,7 @@ def adapt_node( ) for key, var in node.outputs.get_vars().items() ] - initializers = [ - from_array(var._value, name) # type: ignore - for name, var in node.inputs.get_vars().items() - if isinstance(var._value, np.ndarray) - ] + initializers = [] except ValueError: return None diff --git a/src/spox/_graph.py b/src/spox/_graph.py index 39ba006b..4d191103 100644 --- a/src/spox/_graph.py +++ b/src/spox/_graph.py @@ -22,7 +22,7 @@ from ._schemas import max_opset_policy from ._type_system import Tensor, Type from ._utils import from_array -from ._var import Var, VarInfo +from ._var import Var, VarInfo, unwrap_vars def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var]: @@ -95,7 +95,7 @@ def enum_arguments( return arguments(**{f"{prefix}{i}": info for i, info in enumerate(infos)}) -def initializer(arr: np.ndarray) -> VarInfo: +def initializer(arr: np.ndarray) -> Var: """ Create a single initializer (frozen argument) with a given array value. @@ -113,7 +113,7 @@ def initializer(arr: np.ndarray) -> VarInfo: return _Initializer( _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), BaseInputs(), - ).outputs.arg + ).get_output_vars()["arg"] @dataclass(frozen=True, eq=False) @@ -436,23 +436,23 @@ def to_onnx_model( return model -def results(**kwargs: VarInfo) -> Graph: +def results(**kwargs: Var) -> Graph: """ Use this function to construct a ``Graph`` object. Parameters ---------- kwargs - VarInfos to be marked as results in the created Graph. + Var to be marked as results in the created Graph. Returns ------- Graph Graph with the results given in `kwargs`, in the same order. Keys are used as names for the results. """ - return Graph(kwargs) + return Graph(unwrap_vars(kwargs)) -def enum_results(*vars: VarInfo, prefix="out") -> Graph: +def enum_results(*vars: Var, prefix="out") -> Graph: """ Use this function to construct a ``Graph`` object, whenever the exact names are not important. Useful when creating subgraphs. @@ -471,7 +471,7 @@ def enum_results(*vars: VarInfo, prefix="out") -> Graph: return results(**{f"{prefix}{i}": var for i, var in enumerate(vars)}) -def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[VarInfo]]) -> Graph: +def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[Var]]) -> Graph: """ Convenience function for creating a subgraph, for use in an operator like If or Loop. However, for those operators one may prefer to use alternative constructors like ``xif`` or ``xloop`` @@ -498,8 +498,6 @@ def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[VarInfo]]) -> Gr if not callable(fun): raise TypeError("Subgraph callback must be callable.") outs = fun(*ins) - if not ( - isinstance(outs, Iterable) and all(isinstance(out, VarInfo) for out in outs) - ): + if not (isinstance(outs, Iterable) and all(isinstance(out, Var) for out in outs)): raise TypeError("Subgraph result must be an Iterable of VarInfo.") return enum_results(*outs).with_arguments(*ins)._with_constructor(fun) diff --git a/src/spox/_inline.py b/src/spox/_inline.py index d4908b46..ce7f7274 100644 --- a/src/spox/_inline.py +++ b/src/spox/_inline.py @@ -127,10 +127,10 @@ def infer_output_types(self) -> dict[str, Type]: for k, o in enumerate(self.graph.output) } - def propagate_values(self) -> dict[str, _value_prop.PropValueType]: + def propagate_values(self, initializers) -> dict[str, _value_prop.PropValueType]: if any( - var.type is None or var._value is None - for var in self.inputs.get_vars().values() + var_info.type is None or initializers.get(name) is None + for name, var_info in self.inputs.get_vars().items() ): return {} wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index e5dd9246..095ed914 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -126,7 +126,7 @@ def infer_output_types(self) -> dict[str, Type]: arr = self.attrs.value.value return {"arg": Tensor(arr.dtype, arr.shape)} - def propagate_values(self) -> dict[str, PropValueType]: + def propagate_values(self, initializers) -> dict[str, PropValueType]: return {"arg": self.attrs.value.value} def update_metadata(self, opset_req, initializers, functions): @@ -247,7 +247,6 @@ def unsafe_cast(x: VarInfo, typ: Type) -> VarInfo: """ y = intro(x) y.type = typ - y._value = x._value return y diff --git a/src/spox/_public.py b/src/spox/_public.py index b29405f0..8247cbc0 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -17,7 +17,7 @@ from ._inline import _Inline from ._standard import _strip_dim_symbol from ._type_system import Type -from ._var import Var, VarInfo +from ._var import Var, VarInfo, unwrap_vars def argument(typ: Type) -> Var: @@ -41,7 +41,7 @@ def argument(typ: Type) -> Var: @contextlib.contextmanager -def _temporary_renames(**kwargs: VarInfo): +def _temporary_renames(**kwargs: Var): # The build code can't really special-case variable names that are # not just ``VarInfo._name``. So we set names here and reset them # afterwards. @@ -49,8 +49,8 @@ def _temporary_renames(**kwargs: VarInfo): pre: dict[VarInfo, Optional[str]] = {} try: for name, arg in kwargs.items(): - pre[arg] = arg._name - arg._rename(name) + pre[arg._var_info] = arg._var_info._name + arg._var_info._rename(name) yield finally: for arg, name in pre.items(): @@ -107,34 +107,31 @@ def build( >>> # a, b, c are all vectors and named the same in the graph >>> # We create 3 distinct arguments >>> a, b, c = [argument(VectorFloat32) for _ in range(3)] - >>> # p represents the VarInfo equivalent to a * b + >>> # p represents the Var equivalent to a * b >>> q = op.add(op.mul(a, b), c) >>> # Build an ONNX model in Spox >>> model = build({'a': a, 'b': b, 'c': c}, {'r': q}) """ - if not all(isinstance(var, VarInfo) for var in inputs.values()): + if not all(isinstance(var, Var) for var in inputs.values()): seen_types = {type(obj) for obj in inputs.values()} - raise TypeError(f"Build inputs must be VarInfos, not {seen_types - {VarInfo}}.") - if not all(isinstance(var, VarInfo) for var in outputs.values()): + raise TypeError(f"Build inputs must be Vars, not {seen_types - {Var}}.") + if not all(isinstance(var, Var) for var in outputs.values()): seen_types = {type(obj) for obj in outputs.values()} - raise TypeError( - f"Build outputs must be VarInfos, not {seen_types - {VarInfo}}." - ) + raise TypeError(f"Build outputs must be Vars, not {seen_types - {Var}}.") + if not all(isinstance(var._op, Argument) for var in inputs.values()): raise TypeError( - "Build inputs must be `VarInfo`s constructed using the `spox.argument` function. " + "Build inputs must be `Var`s constructed using the `spox.argument` function. " "They must not be results of other operations." ) if not outputs: raise ValueError("Build outputs must not be empty for the graph to be valid.") - input_infos = {key: var._var_info for key, var in inputs.items()} - output_infos = {key: var._var_info for key, var in outputs.items()} - - with _temporary_renames(**input_infos): - graph = results(**output_infos) + with _temporary_renames(**inputs): + graph = results(**outputs) if not drop_unused_inputs: - graph = graph.with_arguments(*input_infos.values()) + print({name: var._var_info for name, var in inputs.items()}) + graph = graph.with_arguments(*unwrap_vars(inputs.values())) model_proto = graph.to_onnx_model() # Validate that no further inputs were required. @@ -147,24 +144,24 @@ def build( class _InlineCall(Protocol): """ A callable returned by ``inline``, taking positional and keyword - arguments of type ``VarInfo``, and returning a dictionary of names - (``str``) into ``VarInfo``. + arguments of type ``Var``, and returning a dictionary of names + (``str``) into ``Var``. """ - def __call__(self, *args: VarInfo, **kwargs: VarInfo) -> dict[str, VarInfo]: + def __call__(self, *args: Var, **kwargs: Var) -> dict[str, Var]: """ Parameters ---------- args - VarInfoiables passed as model inputs - positional, as they are + Variables passed as model inputs - positional, as they are listed in the model. kwargs Further variables passed as model inputs - keyword, as they are named in the model. Returns ------- - Dict[str, VarInfo] - VarInfoiables representing the inlined model's outputs. + Dict[str, Var] + Variables representing the inlined model's outputs. """ @@ -175,7 +172,7 @@ def _copy_model(model: onnx.ModelProto) -> onnx.ModelProto: def inline(model: onnx.ModelProto) -> _InlineCall: - """Inline an existing ONNX model, taking and producing ``VarInfo``. + """Inline an existing ONNX model, taking and producing ``Var``. Any valid model may be inlined. The behaviour of the ``model`` is replicated, its metadata (docstring, annotations) may be stripped. @@ -196,8 +193,8 @@ def inline(model: onnx.ModelProto) -> _InlineCall: Returns ------- _InlineCall - A callable which takes ``VarInfo`` arguments and returns a - dictionary of output names into ``VarInfo``. + A callable which takes ``Var`` arguments and returns a + dictionary of output names into ``Var``. Positional arguments are assigned based on the order they are listed in the model. Keyword arguments are assigned based on @@ -280,14 +277,13 @@ def inline(model: onnx.ModelProto) -> _InlineCall: model.graph.node.reverse() # Now we can assume the graph has no initializers - def inline_inner(*args: Var, **kwargs: Var) -> dict[str, VarInfo]: - kwargs = {name: var._var_info for name, var in kwargs.items()} + def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: for name, arg in zip(in_names, args): if name in kwargs: raise TypeError( f"inline callback got multiple values for argument '{name}', {_signature_msg}." ) - kwargs[name] = arg._var_info + kwargs[name] = arg if not (missing := set(in_names) - set(kwargs)) <= set(in_defaults): raise TypeError( f"inline callback missing required arguments: {missing}, {_signature_msg}." @@ -303,11 +299,11 @@ def inline_inner(*args: Var, **kwargs: Var) -> dict[str, VarInfo]: f"Error processing arguments, got {set(kwargs)}, expected {set(in_names)}." ) node = _Inline( - inputs=_Inline.Inputs([kwargs[name] for name in in_names]), + inputs=_Inline.Inputs([kwargs[name]._var_info for name in in_names]), out_variadic=len(model.graph.output), model=model, ) - return dict(zip(out_names, node.outputs.outputs)) + return node.get_output_vars() return inline_inner diff --git a/src/spox/_standard.py b/src/spox/_standard.py index 7efd19ed..531d7afe 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -154,7 +154,7 @@ def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: """ # Cannot do propagation when some inputs were not propagated/inferred if any( - var_info.type is None or initializers[name] is None + var_info.type is None or initializers.get(name, None) is None for name, var_info in self.inputs.get_vars().items() ): return {} diff --git a/src/spox/_var.py b/src/spox/_var.py index ea8d63b7..3db5f913 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -2,7 +2,8 @@ # SPDX-License-Identifier: BSD-3-Clause import typing -from typing import Callable, Optional, TypeVar, Union +from collections.abc import Iterable, Sequence +from typing import Callable, Optional, TypeVar, Union, overload import numpy as np @@ -158,9 +159,9 @@ def __init__( raise TypeError( "The propagated value field of a VarInfo must be a PropValue." ) - if value is not None and value.type != var_info._type: + if value is not None and value.type != var_info.type: raise ValueError( - f"The propagated value type ({value.type}) and actual VarInfo type ({type_}) must be the same." + f"The propagated value type ({value.type}) and actual VarInfo type ({var_info.type}) must be the same." ) self._var_info = var_info @@ -215,13 +216,97 @@ def unwrap_optional(self) -> _type_system.Optional: """Equivalent to ``self.unwrap_type().unwrap_optional()``.""" return self.unwrap_type().unwrap_optional() - def __copy__(self) -> "VarInfo": + @property + def _op(self): + return self._var_info._op + + @property + def _name(self): + return self._var_info._name + + def _rename(self, name: Optional[str]): + self._var_info._rename(name) + + @property + def _which_output(self): + return self._var_info._which_output + + @property + def type(self): + return self._var_info.type + + def __copy__(self) -> "Var": # Simply return `self` to ensure that "copies" are still equal # during the build process return self - def __deepcopy__(self, _) -> "VarInfo": - raise ValueError("'VarInfo' objects cannot be deepcopied.") + def __deepcopy__(self, _) -> "Var": + raise ValueError("'Var' objects cannot be deepcopied.") + + +# we want unwrap to be type aware +T = TypeVar("T") + + +@overload +def unwrap_vars(var: Var) -> VarInfo: ... + + +@overload +def unwrap_vars(var: Optional[Var]) -> Optional[VarInfo]: ... + + +@overload +def unwrap_vars(var: Union[Sequence[Var], Iterable[Var]]) -> list[VarInfo]: ... + + +@overload +def unwrap_vars(var: dict[T, Var]) -> dict[T, VarInfo]: ... + + +def unwrap_vars(var): + if var is None: + return None + elif isinstance(var, Var): + return var._var_info + elif isinstance(var, dict): + return {k: v._var_info for k, v in var.items()} + elif isinstance(var, Sequence) or isinstance(var, Iterable): + return [v._var_info for v in var] + else: + raise ValueError("Unsupported type for unwrap_vars") + + +@overload +def get_value(var: Var) -> Optional[_value_prop.PropValue]: ... + + +@overload +def get_value(var: Optional[Var]) -> Optional[_value_prop.PropValue]: ... + + +@overload +def get_value( + var: Union[Sequence[Var], Iterable[Var]], +) -> Union[ + Sequence[Optional[_value_prop.PropValue]], Iterable[Optional[_value_prop.PropValue]] +]: ... + + +@overload +def get_value(var: dict[T, Var]) -> dict[T, Optional[_value_prop.PropValue]]: ... + + +def get_value(var): + if var is None: + return None + if isinstance(var, Var): + return var._value + if isinstance(var, Sequence) or isinstance(var, Iterable): + return [v._value if v is not None else None for v in var] + if isinstance(var, dict): + return {k: v._value if v is not None else None for k, v in var.items()} + raise ValueError("Unsupported type for get_value") def result_type( diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index ba2e9bce..7d9cff0b 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -32,7 +32,7 @@ from spox._type_system import Sequence as SpoxSequence from spox._type_system import Tensor, Type from spox._value_prop import PropValueType -from spox._var import Var +from spox._var import Var, VarInfo, get_value, unwrap_vars class _Abs(StandardNode): @@ -42,11 +42,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Abs", "", 13) @@ -62,11 +62,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Acos", "", 7) @@ -82,11 +82,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Acosh", "", 9) @@ -102,12 +102,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Add", "", 14) @@ -123,12 +123,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("And", "", 7) @@ -146,11 +146,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ArgMax", "", 13) @@ -168,11 +168,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ArgMin", "", 13) @@ -188,11 +188,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Asin", "", 7) @@ -208,11 +208,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Asinh", "", 9) @@ -228,11 +228,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Atan", "", 7) @@ -248,11 +248,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Atanh", "", 9) @@ -273,11 +273,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("AveragePool", "", 11) @@ -295,17 +295,17 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - scale: Var - B: Var - input_mean: Var - input_var: Var + X: VarInfo + scale: VarInfo + B: VarInfo + input_mean: VarInfo + input_var: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var - running_mean: Optional[Var] - running_var: Optional[Var] + Y: VarInfo + running_mean: Optional[VarInfo] + running_var: Optional[VarInfo] op_type = OpType("BatchNormalization", "", 15) @@ -322,11 +322,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Bernoulli", "", 15) @@ -342,12 +342,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - Y: Var + X: VarInfo + Y: VarInfo @dataclass class Outputs(BaseOutputs): - Z: Var + Z: VarInfo op_type = OpType("BitShift", "", 11) @@ -364,11 +364,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - size: Var + size: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("BlackmanWindow", "", 17) @@ -384,11 +384,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Cast", "", 13) @@ -404,12 +404,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - target_type: Var + input: VarInfo + target_type: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("CastLike", "", 15) @@ -425,11 +425,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Ceil", "", 13) @@ -445,11 +445,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Celu", "", 12) @@ -465,13 +465,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - min: Optional[Var] - max: Optional[Var] + input: VarInfo + min: Optional[VarInfo] + max: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Clip", "", 13) @@ -487,12 +487,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - condition: Var + input: VarInfo + condition: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo def infer_output_types(self) -> dict[str, Type]: self.infer_output_types_onnx() @@ -534,11 +534,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - inputs: Sequence[Var] + inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - concat_result: Var + concat_result: VarInfo op_type = OpType("Concat", "", 13) @@ -555,11 +555,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: Var + input_sequence: VarInfo @dataclass class Outputs(BaseOutputs): - concat_result: Var + concat_result: VarInfo op_type = OpType("ConcatFromSequence", "", 11) @@ -583,9 +583,9 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo - def propagate_values(self) -> dict[str, PropValueType]: + def propagate_values(self, initializers) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -625,11 +625,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("ConstantOfShape", "", 9) @@ -650,13 +650,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - W: Var - B: Optional[Var] + X: VarInfo + W: VarInfo + B: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Conv", "", 11) @@ -677,14 +677,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - w: Var - x_zero_point: Optional[Var] - w_zero_point: Optional[Var] + x: VarInfo + w: VarInfo + x_zero_point: Optional[VarInfo] + w_zero_point: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("ConvInteger", "", 10) @@ -707,13 +707,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - W: Var - B: Optional[Var] + X: VarInfo + W: VarInfo + B: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("ConvTranspose", "", 11) @@ -729,11 +729,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Cos", "", 7) @@ -749,11 +749,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Cosh", "", 9) @@ -770,12 +770,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - axis: Var + x: VarInfo + axis: VarInfo @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("CumSum", "", 14) @@ -793,12 +793,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - dft_length: Optional[Var] + input: VarInfo + dft_length: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("DFT", "", 17) @@ -815,11 +815,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("DepthToSpace", "", 13) @@ -835,13 +835,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - x_scale: Var - x_zero_point: Optional[Var] + x: VarInfo + x_scale: VarInfo + x_zero_point: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("DequantizeLinear", "", 13) @@ -857,11 +857,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Det", "", 11) @@ -877,12 +877,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Div", "", 14) @@ -898,14 +898,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - ratio: Optional[Var] - training_mode: Optional[Var] + data: VarInfo + ratio: Optional[VarInfo] + training_mode: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var - mask: Optional[Var] + output: VarInfo + mask: Optional[VarInfo] op_type = OpType("Dropout", "", 13) @@ -921,13 +921,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var + x: VarInfo @dataclass class Outputs(BaseOutputs): - y: Var - y_scale: Var - y_zero_point: Var + y: VarInfo + y_scale: VarInfo + y_zero_point: VarInfo op_type = OpType("DynamicQuantizeLinear", "", 11) @@ -943,11 +943,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - Inputs: Sequence[Var] + Inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - Output: Var + Output: VarInfo op_type = OpType("Einsum", "", 12) @@ -963,11 +963,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Elu", "", 6) @@ -983,12 +983,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Equal", "", 13) @@ -1004,11 +1004,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Erf", "", 13) @@ -1024,11 +1024,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Exp", "", 13) @@ -1044,12 +1044,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - shape: Var + input: VarInfo + shape: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Expand", "", 13) @@ -1066,11 +1066,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("EyeLike", "", 9) @@ -1086,11 +1086,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Flatten", "", 13) @@ -1106,11 +1106,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Floor", "", 13) @@ -1133,17 +1133,17 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - W: Var - R: Var - B: Optional[Var] - sequence_lens: Optional[Var] - initial_h: Optional[Var] + X: VarInfo + W: VarInfo + R: VarInfo + B: Optional[VarInfo] + sequence_lens: Optional[VarInfo] + initial_h: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Optional[Var] - Y_h: Optional[Var] + Y: Optional[VarInfo] + Y_h: Optional[VarInfo] op_type = OpType("GRU", "", 14) @@ -1159,12 +1159,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - indices: Var + data: VarInfo + indices: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Gather", "", 13) @@ -1180,12 +1180,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - indices: Var + data: VarInfo + indices: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("GatherElements", "", 13) @@ -1201,12 +1201,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - indices: Var + data: VarInfo + indices: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("GatherND", "", 13) @@ -1225,13 +1225,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var - C: Optional[Var] + A: VarInfo + B: VarInfo + C: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Gemm", "", 13) @@ -1247,11 +1247,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("GlobalAveragePool", "", 1) @@ -1267,11 +1267,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("GlobalLpPool", "", 2) @@ -1287,11 +1287,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("GlobalMaxPool", "", 1) @@ -1307,12 +1307,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Greater", "", 13) @@ -1328,12 +1328,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("GreaterOrEqual", "", 16) @@ -1351,12 +1351,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - grid: Var + X: VarInfo + grid: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("GridSample", "", 16) @@ -1373,11 +1373,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - size: Var + size: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("HammingWindow", "", 17) @@ -1394,11 +1394,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - size: Var + size: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("HannWindow", "", 17) @@ -1415,11 +1415,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("HardSigmoid", "", 6) @@ -1435,11 +1435,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("HardSwish", "", 14) @@ -1455,11 +1455,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Hardmax", "", 13) @@ -1475,11 +1475,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Identity", "", 16) @@ -1496,11 +1496,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - cond: Var + cond: VarInfo @dataclass class Outputs(BaseOutputs): - outputs: Sequence[Var] + outputs: Sequence[VarInfo] op_type = OpType("If", "", 16) @@ -1516,13 +1516,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - scale: Var - B: Var + input: VarInfo + scale: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("InstanceNormalization", "", 6) @@ -1539,11 +1539,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("IsInf", "", 10) @@ -1559,11 +1559,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("IsNaN", "", 13) @@ -1582,11 +1582,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("LRN", "", 13) @@ -1609,20 +1609,20 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - W: Var - R: Var - B: Optional[Var] - sequence_lens: Optional[Var] - initial_h: Optional[Var] - initial_c: Optional[Var] - P: Optional[Var] + X: VarInfo + W: VarInfo + R: VarInfo + B: Optional[VarInfo] + sequence_lens: Optional[VarInfo] + initial_h: Optional[VarInfo] + initial_c: Optional[VarInfo] + P: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Optional[Var] - Y_h: Optional[Var] - Y_c: Optional[Var] + Y: Optional[VarInfo] + Y_h: Optional[VarInfo] + Y_c: Optional[VarInfo] op_type = OpType("LSTM", "", 14) @@ -1640,15 +1640,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - Scale: Var - B: Optional[Var] + X: VarInfo + Scale: VarInfo + B: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var - Mean: Optional[Var] - InvStdDev: Optional[Var] + Y: VarInfo + Mean: Optional[VarInfo] + InvStdDev: Optional[VarInfo] op_type = OpType("LayerNormalization", "", 17) @@ -1664,11 +1664,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("LeakyRelu", "", 16) @@ -1684,12 +1684,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Less", "", 13) @@ -1705,12 +1705,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("LessOrEqual", "", 16) @@ -1726,11 +1726,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Log", "", 13) @@ -1746,11 +1746,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("LogSoftmax", "", 13) @@ -1766,13 +1766,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - M: Optional[Var] - cond: Optional[Var] - v_initial: Sequence[Var] + M: Optional[VarInfo] + cond: Optional[VarInfo] + v_initial: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - v_final_and_scan_outputs: Sequence[Var] + v_final_and_scan_outputs: Sequence[VarInfo] def infer_output_types(self) -> dict[str, Type]: output_types = super().infer_output_types() @@ -1803,11 +1803,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("LpNormalization", "", 1) @@ -1827,11 +1827,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("LpPool", "", 11) @@ -1847,12 +1847,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("MatMul", "", 13) @@ -1868,14 +1868,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var - a_zero_point: Optional[Var] - b_zero_point: Optional[Var] + A: VarInfo + B: VarInfo + a_zero_point: Optional[VarInfo] + b_zero_point: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("MatMulInteger", "", 10) @@ -1891,11 +1891,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data_0: Sequence[Var] + data_0: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - max: Var + max: VarInfo op_type = OpType("Max", "", 13) @@ -1917,12 +1917,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var - Indices: Optional[Var] + Y: VarInfo + Indices: Optional[VarInfo] op_type = OpType("MaxPool", "", 12) @@ -1939,12 +1939,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - rois: Var + X: VarInfo + rois: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("MaxRoiPool", "", 1) @@ -1962,13 +1962,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - I: Var - output_shape: Optional[Var] + X: VarInfo + I: VarInfo + output_shape: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("MaxUnpool", "", 11) @@ -1984,11 +1984,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data_0: Sequence[Var] + data_0: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - mean: Var + mean: VarInfo op_type = OpType("Mean", "", 13) @@ -2004,11 +2004,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("MeanVarianceNormalization", "", 13) @@ -2024,15 +2024,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - num_mel_bins: Var - dft_length: Var - sample_rate: Var - lower_edge_hertz: Var - upper_edge_hertz: Var + num_mel_bins: VarInfo + dft_length: VarInfo + sample_rate: VarInfo + lower_edge_hertz: VarInfo + upper_edge_hertz: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("MelWeightMatrix", "", 17) @@ -2048,11 +2048,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data_0: Sequence[Var] + data_0: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - min: Var + min: VarInfo op_type = OpType("Min", "", 13) @@ -2068,12 +2068,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Mod", "", 13) @@ -2089,12 +2089,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Mul", "", 14) @@ -2112,11 +2112,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Multinomial", "", 7) @@ -2132,11 +2132,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Neg", "", 13) @@ -2153,13 +2153,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - target: Var - weight: Optional[Var] + input: VarInfo + target: VarInfo + weight: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - loss: Var + loss: VarInfo op_type = OpType("NegativeLogLikelihoodLoss", "", 13) @@ -2175,15 +2175,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - boxes: Var - scores: Var - max_output_boxes_per_class: Optional[Var] - iou_threshold: Optional[Var] - score_threshold: Optional[Var] + boxes: VarInfo + scores: VarInfo + max_output_boxes_per_class: Optional[VarInfo] + iou_threshold: Optional[VarInfo] + score_threshold: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - selected_indices: Var + selected_indices: VarInfo op_type = OpType("NonMaxSuppression", "", 11) @@ -2199,11 +2199,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("NonZero", "", 13) @@ -2219,11 +2219,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Not", "", 1) @@ -2239,13 +2239,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - indices: Var - depth: Var - values: Var + indices: VarInfo + depth: VarInfo + values: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("OneHot", "", 11) @@ -2261,11 +2261,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Optional[Var] + input: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Optional", "", 15) @@ -2281,11 +2281,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("OptionalGetElement", "", 15) @@ -2301,11 +2301,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("OptionalHasElement", "", 15) @@ -2321,12 +2321,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Or", "", 7) @@ -2342,12 +2342,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - slope: Var + X: VarInfo + slope: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("PRelu", "", 16) @@ -2363,13 +2363,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - pads: Var - constant_value: Optional[Var] + data: VarInfo + pads: VarInfo + constant_value: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Pad", "", 13) @@ -2385,12 +2385,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - Y: Var + X: VarInfo + Y: VarInfo @dataclass class Outputs(BaseOutputs): - Z: Var + Z: VarInfo op_type = OpType("Pow", "", 15) @@ -2411,19 +2411,19 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - x_scale: Var - x_zero_point: Var - w: Var - w_scale: Var - w_zero_point: Var - y_scale: Var - y_zero_point: Var - B: Optional[Var] + x: VarInfo + x_scale: VarInfo + x_zero_point: VarInfo + w: VarInfo + w_scale: VarInfo + w_zero_point: VarInfo + y_scale: VarInfo + y_zero_point: VarInfo + B: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("QLinearConv", "", 10) @@ -2439,18 +2439,18 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - a: Var - a_scale: Var - a_zero_point: Var - b: Var - b_scale: Var - b_zero_point: Var - y_scale: Var - y_zero_point: Var + a: VarInfo + a_scale: VarInfo + a_zero_point: VarInfo + b: VarInfo + b_scale: VarInfo + b_zero_point: VarInfo + y_scale: VarInfo + y_zero_point: VarInfo @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("QLinearMatMul", "", 10) @@ -2466,13 +2466,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - y_scale: Var - y_zero_point: Optional[Var] + x: VarInfo + y_scale: VarInfo + y_zero_point: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("QuantizeLinear", "", 13) @@ -2494,17 +2494,17 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - W: Var - R: Var - B: Optional[Var] - sequence_lens: Optional[Var] - initial_h: Optional[Var] + X: VarInfo + W: VarInfo + R: VarInfo + B: Optional[VarInfo] + sequence_lens: Optional[VarInfo] + initial_h: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Optional[Var] - Y_h: Optional[Var] + Y: Optional[VarInfo] + Y_h: Optional[VarInfo] op_type = OpType("RNN", "", 14) @@ -2526,7 +2526,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("RandomNormal", "", 1) @@ -2545,11 +2545,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("RandomNormalLike", "", 1) @@ -2571,7 +2571,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("RandomUniform", "", 1) @@ -2590,11 +2590,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("RandomUniformLike", "", 1) @@ -2610,13 +2610,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - start: Var - limit: Var - delta: Var + start: VarInfo + limit: VarInfo + delta: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Range", "", 11) @@ -2632,11 +2632,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Reciprocal", "", 13) @@ -2653,11 +2653,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceL1", "", 13) @@ -2674,11 +2674,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceL2", "", 13) @@ -2695,11 +2695,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceLogSum", "", 13) @@ -2716,11 +2716,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceLogSumExp", "", 13) @@ -2737,11 +2737,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceMax", "", 13) @@ -2758,11 +2758,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceMean", "", 13) @@ -2779,11 +2779,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceMin", "", 13) @@ -2800,11 +2800,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceProd", "", 13) @@ -2821,12 +2821,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceSum", "", 13) @@ -2843,11 +2843,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceSumSquare", "", 13) @@ -2863,11 +2863,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Relu", "", 14) @@ -2883,12 +2883,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - shape: Var + data: VarInfo + shape: VarInfo @dataclass class Outputs(BaseOutputs): - reshaped: Var + reshaped: VarInfo op_type = OpType("Reshape", "", 14) @@ -2909,14 +2909,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - roi: Optional[Var] - scales: Optional[Var] - sizes: Optional[Var] + X: VarInfo + roi: Optional[VarInfo] + scales: Optional[VarInfo] + sizes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Resize", "", 13) @@ -2933,12 +2933,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - sequence_lens: Var + input: VarInfo + sequence_lens: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("ReverseSequence", "", 10) @@ -2959,13 +2959,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - rois: Var - batch_indices: Var + X: VarInfo + rois: VarInfo + batch_indices: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("RoiAlign", "", 16) @@ -2981,11 +2981,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Round", "", 11) @@ -3001,14 +3001,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - signal: Var - frame_step: Var - window: Optional[Var] - frame_length: Optional[Var] + signal: VarInfo + frame_step: VarInfo + window: Optional[VarInfo] + frame_length: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("STFT", "", 17) @@ -3029,11 +3029,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - initial_state_and_scan_inputs: Sequence[Var] + initial_state_and_scan_inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - final_state_and_scan_outputs: Sequence[Var] + final_state_and_scan_outputs: Sequence[VarInfo] op_type = OpType("Scan", "", 16) @@ -3050,13 +3050,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - indices: Var - updates: Var + data: VarInfo + indices: VarInfo + updates: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("ScatterElements", "", 16) @@ -3072,13 +3072,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - indices: Var - updates: Var + data: VarInfo + indices: VarInfo + updates: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("ScatterND", "", 16) @@ -3095,11 +3095,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Selu", "", 6) @@ -3115,12 +3115,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: Var - position: Var + input_sequence: VarInfo + position: VarInfo @dataclass class Outputs(BaseOutputs): - tensor: Var + tensor: VarInfo op_type = OpType("SequenceAt", "", 11) @@ -3136,11 +3136,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - inputs: Sequence[Var] + inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - output_sequence: Var + output_sequence: VarInfo op_type = OpType("SequenceConstruct", "", 11) @@ -3158,7 +3158,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("SequenceEmpty", "", 11) @@ -3174,12 +3174,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: Var - position: Optional[Var] + input_sequence: VarInfo + position: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output_sequence: Var + output_sequence: VarInfo op_type = OpType("SequenceErase", "", 11) @@ -3195,13 +3195,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: Var - tensor: Var - position: Optional[Var] + input_sequence: VarInfo + tensor: VarInfo + position: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output_sequence: Var + output_sequence: VarInfo op_type = OpType("SequenceInsert", "", 11) @@ -3217,11 +3217,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: Var + input_sequence: VarInfo @dataclass class Outputs(BaseOutputs): - length: Var + length: VarInfo op_type = OpType("SequenceLength", "", 11) @@ -3237,12 +3237,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: Var - additional_inputs: Sequence[Var] + input_sequence: VarInfo + additional_inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - out_sequence: Sequence[Var] + out_sequence: Sequence[VarInfo] op_type = OpType("SequenceMap", "", 17) @@ -3259,11 +3259,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - shape: Var + shape: VarInfo op_type = OpType("Shape", "", 15) @@ -3280,11 +3280,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Shrink", "", 9) @@ -3300,11 +3300,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Sigmoid", "", 13) @@ -3320,11 +3320,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Sign", "", 13) @@ -3340,11 +3340,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Sin", "", 7) @@ -3360,11 +3360,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Sinh", "", 9) @@ -3380,11 +3380,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - size: Var + size: VarInfo op_type = OpType("Size", "", 13) @@ -3400,15 +3400,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - starts: Var - ends: Var - axes: Optional[Var] - steps: Optional[Var] + data: VarInfo + starts: VarInfo + ends: VarInfo + axes: Optional[VarInfo] + steps: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Slice", "", 13) @@ -3424,11 +3424,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Softmax", "", 13) @@ -3445,14 +3445,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - scores: Var - labels: Var - weights: Optional[Var] + scores: VarInfo + labels: VarInfo + weights: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var - log_prob: Optional[Var] + output: VarInfo + log_prob: Optional[VarInfo] op_type = OpType("SoftmaxCrossEntropyLoss", "", 13) @@ -3468,11 +3468,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Softplus", "", 1) @@ -3488,11 +3488,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Softsign", "", 1) @@ -3508,11 +3508,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("SpaceToDepth", "", 13) @@ -3528,12 +3528,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - split: Optional[Var] + input: VarInfo + split: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - outputs: Sequence[Var] + outputs: Sequence[VarInfo] op_type = OpType("Split", "", 13) @@ -3550,12 +3550,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - split: Optional[Var] + input: VarInfo + split: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output_sequence: Var + output_sequence: VarInfo op_type = OpType("SplitToSequence", "", 11) @@ -3571,11 +3571,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Sqrt", "", 13) @@ -3591,12 +3591,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - squeezed: Var + squeezed: VarInfo op_type = OpType("Squeeze", "", 13) @@ -3615,11 +3615,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("StringNormalizer", "", 10) @@ -3635,12 +3635,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Sub", "", 14) @@ -3656,11 +3656,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data_0: Sequence[Var] + data_0: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - sum: Var + sum: VarInfo op_type = OpType("Sum", "", 13) @@ -3676,11 +3676,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Tan", "", 7) @@ -3696,11 +3696,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Tanh", "", 13) @@ -3724,11 +3724,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("TfIdfVectorizer", "", 9) @@ -3744,11 +3744,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("ThresholdedRelu", "", 10) @@ -3764,12 +3764,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - repeats: Var + input: VarInfo + repeats: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Tile", "", 13) @@ -3787,13 +3787,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - K: Var + X: VarInfo + K: VarInfo @dataclass class Outputs(BaseOutputs): - Values: Var - Indices: Var + Values: VarInfo + Indices: VarInfo op_type = OpType("TopK", "", 11) @@ -3809,11 +3809,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - transposed: Var + transposed: VarInfo op_type = OpType("Transpose", "", 13) @@ -3829,12 +3829,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - k: Optional[Var] + input: VarInfo + k: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Trilu", "", 14) @@ -3851,14 +3851,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var - indices: Optional[Var] - inverse_indices: Optional[Var] - counts: Optional[Var] + Y: VarInfo + indices: Optional[VarInfo] + inverse_indices: Optional[VarInfo] + counts: Optional[VarInfo] op_type = OpType("Unique", "", 11) @@ -3874,12 +3874,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Var + data: VarInfo + axes: VarInfo @dataclass class Outputs(BaseOutputs): - expanded: Var + expanded: VarInfo op_type = OpType("Unsqueeze", "", 13) @@ -3895,13 +3895,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - condition: Var - X: Var - Y: Var + condition: VarInfo + X: VarInfo + Y: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Where", "", 16) @@ -3917,12 +3917,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Xor", "", 7) @@ -3961,10 +3961,10 @@ def abs( return _Abs( _Abs.Attributes(), _Abs.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -3997,10 +3997,10 @@ def acos( return _Acos( _Acos.Attributes(), _Acos.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -4034,10 +4034,10 @@ def acosh( return _Acosh( _Acosh.Attributes(), _Acosh.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -4081,12 +4081,12 @@ def add( return _Add( _Add.Attributes(), _Add.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -4129,12 +4129,12 @@ def and_( return _And( _And.Attributes(), _And.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -4193,10 +4193,10 @@ def arg_max( select_last_index=AttrInt64(select_last_index, name="select_last_index"), ), _ArgMax.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -4255,10 +4255,10 @@ def arg_min( select_last_index=AttrInt64(select_last_index, name="select_last_index"), ), _ArgMin.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -4291,10 +4291,10 @@ def asin( return _Asin( _Asin.Attributes(), _Asin.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -4327,10 +4327,10 @@ def asinh( return _Asinh( _Asinh.Attributes(), _Asinh.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -4363,10 +4363,10 @@ def atan( return _Atan( _Atan.Attributes(), _Atan.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -4400,10 +4400,10 @@ def atanh( return _Atanh( _Atanh.Attributes(), _Atanh.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -4538,10 +4538,10 @@ def average_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _AveragePool.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -4673,19 +4673,19 @@ def batch_normalization( training_mode=AttrInt64(training_mode, name="training_mode"), ), _BatchNormalization.Inputs( - X=X._var_info, - scale=scale._var_info, - B=B._var_info, - input_mean=input_mean._var_info, - input_var=input_var._var_info, + X=unwrap_vars(X), + scale=unwrap_vars(scale), + B=unwrap_vars(B), + input_mean=unwrap_vars(input_mean), + input_var=unwrap_vars(input_var), ), ) .get_output_vars( - X=X._value, - scale=scale._value, - B=B._value, - input_mean=input_mean._value, - input_var=input_var._value, + X=get_value(X), + scale=get_value(scale), + B=get_value(B), + input_mean=get_value(input_mean), + input_var=get_value(input_var), ) ._unpack_to_any() ) @@ -4742,10 +4742,10 @@ def bernoulli( seed=AttrFloat32.maybe(seed, name="seed"), ), _Bernoulli.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -4804,12 +4804,12 @@ def bit_shift( direction=AttrString(direction, name="direction"), ), _BitShift.Inputs( - X=X._var_info, - Y=Y._var_info, + X=unwrap_vars(X), + Y=unwrap_vars(Y), ), ).get_output_vars( - X=X._value, - Y=Y._value, + X=get_value(X), + Y=get_value(Y), )["Z"] @@ -4860,10 +4860,10 @@ def blackman_window( periodic=AttrInt64(periodic, name="periodic"), ), _BlackmanWindow.Inputs( - size=size._var_info, + size=unwrap_vars(size), ), ).get_output_vars( - size=size._value, + size=get_value(size), )["output"] @@ -4954,10 +4954,10 @@ def cast( to=AttrDtype(to, name="to"), ), _Cast.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -4998,12 +4998,12 @@ def cast_like( return _CastLike( _CastLike.Attributes(), _CastLike.Inputs( - input=input._var_info, - target_type=target_type._var_info, + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), ), ).get_output_vars( - input=input._value, - target_type=target_type._value, + input=get_value(input), + target_type=get_value(target_type), )["output"] @@ -5038,10 +5038,10 @@ def ceil( return _Ceil( _Ceil.Attributes(), _Ceil.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -5086,10 +5086,10 @@ def celu( alpha=AttrFloat32(alpha, name="alpha"), ), _Celu.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -5133,14 +5133,14 @@ def clip( return _Clip( _Clip.Attributes(), _Clip.Inputs( - input=input._var_info, - min=min._var_info, - max=max._var_info, + input=unwrap_vars(input), + min=unwrap_vars(min), + max=unwrap_vars(max), ), ).get_output_vars( - input=input._value, - min=min._value, - max=max._value, + input=get_value(input), + min=get_value(min), + max=get_value(max), )["output"] @@ -5195,12 +5195,12 @@ def compress( axis=AttrInt64.maybe(axis, name="axis"), ), _Compress.Inputs( - input=input._var_info, - condition=condition._var_info, + input=unwrap_vars(input), + condition=unwrap_vars(condition), ), ).get_output_vars( - input=input._value, - condition=condition._value, + input=get_value(input), + condition=get_value(condition), )["output"] @@ -5242,10 +5242,10 @@ def concat( axis=AttrInt64(axis, name="axis"), ), _Concat.Inputs( - inputs=inputs._var_info, + inputs=unwrap_vars(inputs), ), ).get_output_vars( - inputs=inputs._value, + inputs=get_value(inputs), )["concat_result"] @@ -5297,10 +5297,10 @@ def concat_from_sequence( new_axis=AttrInt64(new_axis, name="new_axis"), ), _ConcatFromSequence.Inputs( - input_sequence=input_sequence._var_info, + input_sequence=unwrap_vars(input_sequence), ), ).get_output_vars( - input_sequence=input_sequence._value, + input_sequence=get_value(input_sequence), )["concat_result"] @@ -5415,10 +5415,10 @@ def constant_of_shape( value=AttrTensor.maybe(value, name="value"), ), _ConstantOfShape.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -5529,14 +5529,14 @@ def conv( strides=AttrInt64s.maybe(strides, name="strides"), ), _Conv.Inputs( - X=X._var_info, - W=W._var_info, - B=B._var_info, + X=unwrap_vars(X), + W=unwrap_vars(W), + B=unwrap_vars(B), ), ).get_output_vars( - X=X._value, - W=W._value, - B=B._value, + X=get_value(X), + W=get_value(W), + B=get_value(B), )["Y"] @@ -5658,16 +5658,16 @@ def conv_integer( strides=AttrInt64s.maybe(strides, name="strides"), ), _ConvInteger.Inputs( - x=x._var_info, - w=w._var_info, - x_zero_point=x_zero_point._var_info, - w_zero_point=w_zero_point._var_info, + x=unwrap_vars(x), + w=unwrap_vars(w), + x_zero_point=unwrap_vars(x_zero_point), + w_zero_point=unwrap_vars(w_zero_point), ), ).get_output_vars( - x=x._value, - w=w._value, - x_zero_point=x_zero_point._value, - w_zero_point=w_zero_point._value, + x=get_value(x), + w=get_value(w), + x_zero_point=get_value(x_zero_point), + w_zero_point=get_value(w_zero_point), )["y"] @@ -5811,14 +5811,14 @@ def conv_transpose( strides=AttrInt64s.maybe(strides, name="strides"), ), _ConvTranspose.Inputs( - X=X._var_info, - W=W._var_info, - B=B._var_info, + X=unwrap_vars(X), + W=unwrap_vars(W), + B=unwrap_vars(B), ), ).get_output_vars( - X=X._value, - W=W._value, - B=B._value, + X=get_value(X), + W=get_value(W), + B=get_value(B), )["Y"] @@ -5850,10 +5850,10 @@ def cos( return _Cos( _Cos.Attributes(), _Cos.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -5885,10 +5885,10 @@ def cosh( return _Cosh( _Cosh.Attributes(), _Cosh.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -5963,12 +5963,12 @@ def cumsum( reverse=AttrInt64(reverse, name="reverse"), ), _CumSum.Inputs( - x=x._var_info, - axis=axis._var_info, + x=unwrap_vars(x), + axis=unwrap_vars(axis), ), ).get_output_vars( - x=x._value, - axis=axis._value, + x=get_value(x), + axis=get_value(axis), )["y"] @@ -6052,12 +6052,12 @@ def dft( onesided=AttrInt64(onesided, name="onesided"), ), _DFT.Inputs( - input=input._var_info, - dft_length=dft_length._var_info, + input=unwrap_vars(input), + dft_length=unwrap_vars(dft_length), ), ).get_output_vars( - input=input._value, - dft_length=dft_length._value, + input=get_value(input), + dft_length=get_value(dft_length), )["output"] @@ -6129,10 +6129,10 @@ def depth_to_space( mode=AttrString(mode, name="mode"), ), _DepthToSpace.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -6191,14 +6191,14 @@ def dequantize_linear( axis=AttrInt64(axis, name="axis"), ), _DequantizeLinear.Inputs( - x=x._var_info, - x_scale=x_scale._var_info, - x_zero_point=x_zero_point._var_info, + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), ), ).get_output_vars( - x=x._value, - x_scale=x_scale._value, - x_zero_point=x_zero_point._value, + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), )["y"] @@ -6235,10 +6235,10 @@ def det( return _Det( _Det.Attributes(), _Det.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -6282,12 +6282,12 @@ def div( return _Div( _Div.Attributes(), _Div.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -6373,15 +6373,15 @@ def dropout( seed=AttrInt64.maybe(seed, name="seed"), ), _Dropout.Inputs( - data=data._var_info, - ratio=ratio._var_info, - training_mode=training_mode._var_info, + data=unwrap_vars(data), + ratio=unwrap_vars(ratio), + training_mode=unwrap_vars(training_mode), ), ) .get_output_vars( - data=data._value, - ratio=ratio._value, - training_mode=training_mode._value, + data=get_value(data), + ratio=get_value(ratio), + training_mode=get_value(training_mode), ) ._unpack_to_any() ) @@ -6458,11 +6458,11 @@ def dynamic_quantize_linear( _DynamicQuantizeLinear( _DynamicQuantizeLinear.Attributes(), _DynamicQuantizeLinear.Inputs( - x=x._var_info, + x=unwrap_vars(x), ), ) .get_output_vars( - x=x._value, + x=get_value(x), ) ._unpack_to_any() ) @@ -6535,10 +6535,10 @@ def einsum( equation=AttrString(equation, name="equation"), ), _Einsum.Inputs( - Inputs=Inputs._var_info, + Inputs=unwrap_vars(Inputs), ), ).get_output_vars( - Inputs=Inputs._value, + Inputs=get_value(Inputs), )["Output"] @@ -6580,10 +6580,10 @@ def elu( alpha=AttrFloat32(alpha, name="alpha"), ), _Elu.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -6626,12 +6626,12 @@ def equal( return _Equal( _Equal.Attributes(), _Equal.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -6664,10 +6664,10 @@ def erf( return _Erf( _Erf.Attributes(), _Erf.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -6699,10 +6699,10 @@ def exp( return _Exp( _Exp.Attributes(), _Exp.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -6747,12 +6747,12 @@ def expand( return _Expand( _Expand.Attributes(), _Expand.Inputs( - input=input._var_info, - shape=shape._var_info, + input=unwrap_vars(input), + shape=unwrap_vars(shape), ), ).get_output_vars( - input=input._value, - shape=shape._value, + input=get_value(input), + shape=get_value(shape), )["output"] @@ -6810,10 +6810,10 @@ def eye_like( k=AttrInt64(k, name="k"), ), _EyeLike.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -6861,10 +6861,10 @@ def flatten( axis=AttrInt64(axis, name="axis"), ), _Flatten.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -6899,10 +6899,10 @@ def floor( return _Floor( _Floor.Attributes(), _Floor.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -7097,21 +7097,21 @@ def gru( ), ), _GRU.Inputs( - X=X._var_info, - W=W._var_info, - R=R._var_info, - B=B._var_info, - sequence_lens=sequence_lens._var_info, - initial_h=initial_h._var_info, + X=unwrap_vars(X), + W=unwrap_vars(W), + R=unwrap_vars(R), + B=unwrap_vars(B), + sequence_lens=unwrap_vars(sequence_lens), + initial_h=unwrap_vars(initial_h), ), ) .get_output_vars( - X=X._value, - W=W._value, - R=R._value, - B=B._value, - sequence_lens=sequence_lens._value, - initial_h=initial_h._value, + X=get_value(X), + W=get_value(W), + R=get_value(R), + B=get_value(B), + sequence_lens=get_value(sequence_lens), + initial_h=get_value(initial_h), ) ._unpack_to_any() ) @@ -7208,12 +7208,12 @@ def gather( axis=AttrInt64(axis, name="axis"), ), _Gather.Inputs( - data=data._var_info, - indices=indices._var_info, + data=unwrap_vars(data), + indices=unwrap_vars(indices), ), ).get_output_vars( - data=data._value, - indices=indices._value, + data=get_value(data), + indices=get_value(indices), )["output"] @@ -7316,12 +7316,12 @@ def gather_elements( axis=AttrInt64(axis, name="axis"), ), _GatherElements.Inputs( - data=data._var_info, - indices=indices._var_info, + data=unwrap_vars(data), + indices=unwrap_vars(indices), ), ).get_output_vars( - data=data._value, - indices=indices._value, + data=get_value(data), + indices=get_value(indices), )["output"] @@ -7469,12 +7469,12 @@ def gather_nd( batch_dims=AttrInt64(batch_dims, name="batch_dims"), ), _GatherND.Inputs( - data=data._var_info, - indices=indices._var_info, + data=unwrap_vars(data), + indices=unwrap_vars(indices), ), ).get_output_vars( - data=data._value, - indices=indices._value, + data=get_value(data), + indices=get_value(indices), )["output"] @@ -7559,14 +7559,14 @@ def gemm( transB=AttrInt64(transB, name="transB"), ), _Gemm.Inputs( - A=A._var_info, - B=B._var_info, - C=C._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), + C=unwrap_vars(C), ), ).get_output_vars( - A=A._value, - B=B._value, - C=C._value, + A=get_value(A), + B=get_value(B), + C=get_value(C), )["Y"] @@ -7607,10 +7607,10 @@ def global_average_pool( return _GlobalAveragePool( _GlobalAveragePool.Attributes(), _GlobalAveragePool.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -7658,10 +7658,10 @@ def global_lp_pool( p=AttrInt64(p, name="p"), ), _GlobalLpPool.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -7702,10 +7702,10 @@ def global_max_pool( return _GlobalMaxPool( _GlobalMaxPool.Attributes(), _GlobalMaxPool.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -7748,12 +7748,12 @@ def greater( return _Greater( _Greater.Attributes(), _Greater.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -7796,12 +7796,12 @@ def greater_or_equal( return _GreaterOrEqual( _GreaterOrEqual.Attributes(), _GreaterOrEqual.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -7894,12 +7894,12 @@ def grid_sample( padding_mode=AttrString(padding_mode, name="padding_mode"), ), _GridSample.Inputs( - X=X._var_info, - grid=grid._var_info, + X=unwrap_vars(X), + grid=unwrap_vars(grid), ), ).get_output_vars( - X=X._value, - grid=grid._value, + X=get_value(X), + grid=get_value(grid), )["Y"] @@ -7950,10 +7950,10 @@ def hamming_window( periodic=AttrInt64(periodic, name="periodic"), ), _HammingWindow.Inputs( - size=size._var_info, + size=unwrap_vars(size), ), ).get_output_vars( - size=size._value, + size=get_value(size), )["output"] @@ -8004,10 +8004,10 @@ def hann_window( periodic=AttrInt64(periodic, name="periodic"), ), _HannWindow.Inputs( - size=size._var_info, + size=unwrap_vars(size), ), ).get_output_vars( - size=size._value, + size=get_value(size), )["output"] @@ -8053,10 +8053,10 @@ def hard_sigmoid( beta=AttrFloat32(beta, name="beta"), ), _HardSigmoid.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -8091,10 +8091,10 @@ def hard_swish( return _HardSwish( _HardSwish.Attributes(), _HardSwish.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -8142,10 +8142,10 @@ def hardmax( axis=AttrInt64(axis, name="axis"), ), _Hardmax.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -8177,10 +8177,10 @@ def identity( return _Identity( _Identity.Attributes(), _Identity.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -8244,11 +8244,11 @@ def if_( then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), ), _If.Inputs( - cond=cond._var_info, + cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), ).get_output_vars( - cond=cond._value, + cond=get_value(cond), )["outputs"] @@ -8303,14 +8303,14 @@ def instance_normalization( epsilon=AttrFloat32(epsilon, name="epsilon"), ), _InstanceNormalization.Inputs( - input=input._var_info, - scale=scale._var_info, - B=B._var_info, + input=unwrap_vars(input), + scale=unwrap_vars(scale), + B=unwrap_vars(B), ), ).get_output_vars( - input=input._value, - scale=scale._value, - B=B._value, + input=get_value(input), + scale=get_value(scale), + B=get_value(B), )["output"] @@ -8359,10 +8359,10 @@ def isinf( detect_positive=AttrInt64(detect_positive, name="detect_positive"), ), _IsInf.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -8395,10 +8395,10 @@ def isnan( return _IsNaN( _IsNaN.Attributes(), _IsNaN.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -8469,10 +8469,10 @@ def lrn( size=AttrInt64(size, name="size"), ), _LRN.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -8687,25 +8687,25 @@ def lstm( layout=AttrInt64(layout, name="layout"), ), _LSTM.Inputs( - X=X._var_info, - W=W._var_info, - R=R._var_info, - B=B._var_info, - sequence_lens=sequence_lens._var_info, - initial_h=initial_h._var_info, - initial_c=initial_c._var_info, - P=P._var_info, + X=unwrap_vars(X), + W=unwrap_vars(W), + R=unwrap_vars(R), + B=unwrap_vars(B), + sequence_lens=unwrap_vars(sequence_lens), + initial_h=unwrap_vars(initial_h), + initial_c=unwrap_vars(initial_c), + P=unwrap_vars(P), ), ) .get_output_vars( - X=X._value, - W=W._value, - R=R._value, - B=B._value, - sequence_lens=sequence_lens._value, - initial_h=initial_h._value, - initial_c=initial_c._value, - P=P._value, + X=get_value(X), + W=get_value(W), + R=get_value(R), + B=get_value(B), + sequence_lens=get_value(sequence_lens), + initial_h=get_value(initial_h), + initial_c=get_value(initial_c), + P=get_value(P), ) ._unpack_to_any() ) @@ -8798,15 +8798,15 @@ def layer_normalization( stash_type=AttrInt64(stash_type, name="stash_type"), ), _LayerNormalization.Inputs( - X=X._var_info, - Scale=Scale._var_info, - B=B._var_info, + X=unwrap_vars(X), + Scale=unwrap_vars(Scale), + B=unwrap_vars(B), ), ) .get_output_vars( - X=X._value, - Scale=Scale._value, - B=B._value, + X=get_value(X), + Scale=get_value(Scale), + B=get_value(B), ) ._unpack_to_any() ) @@ -8850,10 +8850,10 @@ def leaky_relu( alpha=AttrFloat32(alpha, name="alpha"), ), _LeakyRelu.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -8896,12 +8896,12 @@ def less( return _Less( _Less.Attributes(), _Less.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -8944,12 +8944,12 @@ def less_or_equal( return _LessOrEqual( _LessOrEqual.Attributes(), _LessOrEqual.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -8981,10 +8981,10 @@ def log( return _Log( _Log.Attributes(), _Log.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -9031,10 +9031,10 @@ def log_softmax( axis=AttrInt64(axis, name="axis"), ), _LogSoftmax.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -9224,15 +9224,15 @@ def loop( body=AttrGraph(_body_subgraph, name="body"), ), _Loop.Inputs( - M=M._var_info, - cond=cond._var_info, - v_initial=v_initial._var_info, + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, ).get_output_vars( - M=M._value, - cond=cond._value, - v_initial=v_initial._value, + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), )["v_final_and_scan_outputs"] @@ -9276,10 +9276,10 @@ def lp_normalization( p=AttrInt64(p, name="p"), ), _LpNormalization.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -9363,10 +9363,10 @@ def lp_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _LpPool.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -9403,12 +9403,12 @@ def matmul( return _MatMul( _MatMul.Attributes(), _MatMul.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["Y"] @@ -9467,16 +9467,16 @@ def matmul_integer( return _MatMulInteger( _MatMulInteger.Attributes(), _MatMulInteger.Inputs( - A=A._var_info, - B=B._var_info, - a_zero_point=a_zero_point._var_info, - b_zero_point=b_zero_point._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), + a_zero_point=unwrap_vars(a_zero_point), + b_zero_point=unwrap_vars(b_zero_point), ), ).get_output_vars( - A=A._value, - B=B._value, - a_zero_point=a_zero_point._value, - b_zero_point=b_zero_point._value, + A=get_value(A), + B=get_value(B), + a_zero_point=get_value(a_zero_point), + b_zero_point=get_value(b_zero_point), )["Y"] @@ -9512,10 +9512,10 @@ def max( return _Max( _Max.Attributes(), _Max.Inputs( - data_0=data_0._var_info, + data_0=unwrap_vars(data_0), ), ).get_output_vars( - data_0=data_0._value, + data_0=get_value(data_0), )["max"] @@ -9667,11 +9667,11 @@ def max_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _MaxPool.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ) .get_output_vars( - X=X._value, + X=get_value(X), ) ._unpack_to_any() ) @@ -9728,12 +9728,12 @@ def max_roi_pool( spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), ), _MaxRoiPool.Inputs( - X=X._var_info, - rois=rois._var_info, + X=unwrap_vars(X), + rois=unwrap_vars(rois), ), ).get_output_vars( - X=X._value, - rois=rois._value, + X=get_value(X), + rois=get_value(rois), )["Y"] @@ -9840,14 +9840,14 @@ def max_unpool( strides=AttrInt64s.maybe(strides, name="strides"), ), _MaxUnpool.Inputs( - X=X._var_info, - I=I._var_info, - output_shape=output_shape._var_info, + X=unwrap_vars(X), + I=unwrap_vars(I), + output_shape=unwrap_vars(output_shape), ), ).get_output_vars( - X=X._value, - I=I._value, - output_shape=output_shape._value, + X=get_value(X), + I=get_value(I), + output_shape=get_value(output_shape), )["output"] @@ -9883,10 +9883,10 @@ def mean( return _Mean( _Mean.Attributes(), _Mean.Inputs( - data_0=data_0._var_info, + data_0=unwrap_vars(data_0), ), ).get_output_vars( - data_0=data_0._value, + data_0=get_value(data_0), )["mean"] @@ -9930,10 +9930,10 @@ def mean_variance_normalization( axes=AttrInt64s(axes, name="axes"), ), _MeanVarianceNormalization.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -10016,18 +10016,18 @@ def mel_weight_matrix( output_datatype=AttrInt64(output_datatype, name="output_datatype"), ), _MelWeightMatrix.Inputs( - num_mel_bins=num_mel_bins._var_info, - dft_length=dft_length._var_info, - sample_rate=sample_rate._var_info, - lower_edge_hertz=lower_edge_hertz._var_info, - upper_edge_hertz=upper_edge_hertz._var_info, + num_mel_bins=unwrap_vars(num_mel_bins), + dft_length=unwrap_vars(dft_length), + sample_rate=unwrap_vars(sample_rate), + lower_edge_hertz=unwrap_vars(lower_edge_hertz), + upper_edge_hertz=unwrap_vars(upper_edge_hertz), ), ).get_output_vars( - num_mel_bins=num_mel_bins._value, - dft_length=dft_length._value, - sample_rate=sample_rate._value, - lower_edge_hertz=lower_edge_hertz._value, - upper_edge_hertz=upper_edge_hertz._value, + num_mel_bins=get_value(num_mel_bins), + dft_length=get_value(dft_length), + sample_rate=get_value(sample_rate), + lower_edge_hertz=get_value(lower_edge_hertz), + upper_edge_hertz=get_value(upper_edge_hertz), )["output"] @@ -10063,10 +10063,10 @@ def min( return _Min( _Min.Attributes(), _Min.Inputs( - data_0=data_0._var_info, + data_0=unwrap_vars(data_0), ), ).get_output_vars( - data_0=data_0._value, + data_0=get_value(data_0), )["min"] @@ -10127,12 +10127,12 @@ def mod( fmod=AttrInt64(fmod, name="fmod"), ), _Mod.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -10176,12 +10176,12 @@ def mul( return _Mul( _Mul.Attributes(), _Mul.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -10239,10 +10239,10 @@ def multinomial( seed=AttrFloat32.maybe(seed, name="seed"), ), _Multinomial.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -10276,10 +10276,10 @@ def neg( return _Neg( _Neg.Attributes(), _Neg.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -10446,14 +10446,14 @@ def negative_log_likelihood_loss( reduction=AttrString(reduction, name="reduction"), ), _NegativeLogLikelihoodLoss.Inputs( - input=input._var_info, - target=target._var_info, - weight=weight._var_info, + input=unwrap_vars(input), + target=unwrap_vars(target), + weight=unwrap_vars(weight), ), ).get_output_vars( - input=input._value, - target=target._value, - weight=weight._value, + input=get_value(input), + target=get_value(target), + weight=get_value(weight), )["loss"] @@ -10528,18 +10528,18 @@ def non_max_suppression( center_point_box=AttrInt64(center_point_box, name="center_point_box"), ), _NonMaxSuppression.Inputs( - boxes=boxes._var_info, - scores=scores._var_info, - max_output_boxes_per_class=max_output_boxes_per_class._var_info, - iou_threshold=iou_threshold._var_info, - score_threshold=score_threshold._var_info, + boxes=unwrap_vars(boxes), + scores=unwrap_vars(scores), + max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), + iou_threshold=unwrap_vars(iou_threshold), + score_threshold=unwrap_vars(score_threshold), ), ).get_output_vars( - boxes=boxes._value, - scores=scores._value, - max_output_boxes_per_class=max_output_boxes_per_class._value, - iou_threshold=iou_threshold._value, - score_threshold=score_threshold._value, + boxes=get_value(boxes), + scores=get_value(scores), + max_output_boxes_per_class=get_value(max_output_boxes_per_class), + iou_threshold=get_value(iou_threshold), + score_threshold=get_value(score_threshold), )["selected_indices"] @@ -10575,10 +10575,10 @@ def non_zero( return _NonZero( _NonZero.Attributes(), _NonZero.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -10610,10 +10610,10 @@ def not_( return _Not( _Not.Attributes(), _Not.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -10703,14 +10703,14 @@ def one_hot( axis=AttrInt64(axis, name="axis"), ), _OneHot.Inputs( - indices=indices._var_info, - depth=depth._var_info, - values=values._var_info, + indices=unwrap_vars(indices), + depth=unwrap_vars(depth), + values=unwrap_vars(values), ), ).get_output_vars( - indices=indices._value, - depth=depth._value, - values=values._value, + indices=get_value(indices), + depth=get_value(depth), + values=get_value(values), )["output"] @@ -10752,10 +10752,10 @@ def optional( type=AttrType.maybe(type, name="type"), ), _Optional.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -10790,10 +10790,10 @@ def optional_get_element( return _OptionalGetElement( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -10828,10 +10828,10 @@ def optional_has_element( return _OptionalHasElement( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -10874,12 +10874,12 @@ def or_( return _Or( _Or.Attributes(), _Or.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -10922,12 +10922,12 @@ def prelu( return _PRelu( _PRelu.Attributes(), _PRelu.Inputs( - X=X._var_info, - slope=slope._var_info, + X=unwrap_vars(X), + slope=unwrap_vars(slope), ), ).get_output_vars( - X=X._value, - slope=slope._value, + X=get_value(X), + slope=get_value(slope), )["Y"] @@ -11030,14 +11030,14 @@ def pad( mode=AttrString(mode, name="mode"), ), _Pad.Inputs( - data=data._var_info, - pads=pads._var_info, - constant_value=constant_value._var_info, + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), ), ).get_output_vars( - data=data._value, - pads=pads._value, - constant_value=constant_value._value, + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), )["output"] @@ -11079,12 +11079,12 @@ def pow( return _Pow( _Pow.Attributes(), _Pow.Inputs( - X=X._var_info, - Y=Y._var_info, + X=unwrap_vars(X), + Y=unwrap_vars(Y), ), ).get_output_vars( - X=X._value, - Y=Y._value, + X=get_value(X), + Y=get_value(Y), )["Z"] @@ -11238,26 +11238,26 @@ def qlinear_conv( strides=AttrInt64s.maybe(strides, name="strides"), ), _QLinearConv.Inputs( - x=x._var_info, - x_scale=x_scale._var_info, - x_zero_point=x_zero_point._var_info, - w=w._var_info, - w_scale=w_scale._var_info, - w_zero_point=w_zero_point._var_info, - y_scale=y_scale._var_info, - y_zero_point=y_zero_point._var_info, - B=B._var_info, + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + w=unwrap_vars(w), + w_scale=unwrap_vars(w_scale), + w_zero_point=unwrap_vars(w_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + B=unwrap_vars(B), ), ).get_output_vars( - x=x._value, - x_scale=x_scale._value, - x_zero_point=x_zero_point._value, - w=w._value, - w_scale=w_scale._value, - w_zero_point=w_zero_point._value, - y_scale=y_scale._value, - y_zero_point=y_zero_point._value, - B=B._value, + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + w=get_value(w), + w_scale=get_value(w_scale), + w_zero_point=get_value(w_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + B=get_value(B), )["y"] @@ -11336,24 +11336,24 @@ def qlinear_matmul( return _QLinearMatMul( _QLinearMatMul.Attributes(), _QLinearMatMul.Inputs( - a=a._var_info, - a_scale=a_scale._var_info, - a_zero_point=a_zero_point._var_info, - b=b._var_info, - b_scale=b_scale._var_info, - b_zero_point=b_zero_point._var_info, - y_scale=y_scale._var_info, - y_zero_point=y_zero_point._var_info, + a=unwrap_vars(a), + a_scale=unwrap_vars(a_scale), + a_zero_point=unwrap_vars(a_zero_point), + b=unwrap_vars(b), + b_scale=unwrap_vars(b_scale), + b_zero_point=unwrap_vars(b_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( - a=a._value, - a_scale=a_scale._value, - a_zero_point=a_zero_point._value, - b=b._value, - b_scale=b_scale._value, - b_zero_point=b_zero_point._value, - y_scale=y_scale._value, - y_zero_point=y_zero_point._value, + a=get_value(a), + a_scale=get_value(a_scale), + a_zero_point=get_value(a_zero_point), + b=get_value(b), + b_scale=get_value(b_scale), + b_zero_point=get_value(b_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), )["y"] @@ -11416,14 +11416,14 @@ def quantize_linear( axis=AttrInt64(axis, name="axis"), ), _QuantizeLinear.Inputs( - x=x._var_info, - y_scale=y_scale._var_info, - y_zero_point=y_zero_point._var_info, + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( - x=x._value, - y_scale=y_scale._value, - y_zero_point=y_zero_point._value, + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), )["y"] @@ -11595,21 +11595,21 @@ def rnn( layout=AttrInt64(layout, name="layout"), ), _RNN.Inputs( - X=X._var_info, - W=W._var_info, - R=R._var_info, - B=B._var_info, - sequence_lens=sequence_lens._var_info, - initial_h=initial_h._var_info, + X=unwrap_vars(X), + W=unwrap_vars(W), + R=unwrap_vars(R), + B=unwrap_vars(B), + sequence_lens=unwrap_vars(sequence_lens), + initial_h=unwrap_vars(initial_h), ), ) .get_output_vars( - X=X._value, - W=W._value, - R=R._value, - B=B._value, - sequence_lens=sequence_lens._value, - initial_h=initial_h._value, + X=get_value(X), + W=get_value(W), + R=get_value(R), + B=get_value(B), + sequence_lens=get_value(sequence_lens), + initial_h=get_value(initial_h), ) ._unpack_to_any() ) @@ -11739,10 +11739,10 @@ def random_normal_like( seed=AttrFloat32.maybe(seed, name="seed"), ), _RandomNormalLike.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -11869,10 +11869,10 @@ def random_uniform_like( seed=AttrFloat32.maybe(seed, name="seed"), ), _RandomUniformLike.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -11943,14 +11943,14 @@ def range( return _Range( _Range.Attributes(), _Range.Inputs( - start=start._var_info, - limit=limit._var_info, - delta=delta._var_info, + start=unwrap_vars(start), + limit=unwrap_vars(limit), + delta=unwrap_vars(delta), ), ).get_output_vars( - start=start._value, - limit=limit._value, - delta=delta._value, + start=get_value(start), + limit=get_value(limit), + delta=get_value(delta), )["output"] @@ -11984,10 +11984,10 @@ def reciprocal( return _Reciprocal( _Reciprocal.Attributes(), _Reciprocal.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -12041,10 +12041,10 @@ def reduce_l1( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceL1.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12098,10 +12098,10 @@ def reduce_l2( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceL2.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12156,10 +12156,10 @@ def reduce_log_sum( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceLogSum.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12214,10 +12214,10 @@ def reduce_log_sum_exp( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceLogSumExp.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12273,10 +12273,10 @@ def reduce_max( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceMax.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12330,10 +12330,10 @@ def reduce_mean( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceMean.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12388,10 +12388,10 @@ def reduce_min( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceMin.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12445,10 +12445,10 @@ def reduce_prod( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceProd.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12513,12 +12513,12 @@ def reduce_sum( ), ), _ReduceSum.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -12572,10 +12572,10 @@ def reduce_sum_square( keepdims=AttrInt64(keepdims, name="keepdims"), ), _ReduceSumSquare.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["reduced"] @@ -12609,10 +12609,10 @@ def relu( return _Relu( _Relu.Attributes(), _Relu.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -12672,12 +12672,12 @@ def reshape( allowzero=AttrInt64(allowzero, name="allowzero"), ), _Reshape.Inputs( - data=data._var_info, - shape=shape._var_info, + data=unwrap_vars(data), + shape=unwrap_vars(shape), ), ).get_output_vars( - data=data._value, - shape=shape._value, + data=get_value(data), + shape=get_value(shape), )["reshaped"] @@ -12814,16 +12814,16 @@ def resize( nearest_mode=AttrString(nearest_mode, name="nearest_mode"), ), _Resize.Inputs( - X=X._var_info, - roi=roi._var_info, - scales=scales._var_info, - sizes=sizes._var_info, + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), ), ).get_output_vars( - X=X._value, - roi=roi._value, - scales=scales._value, - sizes=sizes._value, + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), )["Y"] @@ -12895,12 +12895,12 @@ def reverse_sequence( time_axis=AttrInt64(time_axis, name="time_axis"), ), _ReverseSequence.Inputs( - input=input._var_info, - sequence_lens=sequence_lens._var_info, + input=unwrap_vars(input), + sequence_lens=unwrap_vars(sequence_lens), ), ).get_output_vars( - input=input._value, - sequence_lens=sequence_lens._value, + input=get_value(input), + sequence_lens=get_value(sequence_lens), )["Y"] @@ -13003,14 +13003,14 @@ def roi_align( spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), ), _RoiAlign.Inputs( - X=X._var_info, - rois=rois._var_info, - batch_indices=batch_indices._var_info, + X=unwrap_vars(X), + rois=unwrap_vars(rois), + batch_indices=unwrap_vars(batch_indices), ), ).get_output_vars( - X=X._value, - rois=rois._value, - batch_indices=batch_indices._value, + X=get_value(X), + rois=get_value(rois), + batch_indices=get_value(batch_indices), )["Y"] @@ -13056,10 +13056,10 @@ def round( return _Round( _Round.Attributes(), _Round.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -13129,16 +13129,16 @@ def stft( onesided=AttrInt64(onesided, name="onesided"), ), _STFT.Inputs( - signal=signal._var_info, - frame_step=frame_step._var_info, - window=window._var_info, - frame_length=frame_length._var_info, + signal=unwrap_vars(signal), + frame_step=unwrap_vars(frame_step), + window=unwrap_vars(window), + frame_length=unwrap_vars(frame_length), ), ).get_output_vars( - signal=signal._value, - frame_step=frame_step._value, - window=window._value, - frame_length=frame_length._value, + signal=get_value(signal), + frame_step=get_value(frame_step), + window=get_value(window), + frame_length=get_value(frame_length), )["output"] @@ -13379,11 +13379,11 @@ def scan( ), ), _Scan.Inputs( - initial_state_and_scan_inputs=initial_state_and_scan_inputs._var_info, + initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( - initial_state_and_scan_inputs=initial_state_and_scan_inputs._value, + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), )["final_state_and_scan_outputs"] @@ -13513,14 +13513,14 @@ def scatter_elements( reduction=AttrString(reduction, name="reduction"), ), _ScatterElements.Inputs( - data=data._var_info, - indices=indices._var_info, - updates=updates._var_info, + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), ), ).get_output_vars( - data=data._value, - indices=indices._value, - updates=updates._value, + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), )["output"] @@ -13638,14 +13638,14 @@ def scatter_nd( reduction=AttrString(reduction, name="reduction"), ), _ScatterND.Inputs( - data=data._var_info, - indices=indices._var_info, - updates=updates._var_info, + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), ), ).get_output_vars( - data=data._value, - indices=indices._value, - updates=updates._value, + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), )["output"] @@ -13694,10 +13694,10 @@ def selu( gamma=AttrFloat32(gamma, name="gamma"), ), _Selu.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -13742,12 +13742,12 @@ def sequence_at( return _SequenceAt( _SequenceAt.Attributes(), _SequenceAt.Inputs( - input_sequence=input_sequence._var_info, - position=position._var_info, + input_sequence=unwrap_vars(input_sequence), + position=unwrap_vars(position), ), ).get_output_vars( - input_sequence=input_sequence._value, - position=position._value, + input_sequence=get_value(input_sequence), + position=get_value(position), )["tensor"] @@ -13781,10 +13781,10 @@ def sequence_construct( return _SequenceConstruct( _SequenceConstruct.Attributes(), _SequenceConstruct.Inputs( - inputs=inputs._var_info, + inputs=unwrap_vars(inputs), ), ).get_output_vars( - inputs=inputs._value, + inputs=get_value(inputs), )["output_sequence"] @@ -13864,12 +13864,12 @@ def sequence_erase( return _SequenceErase( _SequenceErase.Attributes(), _SequenceErase.Inputs( - input_sequence=input_sequence._var_info, - position=position._var_info, + input_sequence=unwrap_vars(input_sequence), + position=unwrap_vars(position), ), ).get_output_vars( - input_sequence=input_sequence._value, - position=position._value, + input_sequence=get_value(input_sequence), + position=get_value(position), )["output_sequence"] @@ -13921,14 +13921,14 @@ def sequence_insert( return _SequenceInsert( _SequenceInsert.Attributes(), _SequenceInsert.Inputs( - input_sequence=input_sequence._var_info, - tensor=tensor._var_info, - position=position._var_info, + input_sequence=unwrap_vars(input_sequence), + tensor=unwrap_vars(tensor), + position=unwrap_vars(position), ), ).get_output_vars( - input_sequence=input_sequence._value, - tensor=tensor._value, - position=position._value, + input_sequence=get_value(input_sequence), + tensor=get_value(tensor), + position=get_value(position), )["output_sequence"] @@ -13962,10 +13962,10 @@ def sequence_length( return _SequenceLength( _SequenceLength.Attributes(), _SequenceLength.Inputs( - input_sequence=input_sequence._var_info, + input_sequence=unwrap_vars(input_sequence), ), ).get_output_vars( - input_sequence=input_sequence._value, + input_sequence=get_value(input_sequence), )["length"] @@ -14034,13 +14034,13 @@ def sequence_map( body=AttrGraph(_body_subgraph, name="body"), ), _SequenceMap.Inputs( - input_sequence=input_sequence._var_info, - additional_inputs=additional_inputs._var_info, + input_sequence=unwrap_vars(input_sequence), + additional_inputs=unwrap_vars(additional_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( - input_sequence=input_sequence._value, - additional_inputs=additional_inputs._value, + input_sequence=get_value(input_sequence), + additional_inputs=get_value(additional_inputs), )["out_sequence"] @@ -14126,10 +14126,10 @@ def shape( start=AttrInt64(start, name="start"), ), _Shape.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["shape"] @@ -14176,10 +14176,10 @@ def shrink( lambd=AttrFloat32(lambd, name="lambd"), ), _Shrink.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -14213,10 +14213,10 @@ def sigmoid( return _Sigmoid( _Sigmoid.Attributes(), _Sigmoid.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -14250,10 +14250,10 @@ def sign( return _Sign( _Sign.Attributes(), _Sign.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -14285,10 +14285,10 @@ def sin( return _Sin( _Sin.Attributes(), _Sin.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -14320,10 +14320,10 @@ def sinh( return _Sinh( _Sinh.Attributes(), _Sinh.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -14357,10 +14357,10 @@ def size( return _Size( _Size.Attributes(), _Size.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["size"] @@ -14480,18 +14480,18 @@ def slice( return _Slice( _Slice.Attributes(), _Slice.Inputs( - data=data._var_info, - starts=starts._var_info, - ends=ends._var_info, - axes=axes._var_info, - steps=steps._var_info, + data=unwrap_vars(data), + starts=unwrap_vars(starts), + ends=unwrap_vars(ends), + axes=unwrap_vars(axes), + steps=unwrap_vars(steps), ), ).get_output_vars( - data=data._value, - starts=starts._value, - ends=ends._value, - axes=axes._value, - steps=steps._value, + data=get_value(data), + starts=get_value(starts), + ends=get_value(ends), + axes=get_value(axes), + steps=get_value(steps), )["output"] @@ -14540,10 +14540,10 @@ def softmax( axis=AttrInt64(axis, name="axis"), ), _Softmax.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -14663,15 +14663,15 @@ def softmax_cross_entropy_loss( reduction=AttrString(reduction, name="reduction"), ), _SoftmaxCrossEntropyLoss.Inputs( - scores=scores._var_info, - labels=labels._var_info, - weights=weights._var_info, + scores=unwrap_vars(scores), + labels=unwrap_vars(labels), + weights=unwrap_vars(weights), ), ) .get_output_vars( - scores=scores._value, - labels=labels._value, - weights=weights._value, + scores=get_value(scores), + labels=get_value(labels), + weights=get_value(weights), ) ._unpack_to_any() ) @@ -14707,10 +14707,10 @@ def softplus( return _Softplus( _Softplus.Attributes(), _Softplus.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -14744,10 +14744,10 @@ def softsign( return _Softsign( _Softsign.Attributes(), _Softsign.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -14790,10 +14790,10 @@ def space_to_depth( blocksize=AttrInt64(blocksize, name="blocksize"), ), _SpaceToDepth.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -14844,13 +14844,13 @@ def split( axis=AttrInt64(axis, name="axis"), ), _Split.Inputs( - input=input._var_info, - split=split._var_info, + input=unwrap_vars(input), + split=unwrap_vars(split), ), out_variadic=outputs_count, ).get_output_vars( - input=input._value, - split=split._value, + input=get_value(input), + split=get_value(split), )["outputs"] @@ -14915,12 +14915,12 @@ def split_to_sequence( keepdims=AttrInt64(keepdims, name="keepdims"), ), _SplitToSequence.Inputs( - input=input._var_info, - split=split._var_info, + input=unwrap_vars(input), + split=unwrap_vars(split), ), ).get_output_vars( - input=input._value, - split=split._value, + input=get_value(input), + split=get_value(split), )["output_sequence"] @@ -14954,10 +14954,10 @@ def sqrt( return _Sqrt( _Sqrt.Attributes(), _Sqrt.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -14999,12 +14999,12 @@ def squeeze( return _Squeeze( _Squeeze.Attributes(), _Squeeze.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["squeezed"] @@ -15070,10 +15070,10 @@ def string_normalizer( stopwords=AttrStrings.maybe(stopwords, name="stopwords"), ), _StringNormalizer.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -15117,12 +15117,12 @@ def sub( return _Sub( _Sub.Attributes(), _Sub.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -15158,10 +15158,10 @@ def sum( return _Sum( _Sum.Attributes(), _Sum.Inputs( - data_0=data_0._var_info, + data_0=unwrap_vars(data_0), ), ).get_output_vars( - data_0=data_0._value, + data_0=get_value(data_0), )["sum"] @@ -15193,10 +15193,10 @@ def tan( return _Tan( _Tan.Attributes(), _Tan.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -15229,10 +15229,10 @@ def tanh( return _Tanh( _Tanh.Attributes(), _Tanh.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -15378,10 +15378,10 @@ def tf_idf_vectorizer( weights=AttrFloat32s.maybe(weights, name="weights"), ), _TfIdfVectorizer.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -15422,10 +15422,10 @@ def thresholded_relu( alpha=AttrFloat32(alpha, name="alpha"), ), _ThresholdedRelu.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -15466,12 +15466,12 @@ def tile( return _Tile( _Tile.Attributes(), _Tile.Inputs( - input=input._var_info, - repeats=repeats._var_info, + input=unwrap_vars(input), + repeats=unwrap_vars(repeats), ), ).get_output_vars( - input=input._value, - repeats=repeats._value, + input=get_value(input), + repeats=get_value(repeats), )["output"] @@ -15557,13 +15557,13 @@ def top_k( sorted=AttrInt64(sorted, name="sorted"), ), _TopK.Inputs( - X=X._var_info, - K=K._var_info, + X=unwrap_vars(X), + K=unwrap_vars(K), ), ) .get_output_vars( - X=X._value, - K=K._value, + X=get_value(X), + K=get_value(K), ) ._unpack_to_any() ) @@ -15607,10 +15607,10 @@ def transpose( perm=AttrInt64s.maybe(perm, name="perm"), ), _Transpose.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["transposed"] @@ -15672,12 +15672,12 @@ def trilu( upper=AttrInt64(upper, name="upper"), ), _Trilu.Inputs( - input=input._var_info, - k=k._var_info, + input=unwrap_vars(input), + k=unwrap_vars(k), ), ).get_output_vars( - input=input._value, - k=k._value, + input=get_value(input), + k=get_value(k), )["output"] @@ -15857,11 +15857,11 @@ def unique( sorted=AttrInt64(sorted, name="sorted"), ), _Unique.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ) .get_output_vars( - X=X._value, + X=get_value(X), ) ._unpack_to_any() ) @@ -15915,12 +15915,12 @@ def unsqueeze( return _Unsqueeze( _Unsqueeze.Attributes(), _Unsqueeze.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["expanded"] @@ -15968,14 +15968,14 @@ def where( return _Where( _Where.Attributes(), _Where.Inputs( - condition=condition._var_info, - X=X._var_info, - Y=Y._var_info, + condition=unwrap_vars(condition), + X=unwrap_vars(X), + Y=unwrap_vars(Y), ), ).get_output_vars( - condition=condition._value, - X=X._value, - Y=Y._value, + condition=get_value(condition), + X=get_value(X), + Y=get_value(Y), )["output"] @@ -16018,12 +16018,12 @@ def xor( return _Xor( _Xor.Attributes(), _Xor.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index 7db88912..1f191da5 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -20,7 +20,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._var import Var +from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v17 import ( _DFT, _GRU, @@ -350,12 +350,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("BitwiseAnd", "", 18) @@ -371,11 +371,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("BitwiseNot", "", 18) @@ -391,12 +391,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("BitwiseOr", "", 18) @@ -412,12 +412,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("BitwiseXor", "", 18) @@ -433,12 +433,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_data: Var - shape: Var + input_data: VarInfo + shape: VarInfo @dataclass class Outputs(BaseOutputs): - output_data: Var + output_data: VarInfo op_type = OpType("CenterCropPad", "", 18) @@ -456,13 +456,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - image_shape: Var - block_shape: Var + input: VarInfo + image_shape: VarInfo + block_shape: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Col2Im", "", 18) @@ -479,13 +479,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - scale: Var - bias: Var + X: VarInfo + scale: VarInfo + bias: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("GroupNormalization", "", 18) @@ -507,11 +507,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("LpPool", "", 18) @@ -527,11 +527,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Mish", "", 18) @@ -547,11 +547,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("OptionalGetElement", "", 18) @@ -567,11 +567,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Optional[Var] + input: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("OptionalHasElement", "", 18) @@ -587,14 +587,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - pads: Var - constant_value: Optional[Var] - axes: Optional[Var] + data: VarInfo + pads: VarInfo + constant_value: Optional[VarInfo] + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Pad", "", 18) @@ -611,12 +611,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceL1", "", 18) @@ -633,12 +633,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceL2", "", 18) @@ -655,12 +655,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceLogSum", "", 18) @@ -677,12 +677,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceLogSumExp", "", 18) @@ -699,12 +699,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceMax", "", 18) @@ -721,12 +721,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceMean", "", 18) @@ -743,12 +743,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceMin", "", 18) @@ -765,12 +765,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceProd", "", 18) @@ -787,12 +787,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceSumSquare", "", 18) @@ -816,14 +816,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - roi: Optional[Var] - scales: Optional[Var] - sizes: Optional[Var] + X: VarInfo + roi: Optional[VarInfo] + scales: Optional[VarInfo] + sizes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Resize", "", 18) @@ -840,13 +840,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - indices: Var - updates: Var + data: VarInfo + indices: VarInfo + updates: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("ScatterElements", "", 18) @@ -862,13 +862,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - indices: Var - updates: Var + data: VarInfo + indices: VarInfo + updates: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("ScatterND", "", 18) @@ -885,12 +885,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - split: Optional[Var] + input: VarInfo + split: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - outputs: Sequence[Var] + outputs: Sequence[VarInfo] op_type = OpType("Split", "", 18) @@ -937,12 +937,12 @@ def bitwise_and( return _BitwiseAnd( _BitwiseAnd.Attributes(), _BitwiseAnd.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -974,10 +974,10 @@ def bitwise_not( return _BitwiseNot( _BitwiseNot.Attributes(), _BitwiseNot.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -1019,12 +1019,12 @@ def bitwise_or( return _BitwiseOr( _BitwiseOr.Attributes(), _BitwiseOr.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -1066,12 +1066,12 @@ def bitwise_xor( return _BitwiseXor( _BitwiseXor.Attributes(), _BitwiseXor.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -1127,12 +1127,12 @@ def center_crop_pad( axes=AttrInt64s.maybe(axes, name="axes"), ), _CenterCropPad.Inputs( - input_data=input_data._var_info, - shape=shape._var_info, + input_data=unwrap_vars(input_data), + shape=unwrap_vars(shape), ), ).get_output_vars( - input_data=input_data._value, - shape=shape._value, + input_data=get_value(input_data), + shape=get_value(shape), )["output_data"] @@ -1223,14 +1223,14 @@ def col2_im( strides=AttrInt64s.maybe(strides, name="strides"), ), _Col2Im.Inputs( - input=input._var_info, - image_shape=image_shape._var_info, - block_shape=block_shape._var_info, + input=unwrap_vars(input), + image_shape=unwrap_vars(image_shape), + block_shape=unwrap_vars(block_shape), ), ).get_output_vars( - input=input._value, - image_shape=image_shape._value, - block_shape=block_shape._value, + input=get_value(input), + image_shape=get_value(image_shape), + block_shape=get_value(block_shape), )["output"] @@ -1305,14 +1305,14 @@ def group_normalization( num_groups=AttrInt64(num_groups, name="num_groups"), ), _GroupNormalization.Inputs( - X=X._var_info, - scale=scale._var_info, - bias=bias._var_info, + X=unwrap_vars(X), + scale=unwrap_vars(scale), + bias=unwrap_vars(bias), ), ).get_output_vars( - X=X._value, - scale=scale._value, - bias=bias._value, + X=get_value(X), + scale=get_value(scale), + bias=get_value(bias), )["Y"] @@ -1435,10 +1435,10 @@ def lp_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _LpPool.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -1477,10 +1477,10 @@ def mish( return _Mish( _Mish.Attributes(), _Mish.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -1516,10 +1516,10 @@ def optional_get_element( return _OptionalGetElement( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -1555,10 +1555,10 @@ def optional_has_element( return _OptionalHasElement( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -1701,16 +1701,16 @@ def pad( mode=AttrString(mode, name="mode"), ), _Pad.Inputs( - data=data._var_info, - pads=pads._var_info, - constant_value=constant_value._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - pads=pads._value, - constant_value=constant_value._value, - axes=axes._value, + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), )["output"] @@ -1775,12 +1775,12 @@ def reduce_l1( ), ), _ReduceL1.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -1845,12 +1845,12 @@ def reduce_l2( ), ), _ReduceL2.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -1916,12 +1916,12 @@ def reduce_log_sum( ), ), _ReduceLogSum.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -1987,12 +1987,12 @@ def reduce_log_sum_exp( ), ), _ReduceLogSumExp.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -2059,12 +2059,12 @@ def reduce_max( ), ), _ReduceMax.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -2129,12 +2129,12 @@ def reduce_mean( ), ), _ReduceMean.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -2200,12 +2200,12 @@ def reduce_min( ), ), _ReduceMin.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -2270,12 +2270,12 @@ def reduce_prod( ), ), _ReduceProd.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -2340,12 +2340,12 @@ def reduce_sum_square( ), ), _ReduceSumSquare.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -2538,16 +2538,16 @@ def resize( nearest_mode=AttrString(nearest_mode, name="nearest_mode"), ), _Resize.Inputs( - X=X._var_info, - roi=roi._var_info, - scales=scales._var_info, - sizes=sizes._var_info, + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), ), ).get_output_vars( - X=X._value, - roi=roi._value, - scales=scales._value, - sizes=sizes._value, + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), )["Y"] @@ -2680,14 +2680,14 @@ def scatter_elements( reduction=AttrString(reduction, name="reduction"), ), _ScatterElements.Inputs( - data=data._var_info, - indices=indices._var_info, - updates=updates._var_info, + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), ), ).get_output_vars( - data=data._value, - indices=indices._value, - updates=updates._value, + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), )["output"] @@ -2821,14 +2821,14 @@ def scatter_nd( reduction=AttrString(reduction, name="reduction"), ), _ScatterND.Inputs( - data=data._var_info, - indices=indices._var_info, - updates=updates._var_info, + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), ), ).get_output_vars( - data=data._value, - indices=indices._value, - updates=updates._value, + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), )["output"] @@ -2885,13 +2885,13 @@ def split( num_outputs=AttrInt64.maybe(num_outputs, name="num_outputs"), ), _Split.Inputs( - input=input._var_info, - split=split._var_info, + input=unwrap_vars(input), + split=unwrap_vars(split), ), out_variadic=num_outputs, ).get_output_vars( - input=input._value, - split=split._value, + input=get_value(input), + split=get_value(split), )["outputs"] diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 5fbc7748..74c88f35 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -30,7 +30,7 @@ from spox._standard import StandardNode from spox._type_system import Tensor, Type from spox._value_prop import PropValueType -from spox._var import Var +from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v18 import ( _DFT, _GRU, @@ -384,11 +384,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("AveragePool", "", 19) @@ -405,11 +405,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Cast", "", 19) @@ -425,12 +425,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - target_type: Var + input: VarInfo + target_type: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("CastLike", "", 19) @@ -454,9 +454,9 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo - def propagate_values(self) -> dict[str, PropValueType]: + def propagate_values(self, initializers) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -501,15 +501,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - W: Var - offset: Var - B: Optional[Var] - mask: Optional[Var] + X: VarInfo + W: VarInfo + offset: VarInfo + B: Optional[VarInfo] + mask: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("DeformConv", "", 19) @@ -525,13 +525,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - x_scale: Var - x_zero_point: Optional[Var] + x: VarInfo + x_scale: VarInfo + x_zero_point: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("DequantizeLinear", "", 19) @@ -547,12 +547,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: Var - B: Var + A: VarInfo + B: VarInfo @dataclass class Outputs(BaseOutputs): - C: Var + C: VarInfo op_type = OpType("Equal", "", 19) @@ -568,11 +568,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Identity", "", 19) @@ -589,11 +589,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - cond: Var + cond: VarInfo @dataclass class Outputs(BaseOutputs): - outputs: Sequence[Var] + outputs: Sequence[VarInfo] op_type = OpType("If", "", 19) @@ -609,13 +609,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - M: Optional[Var] - cond: Optional[Var] - v_initial: Sequence[Var] + M: Optional[VarInfo] + cond: Optional[VarInfo] + v_initial: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - v_final_and_scan_outputs: Sequence[Var] + v_final_and_scan_outputs: Sequence[VarInfo] op_type = OpType("Loop", "", 19) @@ -631,14 +631,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - pads: Var - constant_value: Optional[Var] - axes: Optional[Var] + data: VarInfo + pads: VarInfo + constant_value: Optional[VarInfo] + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Pad", "", 19) @@ -655,13 +655,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - y_scale: Var - y_zero_point: Optional[Var] + x: VarInfo + y_scale: VarInfo + y_zero_point: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("QuantizeLinear", "", 19) @@ -677,12 +677,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - shape: Var + data: VarInfo + shape: VarInfo @dataclass class Outputs(BaseOutputs): - reshaped: Var + reshaped: VarInfo op_type = OpType("Reshape", "", 19) @@ -706,14 +706,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - roi: Optional[Var] - scales: Optional[Var] - sizes: Optional[Var] + X: VarInfo + roi: Optional[VarInfo] + scales: Optional[VarInfo] + sizes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Resize", "", 19) @@ -734,11 +734,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - initial_state_and_scan_inputs: Sequence[Var] + initial_state_and_scan_inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - final_state_and_scan_outputs: Sequence[Var] + final_state_and_scan_outputs: Sequence[VarInfo] op_type = OpType("Scan", "", 19) @@ -755,11 +755,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - shape: Var + shape: VarInfo op_type = OpType("Shape", "", 19) @@ -775,11 +775,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - size: Var + size: VarInfo op_type = OpType("Size", "", 19) @@ -926,10 +926,10 @@ def average_pool( strides=AttrInt64s.maybe(strides, name="strides"), ), _AveragePool.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -1060,10 +1060,10 @@ def cast( to=AttrDtype(to, name="to"), ), _Cast.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -1115,12 +1115,12 @@ def cast_like( saturate=AttrInt64(saturate, name="saturate"), ), _CastLike.Inputs( - input=input._var_info, - target_type=target_type._var_info, + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), ), ).get_output_vars( - input=input._value, - target_type=target_type._value, + input=get_value(input), + target_type=get_value(target_type), )["output"] @@ -1299,18 +1299,18 @@ def deform_conv( strides=AttrInt64s.maybe(strides, name="strides"), ), _DeformConv.Inputs( - X=X._var_info, - W=W._var_info, - offset=offset._var_info, - B=B._var_info, - mask=mask._var_info, + X=unwrap_vars(X), + W=unwrap_vars(W), + offset=unwrap_vars(offset), + B=unwrap_vars(B), + mask=unwrap_vars(mask), ), ).get_output_vars( - X=X._value, - W=W._value, - offset=offset._value, - B=B._value, - mask=mask._value, + X=get_value(X), + W=get_value(W), + offset=get_value(offset), + B=get_value(B), + mask=get_value(mask), )["Y"] @@ -1374,14 +1374,14 @@ def dequantize_linear( axis=AttrInt64(axis, name="axis"), ), _DequantizeLinear.Inputs( - x=x._var_info, - x_scale=x_scale._var_info, - x_zero_point=x_zero_point._var_info, + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), ), ).get_output_vars( - x=x._value, - x_scale=x_scale._value, - x_zero_point=x_zero_point._value, + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), )["y"] @@ -1424,12 +1424,12 @@ def equal( return _Equal( _Equal.Attributes(), _Equal.Inputs( - A=A._var_info, - B=B._var_info, + A=unwrap_vars(A), + B=unwrap_vars(B), ), ).get_output_vars( - A=A._value, - B=B._value, + A=get_value(A), + B=get_value(B), )["C"] @@ -1461,10 +1461,10 @@ def identity( return _Identity( _Identity.Attributes(), _Identity.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -1528,11 +1528,11 @@ def if_( then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), ), _If.Inputs( - cond=cond._var_info, + cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), ).get_output_vars( - cond=cond._value, + cond=get_value(cond), )["outputs"] @@ -1722,15 +1722,15 @@ def loop( body=AttrGraph(_body_subgraph, name="body"), ), _Loop.Inputs( - M=M._var_info, - cond=cond._var_info, - v_initial=v_initial._var_info, + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, ).get_output_vars( - M=M._value, - cond=cond._value, - v_initial=v_initial._value, + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), )["v_final_and_scan_outputs"] @@ -1899,16 +1899,16 @@ def pad( mode=AttrString(mode, name="mode"), ), _Pad.Inputs( - data=data._var_info, - pads=pads._var_info, - constant_value=constant_value._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - pads=pads._value, - constant_value=constant_value._value, - axes=axes._value, + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), )["output"] @@ -1984,14 +1984,14 @@ def quantize_linear( saturate=AttrInt64(saturate, name="saturate"), ), _QuantizeLinear.Inputs( - x=x._var_info, - y_scale=y_scale._var_info, - y_zero_point=y_zero_point._var_info, + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( - x=x._value, - y_scale=y_scale._value, - y_zero_point=y_zero_point._value, + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), )["y"] @@ -2051,12 +2051,12 @@ def reshape( allowzero=AttrInt64(allowzero, name="allowzero"), ), _Reshape.Inputs( - data=data._var_info, - shape=shape._var_info, + data=unwrap_vars(data), + shape=unwrap_vars(shape), ), ).get_output_vars( - data=data._value, - shape=shape._value, + data=get_value(data), + shape=get_value(shape), )["reshaped"] @@ -2287,16 +2287,16 @@ def resize( nearest_mode=AttrString(nearest_mode, name="nearest_mode"), ), _Resize.Inputs( - X=X._var_info, - roi=roi._var_info, - scales=scales._var_info, - sizes=sizes._var_info, + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), ), ).get_output_vars( - X=X._value, - roi=roi._value, - scales=scales._value, - sizes=sizes._value, + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), )["Y"] @@ -2537,11 +2537,11 @@ def scan( ), ), _Scan.Inputs( - initial_state_and_scan_inputs=initial_state_and_scan_inputs._var_info, + initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( - initial_state_and_scan_inputs=initial_state_and_scan_inputs._value, + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), )["final_state_and_scan_outputs"] @@ -2627,10 +2627,10 @@ def shape( start=AttrInt64(start, name="start"), ), _Shape.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["shape"] @@ -2664,10 +2664,10 @@ def size( return _Size( _Size.Attributes(), _Size.Inputs( - data=data._var_info, + data=unwrap_vars(data), ), ).get_output_vars( - data=data._value, + data=get_value(data), )["size"] diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 275fb408..014763f8 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -18,7 +18,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._var import Var +from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v19 import ( _GRU, _LRN, @@ -386,12 +386,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - theta: Var - size: Var + theta: VarInfo + size: VarInfo @dataclass class Outputs(BaseOutputs): - grid: Var + grid: VarInfo op_type = OpType("AffineGrid", "", 20) @@ -407,11 +407,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("ConstantOfShape", "", 20) @@ -428,13 +428,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - dft_length: Optional[Var] - axis: Optional[Var] + input: VarInfo + dft_length: Optional[VarInfo] + axis: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("DFT", "", 20) @@ -450,11 +450,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("Gelu", "", 20) @@ -472,12 +472,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - grid: Var + X: VarInfo + grid: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("GridSample", "", 20) @@ -493,11 +493,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - encoded_stream: Var + encoded_stream: VarInfo @dataclass class Outputs(BaseOutputs): - image: Var + image: VarInfo op_type = OpType("ImageDecoder", "", 20) @@ -514,11 +514,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("IsInf", "", 20) @@ -534,11 +534,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("IsNaN", "", 20) @@ -555,12 +555,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceMax", "", 20) @@ -577,12 +577,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: Var + reduced: VarInfo op_type = OpType("ReduceMin", "", 20) @@ -598,11 +598,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("RegexFullMatch", "", 20) @@ -618,12 +618,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - Y: Var + X: VarInfo + Y: VarInfo @dataclass class Outputs(BaseOutputs): - Z: Var + Z: VarInfo op_type = OpType("StringConcat", "", 20) @@ -640,12 +640,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var - Z: Var + Y: VarInfo + Z: VarInfo op_type = OpType("StringSplit", "", 20) @@ -738,12 +738,12 @@ def affine_grid( align_corners=AttrInt64(align_corners, name="align_corners"), ), _AffineGrid.Inputs( - theta=theta._var_info, - size=size._var_info, + theta=unwrap_vars(theta), + size=unwrap_vars(size), ), ).get_output_vars( - theta=theta._value, - size=size._value, + theta=get_value(theta), + size=get_value(size), )["grid"] @@ -789,10 +789,10 @@ def constant_of_shape( value=AttrTensor.maybe(value, name="value"), ), _ConstantOfShape.Inputs( - input=input._var_info, + input=unwrap_vars(input), ), ).get_output_vars( - input=input._value, + input=get_value(input), )["output"] @@ -892,14 +892,14 @@ def dft( onesided=AttrInt64(onesided, name="onesided"), ), _DFT.Inputs( - input=input._var_info, - dft_length=dft_length._var_info, - axis=axis._var_info, + input=unwrap_vars(input), + dft_length=unwrap_vars(dft_length), + axis=unwrap_vars(axis), ), ).get_output_vars( - input=input._value, - dft_length=dft_length._value, - axis=axis._value, + input=get_value(input), + dft_length=get_value(dft_length), + axis=get_value(axis), )["output"] @@ -946,10 +946,10 @@ def gelu( approximate=AttrString(approximate, name="approximate"), ), _Gelu.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -1062,12 +1062,12 @@ def grid_sample( padding_mode=AttrString(padding_mode, name="padding_mode"), ), _GridSample.Inputs( - X=X._var_info, - grid=grid._var_info, + X=unwrap_vars(X), + grid=unwrap_vars(grid), ), ).get_output_vars( - X=X._value, - grid=grid._value, + X=get_value(X), + grid=get_value(grid), )["Y"] @@ -1134,10 +1134,10 @@ def image_decoder( pixel_format=AttrString(pixel_format, name="pixel_format"), ), _ImageDecoder.Inputs( - encoded_stream=encoded_stream._var_info, + encoded_stream=unwrap_vars(encoded_stream), ), ).get_output_vars( - encoded_stream=encoded_stream._value, + encoded_stream=get_value(encoded_stream), )["image"] @@ -1186,10 +1186,10 @@ def isinf( detect_positive=AttrInt64(detect_positive, name="detect_positive"), ), _IsInf.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -1222,10 +1222,10 @@ def isnan( return _IsNaN( _IsNaN.Attributes(), _IsNaN.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -1295,12 +1295,12 @@ def reduce_max( ), ), _ReduceMax.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -1369,12 +1369,12 @@ def reduce_min( ), ), _ReduceMin.Inputs( - data=data._var_info, - axes=axes._var_info, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), ).get_output_vars( - data=data._value, - axes=axes._value, + data=get_value(data), + axes=get_value(axes), )["reduced"] @@ -1419,10 +1419,10 @@ def regex_full_match( pattern=AttrString.maybe(pattern, name="pattern"), ), _RegexFullMatch.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ).get_output_vars( - X=X._value, + X=get_value(X), )["Y"] @@ -1459,12 +1459,12 @@ def string_concat( return _StringConcat( _StringConcat.Attributes(), _StringConcat.Inputs( - X=X._var_info, - Y=Y._var_info, + X=unwrap_vars(X), + Y=unwrap_vars(Y), ), ).get_output_vars( - X=X._value, - Y=Y._value, + X=get_value(X), + Y=get_value(Y), )["Z"] @@ -1544,11 +1544,11 @@ def string_split( maxsplit=AttrInt64.maybe(maxsplit, name="maxsplit"), ), _StringSplit.Inputs( - X=X._var_info, + X=unwrap_vars(X), ), ) .get_output_vars( - X=X._value, + X=get_value(X), ) ._unpack_to_any() ) diff --git a/tests/test_adapt.py b/tests/test_adapt.py index 3b0884ad..d3b01a06 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -18,6 +18,7 @@ from spox._graph import arguments, results from spox._node import OpType from spox._standard import StandardNode +from spox._var import VarInfo @pytest.fixture @@ -82,11 +83,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - squeezed: Var + squeezed: VarInfo op_type = OpType("Squeeze", "", 11) @@ -97,8 +98,9 @@ class Outputs(BaseOutputs): def squeeze11(_data: Var, _axes: Iterable[int]): return Squeeze11( - Squeeze11.Attributes(AttrInt64s(_axes, "axes")), Squeeze11.Inputs(_data) - ).outputs.squeezed + Squeeze11.Attributes(AttrInt64s(_axes, "axes")), + Squeeze11.Inputs(_data._var_info), + ).get_output_vars()["squeezed"] @pytest.fixture diff --git a/tools/templates/class.jinja2 b/tools/templates/class.jinja2 index 080883de..f5d6a4fa 100644 --- a/tools/templates/class.jinja2 +++ b/tools/templates/class.jinja2 @@ -54,7 +54,7 @@ class _{{ schema.name }}(StandardNode): {% endif %} {% if value_propagation %} - def propagate_values(self) -> dict[str, PropValueType]: + def propagate_values(self, initializers) -> dict[str, PropValueType]: {% filter indent(width=8) %} {%+ include value_propagation %} {% endfilter %} diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index 536823ae..514833c8 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -31,14 +31,14 @@ return _{{ schema.name }}( {% endfor %} ), _{{ schema.name }}.Inputs( {% for param in schema.inputs - %}{{param.name}}={{param.name}}._var_info, {% + %}{{param.name}}=unwrap_vars({{param.name}}), {% endfor %} ), {% if schema.outputs and is_variadic(schema.outputs[-1]) %}out_variadic={{ out_variadic_solution if out_variadic_solution else "{}_count".format(schema.outputs[-1].name) }}, {% endif %}).get_output_vars( {% for param in schema.inputs - %}{{param.name}}={{param.name}}._value, {% + %}{{param.name}}=get_value({{param.name}}), {% endfor %} ){% if schema.outputs | length <= 1 diff --git a/tools/templates/constructor.jinja2 b/tools/templates/constructor.jinja2 index 6accb945..63bf2cb8 100644 --- a/tools/templates/constructor.jinja2 +++ b/tools/templates/constructor.jinja2 @@ -1,11 +1,11 @@ def {{ schema.name | get_constructor_name }}({% for param in schema.inputs %}{% if is_optional(param) - %}{{ param.name }}: Optional[VarInfo] = None, {% + %}{{ param.name }}: Optional[Var] = None, {% elif is_variadic(param) - %}{{ param.name }}: Sequence[VarInfo]{{" = ()" if loop.index0 >= schema.min_input else ""}}, {% + %}{{ param.name }}: Sequence[Var]{{" = ()" if loop.index0 >= schema.min_input else ""}}, {% else - %}{{ param.name }}: VarInfo, {% + %}{{ param.name }}: Var, {% endif %}{% endfor %} {% if schema.attributes %}*, {% diff --git a/tools/templates/preamble.jinja2 b/tools/templates/preamble.jinja2 index e4e320f3..e5dc8e83 100644 --- a/tools/templates/preamble.jinja2 +++ b/tools/templates/preamble.jinja2 @@ -2,12 +2,11 @@ import typing import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( Any, Callable, - Iterable, Optional, - Sequence, Union, ) from typing import cast as typing_cast @@ -15,7 +14,7 @@ from typing import cast as typing_cast import numpy as np import numpy.typing as npt -from spox._var import Var, result_type +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, From 1d6bcbcdeabe556bc8c936c984868e3b56aba76d Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Thu, 31 Oct 2024 19:43:03 +0200 Subject: [PATCH 03/29] Changes --- src/spox/_build.py | 10 +++--- src/spox/_fields.py | 44 +++++++++++++++++++++-- src/spox/_function.py | 4 +-- src/spox/_future.py | 52 +++++++++++++-------------- src/spox/_graph.py | 57 ++++++++++++++--------------- src/spox/_inline.py | 3 +- src/spox/_node.py | 29 ++++----------- src/spox/_public.py | 12 +++---- src/spox/_var.py | 73 +++++++++++++++++++++++++++++++++++--- tests/test_constructors.py | 2 +- 10 files changed, 185 insertions(+), 101 deletions(-) diff --git a/src/spox/_build.py b/src/spox/_build.py index 60064da1..d3c59312 100644 --- a/src/spox/_build.py +++ b/src/spox/_build.py @@ -21,7 +21,7 @@ from ._node import Node from ._scope import Scope from ._traverse import iterative_dfs -from ._var import VarInfo +from ._var import Var, VarInfo, unwrap_vars if TYPE_CHECKING: from ._graph import Graph @@ -203,8 +203,8 @@ def build_main(self) -> BuildResult: @staticmethod def get_intro_results( - request_results: dict[str, VarInfo], set_names: bool - ) -> list[VarInfo]: + request_results: dict[str, Var], set_names: bool + ) -> list[Var]: """ Helper method for wrapping all requested results into a single Introduce and possibly naming them. @@ -212,7 +212,7 @@ def get_intro_results( as usually only ONNX subgraph input/output ordering is significant. """ # Created vars all have the same op - vars = list(intros(*request_results.values())) + vars = list(intros(*unwrap_vars(request_results.values()))) for key, var in zip(request_results, vars): if set_names: var._rename(key) @@ -290,7 +290,7 @@ def collect_arguments(nd: Node): else: # If there is a request, we may not have found it by traversal if an argument was unused. all_arguments |= set(graph.requested_arguments) - self.arguments_of[graph] = list(graph.requested_arguments) + self.arguments_of[graph] = unwrap_vars(graph.requested_arguments) if set(self.arguments_of[graph]) & claimed_arguments: raise BuildError( diff --git a/src/spox/_fields.py b/src/spox/_fields.py index 7bcd4227..5bd727be 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -3,12 +3,15 @@ import dataclasses import enum +import warnings from collections.abc import Iterable, Iterator, Sequence from dataclasses import dataclass from typing import Any, Optional, Union from ._attributes import Attr -from ._var import VarInfo +from ._exceptions import InferenceWarning +from ._value_prop import PropValue +from ._var import Var, VarInfo @dataclass @@ -113,4 +116,41 @@ class BaseInputs(BaseVarInfos): @dataclass class BaseOutputs(BaseVarInfos): - pass + def _propagate_vars( + self, + prop_values={}, + flatten_variadic=False, + ): + def _create_var(key, var_info): + ret = Var(var_info, None) + + if var_info.type is None or key not in prop_values: + return ret + + prop = PropValue(var_info.type, prop_values.get(key)) + if prop.check(): + ret._value = prop + else: + warnings.warn( + InferenceWarning( + f"Propagated value {prop} does not type-check, dropping. " + f"Hint: this indicates a bug with the current value prop backend or type inference." + ) + ) + + return ret + + ret_dict = {} + + for key, var_info in self.__dict__.items(): + if var_info is None or isinstance(var_info, VarInfo): + ret_dict[key] = _create_var(key, var_info) + elif flatten_variadic: + for i, v in enumerate(var_info): + ret_dict[f"{key}_{i}"] = _create_var(f"{key}_{i}", v) + else: + ret_dict[key] = [ + _create_var(f"{key}_{i}", v) for i, v in enumerate(var_info) + ] + + return ret_dict diff --git a/src/spox/_function.py b/src/spox/_function.py index 4bc64a8d..60377f3b 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -14,7 +14,7 @@ from ._internal_op import _InternalNode from ._node import Node, OpType from ._type_system import Type -from ._var import VarInfo +from ._var import Var, VarInfo if TYPE_CHECKING: from . import _graph @@ -42,7 +42,7 @@ class Function(_InternalNode): via the ``to_onnx_function`` method. """ - func_args: dict[str, VarInfo] + func_args: dict[str, Var] func_attrs: dict[str, _attributes.Attr] func_inputs: BaseInputs func_outputs: BaseOutputs diff --git a/src/spox/_future.py b/src/spox/_future.py index a806fab7..8199d563 100644 --- a/src/spox/_future.py +++ b/src/spox/_future.py @@ -14,7 +14,7 @@ import spox._value_prop from spox._graph import initializer as _initializer from spox._type_system import Tensor -from spox._var import VarInfo +from spox._var import Var TypeWarningLevel = spox._node.TypeWarningLevel @@ -46,7 +46,7 @@ def value_prop_backend(backend: ValuePropBackend): set_value_prop_backend(prev_backend) -def initializer(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> VarInfo: +def initializer(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: """ Create a VarInfo with a constant value. @@ -79,14 +79,14 @@ def __init__(self, op, type_promotion: bool, constant_promotion: bool): self.constant_promotion = constant_promotion def _promote( - self, *args: Union[VarInfo, np.generic, int, float], to_floating: bool = False - ) -> Iterable[Optional[VarInfo]]: + self, *args: Union[Var, np.generic, int, float], to_floating: bool = False + ) -> Iterable[Optional[Var]]: """ Apply constant promotion and type promotion to given parameters, creating constants and/or casting. """ targets: list[Union[np.dtype, np.generic, int, float]] = [ - x.type.dtype if isinstance(x, VarInfo) and isinstance(x.type, Tensor) else x # type: ignore + x.type.dtype if isinstance(x, Var) and isinstance(x.type, Tensor) else x # type: ignore for x in args ] if self.type_promotion: @@ -97,7 +97,7 @@ def _promote( dtypes = {dtype for dtype in targets if isinstance(dtype, np.dtype)} if len(dtypes) > 1: raise TypeError( - f"Inconsistent types for VarInfo operator with no type promotion: {dtypes}." + f"Inconsistent types for Var operator with no type promotion: {dtypes}." ) (target_type,) = dtypes if issubclass(target_type.type, np.integer): @@ -113,55 +113,55 @@ def _promote( # TODO: Handle more constant-target inconsistencies here? def _promote_target( - obj: Union[VarInfo, np.generic, int, float], - ) -> Optional[VarInfo]: + obj: Union[Var, np.generic, int, float], + ) -> Optional[Var]: if self.constant_promotion and isinstance(obj, (np.generic, int, float)): return self.op.const(np.array(obj, dtype=target_type)) - elif isinstance(obj, VarInfo): + elif isinstance(obj, Var): return self.op.cast(obj, to=target_type) if self.type_promotion else obj raise TypeError( - f"Bad value '{obj!r}' of type {type(obj).__name__!r} for operator overloading with VarInfo. " + f"Bad value '{obj!r}' of type {type(obj).__name__!r} for operator overloading with Var. " f"({self.type_promotion=}, {self.constant_promotion=})" ) return tuple(var for var in map(_promote_target, args)) - def add(self, a, b) -> VarInfo: + def add(self, a, b) -> Var: a, b = self._promote(a, b) return self.op.add(a, b) - def sub(self, a, b) -> VarInfo: + def sub(self, a, b) -> Var: a, b = self._promote(a, b) return self.op.sub(a, b) - def mul(self, a, b) -> VarInfo: + def mul(self, a, b) -> Var: a, b = self._promote(a, b) return self.op.mul(a, b) - def truediv(self, a, b) -> VarInfo: + def truediv(self, a, b) -> Var: a, b = self._promote(a, b, to_floating=True) return self.op.div(a, b) - def floordiv(self, a, b) -> VarInfo: + def floordiv(self, a, b) -> Var: a, b = self._promote(a, b) c = self.op.div(a, b) if isinstance(c.type, Tensor) and not issubclass(c.type._elem_type, np.integer): c = self.op.floor(c) return c - def neg(self, a: VarInfo) -> VarInfo: + def neg(self, a: Var) -> Var: return self.op.neg(a) - def and_(self, a: VarInfo, b: VarInfo) -> VarInfo: + def and_(self, a: Var, b: Var) -> Var: return self.op.and_(a, b) - def or_(self, a: VarInfo, b: VarInfo) -> VarInfo: + def or_(self, a: Var, b: Var) -> Var: return self.op.or_(a, b) - def xor(self, a: VarInfo, b: VarInfo) -> VarInfo: + def xor(self, a: Var, b: Var) -> Var: return self.op.xor(a, b) - def not_(self, a: VarInfo) -> VarInfo: + def not_(self, a: Var) -> Var: return self.op.not_(a) @@ -169,7 +169,7 @@ def not_(self, a: VarInfo) -> VarInfo: def operator_overloading( op, type_promotion: bool = False, constant_promotion: bool = True ): - """Enable operator overloading on VarInfo for this block. + """Enable operator overloading on Var for this block. May be used either as a context manager, or a decorator. @@ -187,7 +187,7 @@ def operator_overloading( if the type was not conclusively floating (as in numpy). False by default. constant_promotion - Whether operator overloading should implicitly promote primitive scalar constants to VarInfo. + Whether operator overloading should implicitly promote primitive scalar constants to Var. True by default. Examples @@ -203,12 +203,12 @@ def operator_overloading( ... return x * y >>> assert foo()._get_value() == np.array(6) """ - prev_dispatcher = VarInfo._operator_dispatcher - VarInfo._operator_dispatcher = _NumpyLikeOperatorDispatcher( + prev_dispatcher = Var._operator_dispatcher + Var._operator_dispatcher = _NumpyLikeOperatorDispatcher( op, type_promotion, constant_promotion ) yield - VarInfo._operator_dispatcher = prev_dispatcher + Var._operator_dispatcher = prev_dispatcher __all__ = [ @@ -222,6 +222,6 @@ def operator_overloading( "ValuePropBackend", "set_value_prop_backend", "value_prop_backend", - # Operator overloading on VarInfo + # Operator overloading on Var "operator_overloading", ] diff --git a/src/spox/_graph.py b/src/spox/_graph.py index 4d191103..0470b289 100644 --- a/src/spox/_graph.py +++ b/src/spox/_graph.py @@ -22,7 +22,7 @@ from ._schemas import max_opset_policy from ._type_system import Tensor, Type from ._utils import from_array -from ._var import Var, VarInfo, unwrap_vars +from ._var import Var, VarInfo def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var]: @@ -36,8 +36,8 @@ def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var and its type is used to create a respective Tensor. Returns ------- - Dict[str, VarInfo] - Argument VarInfos of given Types, named the same as kwargs. + Dict[str, Var] + Argument Vars of given Types, named the same as kwargs. """ result = {} for name, info in kwargs.items(): @@ -66,14 +66,14 @@ def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var return result -def arguments(**kwargs: Optional[Union[Type, np.ndarray]]) -> tuple[VarInfo, ...]: - """This function is a shorthand for a respective call to ``arguments_dict``, unpacking the VarInfos from the dict.""" +def arguments(**kwargs: Optional[Union[Type, np.ndarray]]) -> tuple[Var, ...]: + """This function is a shorthand for a respective call to ``arguments_dict``, unpacking the Vars from the dict.""" return tuple(arguments_dict(**kwargs).values()) def enum_arguments( *infos: Union[Type, np.ndarray], prefix: str = "in" -) -> tuple[VarInfo, ...]: +) -> tuple[Var, ...]: """ Convenience function for creating an enumeration of arguments, prefixed with ``prefix``. Calls ``arguments`` internally. @@ -89,8 +89,8 @@ def enum_arguments( String to prefix the names of created arguments with. Returns ------- - Tuple[VarInfo, ...] - Argument VarInfos as specified, in the same order as information ``infos``. + Tuple[Var, ...] + Argument Vars as specified, in the same order as information ``infos``. """ return arguments(**{f"{prefix}{i}": info for i, info in enumerate(infos)}) @@ -108,7 +108,7 @@ def initializer(arr: np.ndarray) -> Var: Value of the initializer. Returns ------- - VarInfo which is always equal to the respective value provided by `arr`. + Var which is always equal to the respective value provided by `arr`. """ return _Initializer( _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), @@ -133,12 +133,12 @@ class Graph: Note: building a Graph is cached, so changing it in-place without the setters will invalidate the build. """ - _results: dict[str, VarInfo] + _results: dict[str, Var] _name: Optional[str] = None _doc_string: Optional[str] = None - _arguments: Optional[tuple[VarInfo, ...]] = None + _arguments: Optional[tuple[Var, ...]] = None _extra_opset_req: Optional[set[tuple[str, int]]] = None - _constructor: Optional[Callable[..., Iterable[VarInfo]]] = None + _constructor: Optional[Callable[..., Iterable[Var]]] = None _build_result: "_build.Cached[_build.BuildResult]" = dataclasses.field( default_factory=_build.Cached ) @@ -159,18 +159,14 @@ def __repr__(self): return f" ({res_repr}){': ' if comments else ''}{', '.join(comments)}>" def __post_init__(self): - if any(not isinstance(var, VarInfo) for var in self._results.values()): + if any(not isinstance(var, Var) for var in self._results.values()): seen_types = {type(obj) for obj in self._results.values()} - raise TypeError( - f"Graph results must be VarInfos, not {seen_types - {VarInfo}}." - ) + raise TypeError(f"Graph results must be Vars, not {seen_types - {Var}}.") if self._arguments is not None and any( - not isinstance(var, VarInfo) for var in self._arguments + not isinstance(var, Var) for var in self._arguments ): seen_types = {type(obj) for obj in self._arguments} - raise TypeError( - f"Build outputs must be VarInfos, not {seen_types - {VarInfo}}." - ) + raise TypeError(f"Build outputs must be Vars, not {seen_types - {Var}}.") def with_name(self, name: str) -> "Graph": """Return a Graph with its name set to ``name``.""" @@ -180,9 +176,9 @@ def with_doc(self, doc_string: str) -> "Graph": """Return a Graph with its doc string set to ``doc``.""" return replace(self, _doc_string=doc_string) - def with_arguments(self, *args: VarInfo) -> "Graph": + def with_arguments(self, *args: Var) -> "Graph": """ - Return a Graph with given VarInfos marked as exactly its arguments. + Return a Graph with given Vars marked as exactly its arguments. A useful idiom is ``results(...).with_arguments(...)`` when you want to specify both results and arguments. """ return replace(self, _arguments=args) @@ -197,11 +193,11 @@ def with_opset(self, *args: tuple[str, int]) -> "Graph": extra_opset_req |= self._extra_opset_req return replace(self, _extra_opset_req=extra_opset_req) - def _with_constructor(self, fun: Callable[..., Iterable[VarInfo]]) -> "Graph": + def _with_constructor(self, fun: Callable[..., Iterable[Var]]) -> "Graph": """Assign a constructor that constructed this Graph given ``self.requested_arguments``.""" return replace(self, _constructor=fun) - def _reconstruct(self, *args: VarInfo) -> "Graph": + def _reconstruct(self, *args: Var) -> "Graph": assert self._constructor is not None return ( results(**dict(zip(self._results, self._constructor(*args)))) @@ -217,12 +213,12 @@ def _inject_build_result(self, what: "_build.BuildResult") -> "Graph": return replace(self, _build_result=_build.Cached(what)) @property - def requested_arguments(self) -> Optional[Iterable[VarInfo]]: + def requested_arguments(self) -> Optional[Iterable[Var]]: """Arguments requested by this Graph (for building) - ``None`` if unspecified.""" return self._arguments @property - def requested_results(self) -> dict[str, VarInfo]: + def requested_results(self) -> dict[str, Var]: """Results (named) requested by this Graph (for building).""" return self._results @@ -449,7 +445,7 @@ def results(**kwargs: Var) -> Graph: Graph Graph with the results given in `kwargs`, in the same order. Keys are used as names for the results. """ - return Graph(unwrap_vars(kwargs)) + return Graph(kwargs) def enum_results(*vars: Var, prefix="out") -> Graph: @@ -460,7 +456,7 @@ def enum_results(*vars: Var, prefix="out") -> Graph: Parameters ---------- vars - VarInfos to be marked as results. + Vars to be marked as results. prefix String to prefix the names of created results with. Returns @@ -482,7 +478,7 @@ def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[Var]]) -> Graph: types A list of argument types for the subgraph. fun - A function taking as many VarInfo arguments as the length of `types`, and returning the results of the subgraph. + A function taking as many Var arguments as the length of `types`, and returning the results of the subgraph. Returns ------- Graph @@ -499,5 +495,6 @@ def subgraph(types: Iterable[Type], fun: Callable[..., Iterable[Var]]) -> Graph: raise TypeError("Subgraph callback must be callable.") outs = fun(*ins) if not (isinstance(outs, Iterable) and all(isinstance(out, Var) for out in outs)): - raise TypeError("Subgraph result must be an Iterable of VarInfo.") + raise TypeError("Subgraph result must be an Iterable of Var.") + return enum_results(*outs).with_arguments(*ins)._with_constructor(fun) diff --git a/src/spox/_inline.py b/src/spox/_inline.py index ce7f7274..b8bf407d 100644 --- a/src/spox/_inline.py +++ b/src/spox/_inline.py @@ -135,8 +135,7 @@ def propagate_values(self, initializers) -> dict[str, _value_prop.PropValueType] return {} wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() input_feed = { - i.name: wrap_feed(var._value) - for i, var in zip(self.model.graph.input, self.inputs.inputs) + i.name: wrap_feed(initializers.get(i.name)) for i in self.model.graph.input } output_feed = run(self.model, input_feed) return { diff --git a/src/spox/_node.py b/src/spox/_node.py index e69f5890..8910604b 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -19,8 +19,8 @@ from ._exceptions import InferenceWarning from ._fields import BaseAttributes, BaseInputs, BaseOutputs, VarFieldKind from ._type_system import Type -from ._value_prop import PropValue, PropValueType -from ._var import Var, VarInfo +from ._value_prop import PropValueType +from ._var import VarInfo if typing.TYPE_CHECKING: from ._graph import Graph @@ -235,29 +235,12 @@ def inference(self, infer_types: bool = True): # Attempt to use the ones from kwargs, if none then what type inference gave var.type = out_types.get(key) - def get_output_vars(self, **initializers): + def get_output_vars(self, flatten_variadic=False, **initializers): # After typing everything, try to get values for outputs out_values = self.propagate_values(initializers) - ret = { - key: Var(var_info, None) - for key, var_info in self.outputs.get_vars().items() - } - for key, var_info in self.outputs.get_vars().items(): - if var_info.type is None or key not in out_values: - continue - - prop = PropValue(var_info.type, out_values.get(key)) - if prop.check(): - ret[key]._value = prop - else: - warnings.warn( - InferenceWarning( - f"Propagated value {prop} does not type-check, dropping. " - f"Hint: this indicates a bug with the current value prop backend or type inference." - ) - ) - - return ret + return self.outputs._propagate_vars( + out_values, flatten_variadic=flatten_variadic + ) def validate_types(self) -> None: """Validation of types, ran at the end of Node creation.""" diff --git a/src/spox/_public.py b/src/spox/_public.py index 8247cbc0..2d845f84 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -17,7 +17,7 @@ from ._inline import _Inline from ._standard import _strip_dim_symbol from ._type_system import Type -from ._var import Var, VarInfo, unwrap_vars +from ._var import Var def argument(typ: Type) -> Var: @@ -43,10 +43,10 @@ def argument(typ: Type) -> Var: @contextlib.contextmanager def _temporary_renames(**kwargs: Var): # The build code can't really special-case variable names that are - # not just ``VarInfo._name``. So we set names here and reset them + # not just ``Var._name``. So we set names here and reset them # afterwards. name: Optional[str] - pre: dict[VarInfo, Optional[str]] = {} + pre: dict[Var, Optional[str]] = {} try: for name, arg in kwargs.items(): pre[arg._var_info] = arg._var_info._name @@ -130,8 +130,7 @@ def build( with _temporary_renames(**inputs): graph = results(**outputs) if not drop_unused_inputs: - print({name: var._var_info for name, var in inputs.items()}) - graph = graph.with_arguments(*unwrap_vars(inputs.values())) + graph = graph.with_arguments(*inputs.values()) model_proto = graph.to_onnx_model() # Validate that no further inputs were required. @@ -303,7 +302,8 @@ def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: out_variadic=len(model.graph.output), model=model, ) - return node.get_output_vars() + + return node.get_output_vars(flatten_variadic=True) return inline_inner diff --git a/src/spox/_var.py b/src/spox/_var.py index 3db5f913..06a327fc 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -3,7 +3,7 @@ import typing from collections.abc import Iterable, Sequence -from typing import Callable, Optional, TypeVar, Union, overload +from typing import Any, Callable, ClassVar, Optional, TypeVar, Union, overload import numpy as np @@ -15,6 +15,13 @@ F = TypeVar("F", bound=Callable) +class NotImplementedOperatorDispatcher: + def _not_impl(self, *_): + return NotImplemented + + add = sub = mul = truediv = floordiv = neg = and_ = or_ = xor = not_ = _not_impl + + class VarInfo: """ Abstraction for a single ONNX value - like a tensor - that can be passed around in Python code. @@ -149,6 +156,8 @@ class Var: _var_info: VarInfo _value: Optional[_value_prop.PropValue] + _operator_dispatcher: ClassVar[Any] = NotImplementedOperatorDispatcher() + def __init__( self, var_info: VarInfo, @@ -243,6 +252,60 @@ def __copy__(self) -> "Var": def __deepcopy__(self, _) -> "Var": raise ValueError("'Var' objects cannot be deepcopied.") + def __add__(self, other) -> "Var": + return Var._operator_dispatcher.add(self, other) + + def __sub__(self, other) -> "Var": + return Var._operator_dispatcher.sub(self, other) + + def __mul__(self, other) -> "Var": + return Var._operator_dispatcher.mul(self, other) + + def __truediv__(self, other) -> "Var": + return Var._operator_dispatcher.truediv(self, other) + + def __floordiv__(self, other) -> "Var": + return Var._operator_dispatcher.floordiv(self, other) + + def __neg__(self) -> "Var": + return Var._operator_dispatcher.neg(self) + + def __and__(self, other) -> "Var": + return Var._operator_dispatcher.and_(self, other) + + def __or__(self, other) -> "Var": + return Var._operator_dispatcher.or_(self, other) + + def __xor__(self, other) -> "Var": + return Var._operator_dispatcher.xor(self, other) + + def __invert__(self) -> "Var": + return Var._operator_dispatcher.not_(self) + + def __radd__(self, other) -> "Var": + return Var._operator_dispatcher.add(other, self) + + def __rsub__(self, other) -> "Var": + return Var._operator_dispatcher.sub(other, self) + + def __rmul__(self, other) -> "Var": + return Var._operator_dispatcher.mul(other, self) + + def __rtruediv__(self, other) -> "Var": + return Var._operator_dispatcher.truediv(other, self) + + def __rfloordiv__(self, other) -> "Var": + return Var._operator_dispatcher.floordiv(other, self) + + def __rand__(self, other) -> "Var": + return Var._operator_dispatcher.and_(other, self) + + def __ror__(self, other) -> "Var": + return Var._operator_dispatcher.or_(other, self) + + def __rxor__(self, other) -> "Var": + return Var._operator_dispatcher.xor(other, self) + # we want unwrap to be type aware T = TypeVar("T") @@ -257,11 +320,11 @@ def unwrap_vars(var: Optional[Var]) -> Optional[VarInfo]: ... @overload -def unwrap_vars(var: Union[Sequence[Var], Iterable[Var]]) -> list[VarInfo]: ... +def unwrap_vars(var: dict[T, Var]) -> dict[T, VarInfo]: ... @overload -def unwrap_vars(var: dict[T, Var]) -> dict[T, VarInfo]: ... +def unwrap_vars(var: Union[Sequence[Var], Iterable[Var]]) -> list[VarInfo]: ... def unwrap_vars(var): @@ -316,7 +379,9 @@ def result_type( return np.dtype( np.result_type( *( - typ.unwrap_tensor().dtype if isinstance(typ, VarInfo) else typ + typ.unwrap_tensor().dtype + if isinstance(typ, Var) or isinstance(typ, VarInfo) + else typ for typ in types ) ) diff --git a/tests/test_constructors.py b/tests/test_constructors.py index 5dc3c641..c36394ae 100644 --- a/tests/test_constructors.py +++ b/tests/test_constructors.py @@ -34,7 +34,7 @@ def test_variadic_no_input_list_mutation(onnx_helper): ins = [a, b] concat = op.concat(ins, axis=0) ins[1] = b - assert list(concat._op.inputs) == [a, b] + assert list(concat._op.inputs.get_vars()) == [a, b] def test_variadic_no_attr_mutation_array(onnx_helper): From 3c8e9b11b733a35d98552b65de28abcfd8c844c0 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Fri, 1 Nov 2024 18:12:46 +0200 Subject: [PATCH 04/29] Fix ml --- src/spox/_public.py | 4 +- src/spox/opset/ai/onnx/ml/v3.py | 374 ++++++++++++++++++-------------- src/spox/opset/ai/onnx/ml/v4.py | 21 +- 3 files changed, 227 insertions(+), 172 deletions(-) diff --git a/src/spox/_public.py b/src/spox/_public.py index 2d845f84..736f6a28 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -303,7 +303,9 @@ def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: model=model, ) - return node.get_output_vars(flatten_variadic=True) + return dict( + zip(out_names, node.get_output_vars(flatten_variadic=True).values()) + ) return inline_inner diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index b34d4020..65d31dd4 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -23,7 +23,7 @@ from spox._node import OpType from spox._standard import InferenceError, StandardNode from spox._type_system import Tensor, Type -from spox._var import Var +from spox._var import Var, VarInfo, get_value, unwrap_vars class _ArrayFeatureExtractor(StandardNode): @@ -33,12 +33,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - Y: Var + X: VarInfo + Y: VarInfo @dataclass class Outputs(BaseOutputs): - Z: Var + Z: VarInfo def infer_output_types(self) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -69,11 +69,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo def infer_output_types(self) -> dict[str, Type]: return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {} @@ -94,11 +94,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("CastMap", "ai.onnx.ml", 1) @@ -117,11 +117,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo def infer_output_types(self) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -150,11 +150,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("DictVectorizer", "ai.onnx.ml", 1) @@ -170,11 +170,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Sequence[Var] + X: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("FeatureVectorizer", "ai.onnx.ml", 1) @@ -193,11 +193,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo def infer_output_types(self) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -256,11 +256,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("LabelEncoder", "ai.onnx.ml", 2) @@ -281,12 +281,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var - Z: Var + Y: VarInfo + Z: VarInfo op_type = OpType("LinearClassifier", "ai.onnx.ml", 1) @@ -305,11 +305,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo def infer_output_types(self) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -339,11 +339,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo def infer_output_types(self) -> dict[str, Type]: if self.attrs.norm.value not in ("MAX", "L1", "L2"): @@ -368,11 +368,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo def infer_output_types(self) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -412,12 +412,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var - Z: Var + Y: VarInfo + Z: VarInfo op_type = OpType("SVMClassifier", "ai.onnx.ml", 1) @@ -440,11 +440,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("SVMRegressor", "ai.onnx.ml", 1) @@ -461,11 +461,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo def infer_output_types(self) -> dict[str, Type]: if self.inputs.X.type is None: @@ -520,12 +520,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var - Z: Var + Y: VarInfo + Z: VarInfo def infer_output_types(self) -> dict[str, Type]: e = ( @@ -585,11 +585,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo def infer_output_types(self) -> dict[str, Type]: if self.inputs.fully_typed: @@ -619,11 +619,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Z: Var + Z: VarInfo op_type = OpType("ZipMap", "ai.onnx.ml", 1) @@ -665,10 +665,13 @@ def array_feature_extractor( return _ArrayFeatureExtractor( _ArrayFeatureExtractor.Attributes(), _ArrayFeatureExtractor.Inputs( - X=X, - Y=Y, + X=unwrap_vars(X), + Y=unwrap_vars(Y), ), - ).outputs.Z + ).get_output_vars( + X=get_value(X), + Y=get_value(Y), + )["Z"] def binarizer( @@ -707,9 +710,11 @@ def binarizer( threshold=AttrFloat32(threshold, name="threshold"), ), _Binarizer.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def cast_map( @@ -766,9 +771,11 @@ def cast_map( max_map=AttrInt64(max_map, name="max_map"), ), _CastMap.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def category_mapper( @@ -834,9 +841,11 @@ def category_mapper( default_string=AttrString(default_string, name="default_string"), ), _CategoryMapper.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def dict_vectorizer( @@ -899,9 +908,11 @@ def dict_vectorizer( ), ), _DictVectorizer.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def feature_vectorizer( @@ -943,9 +954,11 @@ def feature_vectorizer( inputdimensions=AttrInt64s.maybe(inputdimensions, name="inputdimensions"), ), _FeatureVectorizer.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def imputer( @@ -1019,9 +1032,11 @@ def imputer( ), ), _Imputer.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def label_encoder( @@ -1117,9 +1132,11 @@ def label_encoder( values_strings=AttrStrings.maybe(values_strings, name="values_strings"), ), _LabelEncoder.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def linear_classifier( @@ -1179,23 +1196,29 @@ def linear_classifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - return _LinearClassifier( - _LinearClassifier.Attributes( - classlabels_ints=AttrInt64s.maybe( - classlabels_ints, name="classlabels_ints" + return ( + _LinearClassifier( + _LinearClassifier.Attributes( + classlabels_ints=AttrInt64s.maybe( + classlabels_ints, name="classlabels_ints" + ), + classlabels_strings=AttrStrings.maybe( + classlabels_strings, name="classlabels_strings" + ), + coefficients=AttrFloat32s(coefficients, name="coefficients"), + intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), + multi_class=AttrInt64(multi_class, name="multi_class"), + post_transform=AttrString(post_transform, name="post_transform"), ), - classlabels_strings=AttrStrings.maybe( - classlabels_strings, name="classlabels_strings" + _LinearClassifier.Inputs( + X=unwrap_vars(X), ), - coefficients=AttrFloat32s(coefficients, name="coefficients"), - intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), - multi_class=AttrInt64(multi_class, name="multi_class"), - post_transform=AttrString(post_transform, name="post_transform"), - ), - _LinearClassifier.Inputs( - X=X, - ), - ).outputs._unpack_to_any() + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) def linear_regressor( @@ -1255,9 +1278,11 @@ def linear_regressor( targets=AttrInt64(targets, name="targets"), ), _LinearRegressor.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def normalizer( @@ -1301,9 +1326,11 @@ def normalizer( norm=AttrString(norm, name="norm"), ), _Normalizer.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def one_hot_encoder( @@ -1362,9 +1389,11 @@ def one_hot_encoder( zeros=AttrInt64(zeros, name="zeros"), ), _OneHotEncoder.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def svmclassifier( @@ -1449,30 +1478,38 @@ def svmclassifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - return _SVMClassifier( - _SVMClassifier.Attributes( - classlabels_ints=AttrInt64s.maybe( - classlabels_ints, name="classlabels_ints" + return ( + _SVMClassifier( + _SVMClassifier.Attributes( + classlabels_ints=AttrInt64s.maybe( + classlabels_ints, name="classlabels_ints" + ), + classlabels_strings=AttrStrings.maybe( + classlabels_strings, name="classlabels_strings" + ), + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), + kernel_type=AttrString(kernel_type, name="kernel_type"), + post_transform=AttrString(post_transform, name="post_transform"), + prob_a=AttrFloat32s.maybe(prob_a, name="prob_a"), + prob_b=AttrFloat32s.maybe(prob_b, name="prob_b"), + rho=AttrFloat32s.maybe(rho, name="rho"), + support_vectors=AttrFloat32s.maybe( + support_vectors, name="support_vectors" + ), + vectors_per_class=AttrInt64s.maybe( + vectors_per_class, name="vectors_per_class" + ), ), - classlabels_strings=AttrStrings.maybe( - classlabels_strings, name="classlabels_strings" + _SVMClassifier.Inputs( + X=unwrap_vars(X), ), - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), - kernel_type=AttrString(kernel_type, name="kernel_type"), - post_transform=AttrString(post_transform, name="post_transform"), - prob_a=AttrFloat32s.maybe(prob_a, name="prob_a"), - prob_b=AttrFloat32s.maybe(prob_b, name="prob_b"), - rho=AttrFloat32s.maybe(rho, name="rho"), - support_vectors=AttrFloat32s.maybe(support_vectors, name="support_vectors"), - vectors_per_class=AttrInt64s.maybe( - vectors_per_class, name="vectors_per_class" - ), - ), - _SVMClassifier.Inputs( - X=X, - ), - ).outputs._unpack_to_any() + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) def svmregressor( @@ -1548,9 +1585,11 @@ def svmregressor( support_vectors=AttrFloat32s.maybe(support_vectors, name="support_vectors"), ), _SVMRegressor.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def scaler( @@ -1598,9 +1637,11 @@ def scaler( scale=AttrFloat32s.maybe(scale, name="scale"), ), _Scaler.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def tree_ensemble_classifier( @@ -1737,54 +1778,63 @@ def tree_ensemble_classifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - return _TreeEnsembleClassifier( - _TreeEnsembleClassifier.Attributes( - base_values=AttrFloat32s.maybe(base_values, name="base_values"), - base_values_as_tensor=AttrTensor.maybe( - base_values_as_tensor, name="base_values_as_tensor" - ), - class_ids=AttrInt64s.maybe(class_ids, name="class_ids"), - class_nodeids=AttrInt64s.maybe(class_nodeids, name="class_nodeids"), - class_treeids=AttrInt64s.maybe(class_treeids, name="class_treeids"), - class_weights=AttrFloat32s.maybe(class_weights, name="class_weights"), - class_weights_as_tensor=AttrTensor.maybe( - class_weights_as_tensor, name="class_weights_as_tensor" - ), - classlabels_int64s=AttrInt64s.maybe( - classlabels_int64s, name="classlabels_int64s" - ), - classlabels_strings=AttrStrings.maybe( - classlabels_strings, name="classlabels_strings" + return ( + _TreeEnsembleClassifier( + _TreeEnsembleClassifier.Attributes( + base_values=AttrFloat32s.maybe(base_values, name="base_values"), + base_values_as_tensor=AttrTensor.maybe( + base_values_as_tensor, name="base_values_as_tensor" + ), + class_ids=AttrInt64s.maybe(class_ids, name="class_ids"), + class_nodeids=AttrInt64s.maybe(class_nodeids, name="class_nodeids"), + class_treeids=AttrInt64s.maybe(class_treeids, name="class_treeids"), + class_weights=AttrFloat32s.maybe(class_weights, name="class_weights"), + class_weights_as_tensor=AttrTensor.maybe( + class_weights_as_tensor, name="class_weights_as_tensor" + ), + classlabels_int64s=AttrInt64s.maybe( + classlabels_int64s, name="classlabels_int64s" + ), + classlabels_strings=AttrStrings.maybe( + classlabels_strings, name="classlabels_strings" + ), + nodes_falsenodeids=AttrInt64s.maybe( + nodes_falsenodeids, name="nodes_falsenodeids" + ), + nodes_featureids=AttrInt64s.maybe( + nodes_featureids, name="nodes_featureids" + ), + nodes_hitrates=AttrFloat32s.maybe( + nodes_hitrates, name="nodes_hitrates" + ), + nodes_hitrates_as_tensor=AttrTensor.maybe( + nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor" + ), + nodes_missing_value_tracks_true=AttrInt64s.maybe( + nodes_missing_value_tracks_true, + name="nodes_missing_value_tracks_true", + ), + nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), + nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), + nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), + nodes_truenodeids=AttrInt64s.maybe( + nodes_truenodeids, name="nodes_truenodeids" + ), + nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), + nodes_values_as_tensor=AttrTensor.maybe( + nodes_values_as_tensor, name="nodes_values_as_tensor" + ), + post_transform=AttrString(post_transform, name="post_transform"), ), - nodes_falsenodeids=AttrInt64s.maybe( - nodes_falsenodeids, name="nodes_falsenodeids" - ), - nodes_featureids=AttrInt64s.maybe( - nodes_featureids, name="nodes_featureids" - ), - nodes_hitrates=AttrFloat32s.maybe(nodes_hitrates, name="nodes_hitrates"), - nodes_hitrates_as_tensor=AttrTensor.maybe( - nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor" - ), - nodes_missing_value_tracks_true=AttrInt64s.maybe( - nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true" + _TreeEnsembleClassifier.Inputs( + X=unwrap_vars(X), ), - nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), - nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), - nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), - nodes_truenodeids=AttrInt64s.maybe( - nodes_truenodeids, name="nodes_truenodeids" - ), - nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), - nodes_values_as_tensor=AttrTensor.maybe( - nodes_values_as_tensor, name="nodes_values_as_tensor" - ), - post_transform=AttrString(post_transform, name="post_transform"), - ), - _TreeEnsembleClassifier.Inputs( - X=X, - ), - ).outputs._unpack_to_any() + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) def tree_ensemble_regressor( @@ -1836,14 +1886,12 @@ def tree_ensemble_regressor( 'SUM,' 'MIN,' 'MAX.' base_values Attribute. - Base values for regression, added to final prediction after applying - aggregate_function; the size must be the same as the classes or can be - left unassigned (assumed 0) + Base values for classification, added to final class score; the size + must be the same as the classes or can be left unassigned (assumed 0) base_values_as_tensor Attribute. - Base values for regression, added to final prediction after applying - aggregate_function; the size must be the same as the classes or can be - left unassigned (assumed 0) + Base values for classification, added to final class score; the size + must be the same as the classes or can be left unassigned (assumed 0) n_targets Attribute. The total number of targets. @@ -1962,9 +2010,11 @@ def tree_ensemble_regressor( ), ), _TreeEnsembleRegressor.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] def zip_map( @@ -2017,9 +2067,11 @@ def zip_map( ), ), _ZipMap.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Z + ).get_output_vars( + X=get_value(X), + )["Z"] _OPERATORS = { diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index 9e51382c..4c781564 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -22,7 +22,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._var import Var +from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.ml.v3 import ( _ArrayFeatureExtractor, _Binarizer, @@ -67,7 +67,7 @@ class Attributes(BaseAttributes): default_float: AttrFloat32 default_int64: AttrInt64 default_string: AttrString - default_tensor: Optional[AttrTensor] + default_tensor: AttrTensor keys_floats: Optional[AttrFloat32s] keys_int64s: Optional[AttrInt64s] keys_strings: Optional[AttrStrings] @@ -79,11 +79,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("LabelEncoder", "ai.onnx.ml", 4) @@ -98,7 +98,7 @@ def label_encoder( default_float: float = -0.0, default_int64: int = -1, default_string: str = "_Unused", - default_tensor: Optional[np.ndarray] = None, + default_tensor: np.ndarray, keys_floats: Optional[Iterable[float]] = None, keys_int64s: Optional[Iterable[int]] = None, keys_strings: Optional[Iterable[str]] = None, @@ -147,8 +147,7 @@ def label_encoder( A string. default_tensor Attribute. - A default tensor. {"*Unused"} if values*\ \* has string type, {-1} if - values\_\* has integral type, and {-0.f} if values\_\* has float type. + A default tensor. keys_floats Attribute. A list of floats. @@ -196,7 +195,7 @@ def label_encoder( default_float=AttrFloat32(default_float, name="default_float"), default_int64=AttrInt64(default_int64, name="default_int64"), default_string=AttrString(default_string, name="default_string"), - default_tensor=AttrTensor.maybe(default_tensor, name="default_tensor"), + default_tensor=AttrTensor(default_tensor, name="default_tensor"), keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), @@ -207,9 +206,11 @@ def label_encoder( values_tensor=AttrTensor.maybe(values_tensor, name="values_tensor"), ), _LabelEncoder.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] _OPERATORS = { From 096a4f48244b70fd6c31a41fb66f572de55b6179 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Mon, 4 Nov 2024 15:39:57 +0200 Subject: [PATCH 05/29] Fix some tests --- src/spox/_build.py | 6 +++--- src/spox/_internal_op.py | 40 +++++++++++++++++------------------ src/spox/_var.py | 4 ++-- tests/test_custom_operator.py | 15 +++++++------ tests/test_function.py | 22 +++++++++---------- 5 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/spox/_build.py b/src/spox/_build.py index d3c59312..f7ce3b29 100644 --- a/src/spox/_build.py +++ b/src/spox/_build.py @@ -212,7 +212,7 @@ def get_intro_results( as usually only ONNX subgraph input/output ordering is significant. """ # Created vars all have the same op - vars = list(intros(*unwrap_vars(request_results.values()))) + vars = list(intros(*request_results.values())) for key, var in zip(request_results, vars): if set_names: var._rename(key) @@ -244,8 +244,8 @@ def discover(self, graph: "Graph") -> tuple[set[VarInfo], set[VarInfo]]: # Create and set the source & results of this graph if not graph.requested_results: raise BuildError(f"Graph {graph} has no results.") - self.results_of[graph] = self.get_intro_results( - graph.requested_results, graph is self.main + self.results_of[graph] = unwrap_vars( + self.get_intro_results(graph.requested_results, graph is self.main) ) self.source_of[graph] = self.results_of[graph][0]._op diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index 095ed914..f734aff1 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -20,7 +20,7 @@ from ._shape import SimpleShape from ._type_system import Tensor, Type from ._value_prop import PropValueType -from ._var import VarInfo +from ._var import Var, VarInfo, unwrap_vars # This is a default used for internal operators that # require the default domain. The most common of these @@ -192,7 +192,7 @@ def to_onnx( return protos -def intros(*args: VarInfo) -> Sequence[VarInfo]: +def intros(*args: Var) -> Sequence[Var]: """ Internal identity operator with variadic arguments. @@ -206,55 +206,55 @@ def intros(*args: VarInfo) -> Sequence[VarInfo]: Parameters ---------- args - VarInfos to introduce in current scope. + Vars to introduce in current scope. Returns ------- - Sequence[VarInfo] - VarInfos of the same value as ``args``, but with a shared dependency. + Sequence[Var] + Vars of the same value as ``args``, but with a shared dependency. """ return _Introduce( - None, _Introduce.Inputs(args), out_variadic=len(args) - ).outputs.outputs + None, _Introduce.Inputs(unwrap_vars(args)), out_variadic=len(args) + ).get_output_vars()["outputs"] -def intro(*args: VarInfo) -> VarInfo: +def intro(*args: Var) -> Var: """Introduces arguments like ``intros``, but only returns the last.""" return intros(*args)[-1] -def unsafe_cast(x: VarInfo, typ: Type) -> VarInfo: +def unsafe_cast(x: Var, typ: Type) -> Var: """ Creates a new var with the type forcefully set to ``typ``. - Assumes that the real type of the VarInfo is indeed compatible with ``shape`` (for example it was unknown). + Assumes that the real type of the Var is indeed compatible with ``shape`` (for example it was unknown). The function is meant for use when type inference failed, and it has to be overriden to avoid further failures. - If you want to properly change a ``VarInfo``'s type, use an operator like Cast, CastLike, Optional, etc. + If you want to properly change a ``Var``'s type, use an operator like Cast, CastLike, Optional, etc. Parameters ---------- x - VarInfo to retype. + Var to retype. typ Target type - must be a constant. Returns ------- - VarInfo - VarInfo with the type reset to whatever was given. + Var + Var with the type reset to whatever was given. """ y = intro(x) - y.type = typ + y._var_info.type = typ return y -def unsafe_reshape(x: VarInfo, shape: SimpleShape) -> VarInfo: +def unsafe_reshape(x: Var, shape: SimpleShape) -> Var: """ Creates a new var with the shape forcefully set to ``shape`` (like an unsafe cast). - Assumes that the real shape of the VarInfo is indeed compatible with ``shape`` (for example it was unknown). + Assumes that the real shape of the Var is indeed compatible with ``shape`` (for example it was unknown). The function is meant for use when shape inference failed, and it has to be overriden to avoid failures. @@ -263,12 +263,12 @@ def unsafe_reshape(x: VarInfo, shape: SimpleShape) -> VarInfo: Parameters ---------- x - VarInfo to reshape. + Var to reshape. shape Target shape - must be a constant. Returns ------- - VarInfo - VarInfo with the same Tensor element type, but different shape. + Var + Var with the same Tensor element type, but different shape. """ return unsafe_cast(x, Tensor(x.unwrap_tensor().dtype, shape)) diff --git a/src/spox/_var.py b/src/spox/_var.py index 06a327fc..751988f7 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -333,9 +333,9 @@ def unwrap_vars(var): elif isinstance(var, Var): return var._var_info elif isinstance(var, dict): - return {k: v._var_info for k, v in var.items()} + return {k: unwrap_vars(v) for k, v in var.items()} elif isinstance(var, Sequence) or isinstance(var, Iterable): - return [v._var_info for v in var] + return [unwrap_vars(v) for v in var] else: raise ValueError("Unsupported type for unwrap_vars") diff --git a/tests/test_custom_operator.py b/tests/test_custom_operator.py index 1c3c195c..752a17f3 100644 --- a/tests/test_custom_operator.py +++ b/tests/test_custom_operator.py @@ -19,6 +19,7 @@ from spox._graph import arguments, results from spox._node import Node, OpType from spox._type_system import Tensor, Type +from spox._var import VarInfo # Define the Node for this operator - need to know the attributes, inputs and outputs statically @@ -32,11 +33,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo # This is optional, but is useful when defining the inference functions below. attrs: Attributes @@ -54,19 +55,21 @@ def infer_output_types(self) -> dict[str, Type]: ) return {"Y": t} - def propagate_values(self) -> dict[str, np.ndarray]: + def propagate_values(self, initializers) -> dict[str, np.ndarray]: # This is optional and implements value propagation ('partial data propagation' in ONNX). # In essence constant folding carried through for purposes of type inference. return ( - {"Y": np.linalg.inv(self.inputs.X._get_value())} - if self.inputs.X._value is not None + {"Y": np.linalg.inv(initializers["X"].value)} + if initializers["X"] is not None else {} ) # Define the operator constructor which is actually used def inverse(matrix: Var) -> Var: - return Inverse(Inverse.Attributes(), Inverse.Inputs(matrix)).outputs.Y + return Inverse( + Inverse.Attributes(), Inverse.Inputs(matrix._var_info) + ).get_output_vars(X=matrix._value)["Y"] # Test the correct runtime behaviour with ORT diff --git a/tests/test_function.py b/tests/test_function.py index fd03d1b1..83273766 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -19,7 +19,7 @@ from spox._graph import arguments, results from spox._node import OpType from spox._type_system import Tensor -from spox._var import Var +from spox._var import Var, VarInfo @pytest.fixture @@ -32,11 +32,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("LinearFunction", "spox.test", 0) @@ -67,8 +67,8 @@ def linear_inner( slope_outer=AttrFloat32(a, "slope_outer"), shift_outer=AttrFloat32(b, "shift_outer"), ), - LinearFunction.Inputs(x), - ).outputs.Y + LinearFunction.Inputs(x._var_info), + ).get_output_vars(X=x._value)["Y"] return linear_inner @@ -83,11 +83,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("LinearFunction2", "spox.test", 0) @@ -111,8 +111,8 @@ def linear_inner( LinearFunction2.Attributes( slope1=AttrFloat32(a, name="slope1"), shift1=AttrFloat32(b, "shift1") ), - LinearFunction2.Inputs(x), - ).outputs.Y + LinearFunction2.Inputs(x._var_info), + ).get_output_vars(X=x._value)["Y"] return linear_inner @@ -129,11 +129,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("CubicFunction", "spox.test.extra", 0) From e29a9206ab00bb6e23e1d03df0e0260142fbe61e Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Mon, 4 Nov 2024 15:54:09 +0200 Subject: [PATCH 06/29] Fix some tests --- src/spox/_build.py | 2 +- src/spox/opset/ai/onnx/ml/v3.py | 10 +- src/spox/opset/ai/onnx/ml/v4.py | 9 +- src/spox/opset/ai/onnx/ml/v5.py | 12 +- src/spox/opset/ai/onnx/v17.py | 36 +-- src/spox/opset/ai/onnx/v19.py | 3 +- src/spox/opset/ai/onnx/v21.py | 400 ++++++++++++++++++-------------- 7 files changed, 271 insertions(+), 201 deletions(-) diff --git a/src/spox/_build.py b/src/spox/_build.py index f7ce3b29..8d782ba5 100644 --- a/src/spox/_build.py +++ b/src/spox/_build.py @@ -289,7 +289,7 @@ def collect_arguments(nd: Node): self.arguments_of[graph] = list(all_arguments - claimed_arguments) else: # If there is a request, we may not have found it by traversal if an argument was unused. - all_arguments |= set(graph.requested_arguments) + all_arguments |= set(unwrap_vars(graph.requested_arguments)) self.arguments_of[graph] = unwrap_vars(graph.requested_arguments) if set(self.arguments_of[graph]) & claimed_arguments: diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index 65d31dd4..939a3aab 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -1886,12 +1886,14 @@ def tree_ensemble_regressor( 'SUM,' 'MIN,' 'MAX.' base_values Attribute. - Base values for classification, added to final class score; the size - must be the same as the classes or can be left unassigned (assumed 0) + Base values for regression, added to final prediction after applying + aggregate_function; the size must be the same as the classes or can be + left unassigned (assumed 0) base_values_as_tensor Attribute. - Base values for classification, added to final class score; the size - must be the same as the classes or can be left unassigned (assumed 0) + Base values for regression, added to final prediction after applying + aggregate_function; the size must be the same as the classes or can be + left unassigned (assumed 0) n_targets Attribute. The total number of targets. diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index 4c781564..c9247b26 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -67,7 +67,7 @@ class Attributes(BaseAttributes): default_float: AttrFloat32 default_int64: AttrInt64 default_string: AttrString - default_tensor: AttrTensor + default_tensor: Optional[AttrTensor] keys_floats: Optional[AttrFloat32s] keys_int64s: Optional[AttrInt64s] keys_strings: Optional[AttrStrings] @@ -98,7 +98,7 @@ def label_encoder( default_float: float = -0.0, default_int64: int = -1, default_string: str = "_Unused", - default_tensor: np.ndarray, + default_tensor: Optional[np.ndarray] = None, keys_floats: Optional[Iterable[float]] = None, keys_int64s: Optional[Iterable[int]] = None, keys_strings: Optional[Iterable[str]] = None, @@ -147,7 +147,8 @@ def label_encoder( A string. default_tensor Attribute. - A default tensor. + A default tensor. {"*Unused"} if values*\ \* has string type, {-1} if + values\_\* has integral type, and {-0.f} if values\_\* has float type. keys_floats Attribute. A list of floats. @@ -195,7 +196,7 @@ def label_encoder( default_float=AttrFloat32(default_float, name="default_float"), default_int64=AttrInt64(default_int64, name="default_int64"), default_string=AttrString(default_string, name="default_string"), - default_tensor=AttrTensor(default_tensor, name="default_tensor"), + default_tensor=AttrTensor.maybe(default_tensor, name="default_tensor"), keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index 100bf179..6843a8ce 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -18,7 +18,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._var import Var +from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.ml.v4 import ( _ArrayFeatureExtractor, _Binarizer, @@ -77,11 +77,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var + X: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("TreeEnsemble", "ai.onnx.ml", 5) @@ -250,9 +250,11 @@ def tree_ensemble( tree_roots=AttrInt64s(tree_roots, name="tree_roots"), ), _TreeEnsemble.Inputs( - X=X, + X=unwrap_vars(X), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + )["Y"] _OPERATORS = { diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 7d9cff0b..c2be0920 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -4640,7 +4640,7 @@ def batch_normalization( training_mode Attribute. If set to true, it indicates BatchNormalization is being used for - training, and outputs 1, 2, 3, and 4 would be populated. + training, and outputs 1 and 2 are to be computed. Returns ======= @@ -8744,7 +8744,11 @@ def layer_normalization( indicate the i-th dimension of ``X``. If ``X``'s shape is ``[d[0], ..., d[axis-1], d[axis], ..., d[rank-1]]``, the shape of ``Mean`` and ``InvStdDev`` is ``[d[0], ..., d[axis-1], 1, ..., 1]``. - ``Y`` and ``X`` have the same shape. + ``Y`` and ``X`` have the same shape. This operator supports + unidirectional broadcasting (tensors ``Scale`` and ``B`` should be + unidirectional broadcastable to tensor ``X``); for more details please + check `the + doc `__. Parameters ========== @@ -9552,7 +9556,8 @@ def max_pool( output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. + ``i``. Sliding windows that would start in the right padded region are + ignored. ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: @@ -15485,16 +15490,16 @@ def top_k( ) -> tuple[Var, Var]: r""" Retrieve the top-K largest or smallest elements along a specified axis. - Given an input tensor of shape [a_1, a_2, ..., a_n, r] and integer + Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer argument k, return two outputs: - - Value tensor of shape [a_1, a_2, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a_n] which contains the values of the top k elements along the - specified axis + - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a\_{n-1}] which contains the values of the top k elements along + the specified axis - - Index tensor of shape [a_1, a_2, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a_n] which contains the indices of the top k elements (original - indices from the input tensor). + - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a\_{n-1}] which contains the indices of the top k elements + (original indices from the input tensor). - If "largest" is 1 (the default value) then the k largest elements are returned. @@ -15513,7 +15518,7 @@ def top_k( ========== X Type T. - Tensor of shape [a_1, a_2, ..., a_n, r] + Tensor of shape [a_0, a_1, ..., a\_{n-1}] K Type tensor(int64). A 1-D tensor containing a single positive value corresponding to the @@ -15534,12 +15539,13 @@ def top_k( ======= Values : Var Type T. - Tensor of shape [a_1, a_2, ..., a\_{axis-1}, k, a\_{axis+1}, ... a_n] - containing top K values from the input tensor + Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] containing top K values from the input tensor Indices : Var Type I. - Tensor of shape [a_1, a_2, ..., a\_{axis-1}, k, a\_{axis+1}, ... a_n] - containing the corresponding input tensor indices for the top K values. + Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] containing the corresponding input tensor indices for the top + K values. Notes ===== diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 74c88f35..8cf8cce4 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -821,7 +821,8 @@ def average_pool( output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. + ``i``. Sliding windows that would start in the right padded region are + ignored. ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index f4f027cc..1f7110aa 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -30,7 +30,7 @@ from spox._standard import StandardNode from spox._type_system import Tensor, Type from spox._value_prop import PropValueType -from spox._var import Var +from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v20 import ( _DFT, _GRU, @@ -385,11 +385,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Cast", "", 21) @@ -405,12 +405,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var - target_type: Var + input: VarInfo + target_type: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("CastLike", "", 21) @@ -434,9 +434,9 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo - def propagate_values(self) -> dict[str, PropValueType]: + def propagate_values(self, initializers) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -476,11 +476,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("ConstantOfShape", "", 21) @@ -497,13 +497,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - x_scale: Var - x_zero_point: Optional[Var] + x: VarInfo + x_scale: VarInfo + x_zero_point: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("DequantizeLinear", "", 21) @@ -519,11 +519,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Flatten", "", 21) @@ -541,13 +541,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Var - scale: Var - bias: Var + X: VarInfo + scale: VarInfo + bias: VarInfo @dataclass class Outputs(BaseOutputs): - Y: Var + Y: VarInfo op_type = OpType("GroupNormalization", "", 21) @@ -563,11 +563,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Var + input: VarInfo @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Identity", "", 21) @@ -584,11 +584,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - cond: Var + cond: VarInfo @dataclass class Outputs(BaseOutputs): - outputs: Sequence[Var] + outputs: Sequence[VarInfo] op_type = OpType("If", "", 21) @@ -604,13 +604,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - M: Optional[Var] - cond: Optional[Var] - v_initial: Sequence[Var] + M: Optional[VarInfo] + cond: Optional[VarInfo] + v_initial: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - v_final_and_scan_outputs: Sequence[Var] + v_final_and_scan_outputs: Sequence[VarInfo] op_type = OpType("Loop", "", 21) @@ -626,14 +626,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - pads: Var - constant_value: Optional[Var] - axes: Optional[Var] + data: VarInfo + pads: VarInfo + constant_value: Optional[VarInfo] + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - output: Var + output: VarInfo op_type = OpType("Pad", "", 21) @@ -649,18 +649,18 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - a: Var - a_scale: Var - a_zero_point: Var - b: Var - b_scale: Var - b_zero_point: Var - y_scale: Var - y_zero_point: Var + a: VarInfo + a_scale: VarInfo + a_zero_point: VarInfo + b: VarInfo + b_scale: VarInfo + b_zero_point: VarInfo + y_scale: VarInfo + y_zero_point: VarInfo @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("QLinearMatMul", "", 21) @@ -679,13 +679,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: Var - y_scale: Var - y_zero_point: Optional[Var] + x: VarInfo + y_scale: VarInfo + y_zero_point: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - y: Var + y: VarInfo op_type = OpType("QuantizeLinear", "", 21) @@ -701,12 +701,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - shape: Var + data: VarInfo + shape: VarInfo @dataclass class Outputs(BaseOutputs): - reshaped: Var + reshaped: VarInfo op_type = OpType("Reshape", "", 21) @@ -727,11 +727,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - initial_state_and_scan_inputs: Sequence[Var] + initial_state_and_scan_inputs: Sequence[VarInfo] @dataclass class Outputs(BaseOutputs): - final_state_and_scan_outputs: Sequence[Var] + final_state_and_scan_outputs: Sequence[VarInfo] op_type = OpType("Scan", "", 21) @@ -748,11 +748,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - shape: Var + shape: VarInfo op_type = OpType("Shape", "", 21) @@ -768,11 +768,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - size: Var + size: VarInfo op_type = OpType("Size", "", 21) @@ -788,12 +788,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Optional[Var] + data: VarInfo + axes: Optional[VarInfo] @dataclass class Outputs(BaseOutputs): - squeezed: Var + squeezed: VarInfo op_type = OpType("Squeeze", "", 21) @@ -809,11 +809,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var + data: VarInfo @dataclass class Outputs(BaseOutputs): - transposed: Var + transposed: VarInfo op_type = OpType("Transpose", "", 21) @@ -829,12 +829,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: Var - axes: Var + data: VarInfo + axes: VarInfo @dataclass class Outputs(BaseOutputs): - expanded: Var + expanded: VarInfo op_type = OpType("Unsqueeze", "", 21) @@ -880,26 +880,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules if the destination type is not a float 8 type. - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Float 8 type were introduced to speed up the training of deep models. By default the conversion of a float *x* obeys to the following rules. @@ -970,9 +970,11 @@ def cast( to=AttrDtype(to, name="to"), ), _Cast.Inputs( - input=input, + input=unwrap_vars(input), ), - ).outputs.output + ).get_output_vars( + input=get_value(input), + )["output"] def cast_like( @@ -1023,10 +1025,13 @@ def cast_like( saturate=AttrInt64(saturate, name="saturate"), ), _CastLike.Inputs( - input=input, - target_type=target_type, + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), ), - ).outputs.output + ).get_output_vars( + input=get_value(input), + target_type=get_value(target_type), + )["output"] def constant( @@ -1095,7 +1100,7 @@ def constant( value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), _Constant.Inputs(), - ).outputs.output + ).get_output_vars()["output"] def constant_of_shape( @@ -1140,9 +1145,11 @@ def constant_of_shape( value=AttrTensor.maybe(value, name="value"), ), _ConstantOfShape.Inputs( - input=input, + input=unwrap_vars(input), ), - ).outputs.output + ).get_output_vars( + input=get_value(input), + )["output"] def dequantize_linear( @@ -1219,11 +1226,15 @@ def dequantize_linear( block_size=AttrInt64(block_size, name="block_size"), ), _DequantizeLinear.Inputs( - x=x, - x_scale=x_scale, - x_zero_point=x_zero_point, + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), ), - ).outputs.y + ).get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + )["y"] def flatten( @@ -1270,9 +1281,11 @@ def flatten( axis=AttrInt64(axis, name="axis"), ), _Flatten.Inputs( - input=input, + input=unwrap_vars(input), ), - ).outputs.output + ).get_output_vars( + input=get_value(input), + )["output"] def group_normalization( @@ -1361,11 +1374,15 @@ def group_normalization( stash_type=AttrInt64(stash_type, name="stash_type"), ), _GroupNormalization.Inputs( - X=X, - scale=scale, - bias=bias, + X=unwrap_vars(X), + scale=unwrap_vars(scale), + bias=unwrap_vars(bias), ), - ).outputs.Y + ).get_output_vars( + X=get_value(X), + scale=get_value(scale), + bias=get_value(bias), + )["Y"] def identity( @@ -1396,9 +1413,11 @@ def identity( return _Identity( _Identity.Attributes(), _Identity.Inputs( - input=input, + input=unwrap_vars(input), ), - ).outputs.output + ).get_output_vars( + input=get_value(input), + )["output"] def if_( @@ -1461,10 +1480,12 @@ def if_( then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), ), _If.Inputs( - cond=cond, + cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), - ).outputs.outputs + ).get_output_vars( + cond=get_value(cond), + )["outputs"] def loop( @@ -1492,21 +1513,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond = - ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond = - true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -1653,12 +1674,16 @@ def loop( body=AttrGraph(_body_subgraph, name="body"), ), _Loop.Inputs( - M=M, - cond=cond, - v_initial=v_initial, + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, - ).outputs.v_final_and_scan_outputs + ).get_output_vars( + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), + )["v_final_and_scan_outputs"] def pad( @@ -1826,12 +1851,17 @@ def pad( mode=AttrString(mode, name="mode"), ), _Pad.Inputs( - data=data, - pads=pads, - constant_value=constant_value, - axes=axes, + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), ), - ).outputs.output + ).get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), + )["output"] def qlinear_matmul( @@ -1845,8 +1875,8 @@ def qlinear_matmul( y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like - `numpy.matmul `__. + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). For @@ -1910,16 +1940,25 @@ def qlinear_matmul( return _QLinearMatMul( _QLinearMatMul.Attributes(), _QLinearMatMul.Inputs( - a=a, - a_scale=a_scale, - a_zero_point=a_zero_point, - b=b, - b_scale=b_scale, - b_zero_point=b_zero_point, - y_scale=y_scale, - y_zero_point=y_zero_point, + a=unwrap_vars(a), + a_scale=unwrap_vars(a_scale), + a_zero_point=unwrap_vars(a_zero_point), + b=unwrap_vars(b), + b_scale=unwrap_vars(b_scale), + b_zero_point=unwrap_vars(b_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), ), - ).outputs.y + ).get_output_vars( + a=get_value(a), + a_scale=get_value(a_scale), + a_zero_point=get_value(a_zero_point), + b=get_value(b), + b_scale=get_value(b_scale), + b_zero_point=get_value(b_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + )["y"] def quantize_linear( @@ -1941,12 +1980,12 @@ def quantize_linear( Saturation is done according to: - - uint16: [0, 65535] - - int16: [-32768, 32767] - - uint8: [0, 255] - - int8: [-128, 127] - - uint4: [0, 15] - - int4: [-8, 7] + - uint16: [0, 65535] + - int16: [-32768, 32767] + - uint8: [0, 255] + - int8: [-128, 127] + - uint4: [0, 15] + - int4: [-8, 7] For ``(x / y_scale)``, it rounds to the nearest even. Refer to https://en.wikipedia.org/wiki/Rounding for details. @@ -1960,15 +1999,15 @@ def quantize_linear( shape of ``y_scale``. In all cases, ``y_zero_point`` must have the same shape as ``y_scale``. - - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. - - Per-axis quantization: The scale must be a 1-D tensor, with the length - of the quantization axis. For an input shape - ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D tensor - of length ``Di``. - - Blocked quantization: The scale's shape is identical to the input's - shape, except for one dimension, in which blocking is performed. Given - ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block size - ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. + - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. + - Per-axis quantization: The scale must be a 1-D tensor, with the + length of the quantization axis. For an input shape + ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D + tensor of length ``Di``. + - Blocked quantization: The scale's shape is identical to the input's + shape, except for one dimension, in which blocking is performed. + Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block + size ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. Parameters ========== @@ -1988,11 +2027,9 @@ def quantize_linear( axis Attribute. (Optional) The axis of the dequantizing dimension of the input tensor. - Used only for per-axis and blocked quantization. Negative value means + Used for per-axis and blocked quantization. Negative value means counting dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. When the rank of the input is 1, per-tensor - quantization is applied, rendering the axis unnecessary in this - scenario. + ``r = rank(input)``. block_size Attribute. (Optional) The size of the quantization block (number of times every @@ -2037,11 +2074,15 @@ def quantize_linear( saturate=AttrInt64(saturate, name="saturate"), ), _QuantizeLinear.Inputs( - x=x, - y_scale=y_scale, - y_zero_point=y_zero_point, + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), ), - ).outputs.y + ).get_output_vars( + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + )["y"] def reshape( @@ -2100,10 +2141,13 @@ def reshape( allowzero=AttrInt64(allowzero, name="allowzero"), ), _Reshape.Inputs( - data=data, - shape=shape, + data=unwrap_vars(data), + shape=unwrap_vars(shape), ), - ).outputs.reshaped + ).get_output_vars( + data=get_value(data), + shape=get_value(shape), + )["reshaped"] def scan( @@ -2343,10 +2387,12 @@ def scan( ), ), _Scan.Inputs( - initial_state_and_scan_inputs=initial_state_and_scan_inputs, + initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), - ).outputs.final_state_and_scan_outputs + ).get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + )["final_state_and_scan_outputs"] def shape( @@ -2431,9 +2477,11 @@ def shape( start=AttrInt64(start, name="start"), ), _Shape.Inputs( - data=data, + data=unwrap_vars(data), ), - ).outputs.shape + ).get_output_vars( + data=get_value(data), + )["shape"] def size( @@ -2466,9 +2514,11 @@ def size( return _Size( _Size.Attributes(), _Size.Inputs( - data=data, + data=unwrap_vars(data), ), - ).outputs.size + ).get_output_vars( + data=get_value(data), + )["size"] def squeeze( @@ -2509,10 +2559,13 @@ def squeeze( return _Squeeze( _Squeeze.Attributes(), _Squeeze.Inputs( - data=data, - axes=axes, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), - ).outputs.squeezed + ).get_output_vars( + data=get_value(data), + axes=get_value(axes), + )["squeezed"] def transpose( @@ -2554,9 +2607,11 @@ def transpose( perm=AttrInt64s.maybe(perm, name="perm"), ), _Transpose.Inputs( - data=data, + data=unwrap_vars(data), ), - ).outputs.transposed + ).get_output_vars( + data=get_value(data), + )["transposed"] def unsqueeze( @@ -2607,10 +2662,13 @@ def unsqueeze( return _Unsqueeze( _Unsqueeze.Attributes(), _Unsqueeze.Inputs( - data=data, - axes=axes, + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), - ).outputs.expanded + ).get_output_vars( + data=get_value(data), + axes=get_value(axes), + )["expanded"] def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: From bfaed791015998690aaa06c7744d01a82ba1da2a Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Mon, 4 Nov 2024 16:55:32 +0200 Subject: [PATCH 07/29] Fix more tests --- src/spox/_function.py | 28 +++++++++++++---------- src/spox/_node.py | 4 +--- src/spox/_public.py | 2 +- src/spox/_var.py | 39 ++++++++++++++++++++++++++++---- src/spox/opset/ai/onnx/ml/v3.py | 6 ++--- src/spox/opset/ai/onnx/v17.py | 22 +++++++++--------- src/spox/opset/ai/onnx/v20.py | 2 +- tests/test_function.py | 16 ++++++------- tests/test_value_propagation.py | 3 ++- tools/templates/construct.jinja2 | 2 +- 10 files changed, 78 insertions(+), 46 deletions(-) diff --git a/src/spox/_function.py b/src/spox/_function.py index 60377f3b..16a106b8 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -14,7 +14,7 @@ from ._internal_op import _InternalNode from ._node import Node, OpType from ._type_system import Type -from ._var import Var, VarInfo +from ._var import Var, VarInfo, unwrap_vars, wrap_vars if TYPE_CHECKING: from . import _graph @@ -42,7 +42,7 @@ class Function(_InternalNode): via the ``to_onnx_function`` method. """ - func_args: dict[str, Var] + func_args: dict[str, VarInfo] func_attrs: dict[str, _attributes.Attr] func_inputs: BaseInputs func_outputs: BaseOutputs @@ -64,10 +64,12 @@ def constructor(self, attrs, inputs): def infer_output_types(self) -> dict[str, Type]: from . import _graph - self.func_args = _graph.arguments_dict( + func_args_var = _graph.arguments_dict( **{name: var.type for name, var in self.inputs.get_vars().items()} ) + self.func_args = unwrap_vars(func_args_var) + self.func_attrs = {} for name, attr in self.attrs.get_fields().items(): if attr is None: @@ -78,9 +80,9 @@ def infer_output_types(self) -> dict[str, Type]: self.func_inputs = self.Inputs(**self.func_args) # type: ignore self.func_outputs = self.constructor(self.func_attrs, self.func_inputs) - self.func_graph = _graph.results(**self.func_outputs.get_vars()).with_arguments( - *self.func_args.values() - ) + self.func_graph = _graph.results( + **self.func_outputs._propagate_vars() + ).with_arguments(*func_args_var.values()) return { name: var.type @@ -157,7 +159,7 @@ def to_function(name: str, domain: str = "spox.function", *, _version: int = 0): The function must be deterministic in the performed operations, as otherwise an error will be raised at build due to inconsistent function bodies. - ``fun`` is assumed to take only VarInfo arguments and return an iterable of them. These will be used to generate the + ``fun`` is assumed to take only Var arguments and return an iterable of them. These will be used to generate the function class signature. Keep in mind that functions with the same name & domain will be merged together. @@ -172,13 +174,13 @@ def inner(fun: ConstructorT) -> ConstructorT: _num_outputs = None _cls = None - def get_num_outputs(*args: VarInfo) -> int: + def get_num_outputs(*args: Var) -> int: nonlocal _num_outputs if _num_outputs is None: _num_outputs = sum(1 for _ in fun(*args)) return _num_outputs - def init(*args: VarInfo): + def init(*args: Var): nonlocal _cls if _cls is not None: return _cls @@ -188,10 +190,12 @@ def init(*args: VarInfo): ) return _cls - def alt_fun(*args: VarInfo) -> Iterable[VarInfo]: + def alt_fun(*args: Var) -> Iterable[Var]: cls = init(*args) - return ( - cls(cls.Attributes(), cls.Inputs(*args)).outputs.get_fields().values() + return wrap_vars( + cls(cls.Attributes(), cls.Inputs(*unwrap_vars(args))) + .outputs.get_fields() + .values() ) return alt_fun # type: ignore diff --git a/src/spox/_node.py b/src/spox/_node.py index 8910604b..ce69b9b1 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -181,9 +181,7 @@ def signature(self) -> str: """Get a signature of this Node, including its inputs and attributes (but not outputs).""" def fmt_input(key, var): - return f"{key}: {var.type}" + ( - f" = {var._value}" if var._value is not None else "" - ) + return f"{key}: {var.type}" sign = ", ".join( fmt_input(key, var) for key, var in self.inputs.get_vars().items() diff --git a/src/spox/_public.py b/src/spox/_public.py index 736f6a28..20385fd3 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -49,7 +49,7 @@ def _temporary_renames(**kwargs: Var): pre: dict[Var, Optional[str]] = {} try: for name, arg in kwargs.items(): - pre[arg._var_info] = arg._var_info._name + pre[arg] = arg._var_info._name arg._var_info._rename(name) yield finally: diff --git a/src/spox/_var.py b/src/spox/_var.py index 751988f7..cb418d97 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -311,6 +311,35 @@ def __rxor__(self, other) -> "Var": T = TypeVar("T") +@overload +def wrap_vars(var_info: VarInfo) -> Var: ... + + +@overload +def wrap_vars(var_info: Optional[VarInfo]) -> Optional[Var]: ... + + +@overload +def wrap_vars(var_info: dict[T, VarInfo]) -> dict[T, Var]: ... # type: ignore[misc] + + +@overload +def wrap_vars(var_info: Union[Sequence[VarInfo], Iterable[VarInfo]]) -> list[Var]: ... + + +def wrap_vars(var_info): + if var_info is None: + return None + elif isinstance(var_info, VarInfo): + return Var(var_info) + elif isinstance(var_info, dict): + return {k: wrap_vars(v) for k, v in var_info.items()} + elif isinstance(var_info, (Sequence, Iterable)): + return [wrap_vars(v) for v in var_info] + else: + raise ValueError("Unsupported type for wrap_vars") + + @overload def unwrap_vars(var: Var) -> VarInfo: ... @@ -320,7 +349,7 @@ def unwrap_vars(var: Optional[Var]) -> Optional[VarInfo]: ... @overload -def unwrap_vars(var: dict[T, Var]) -> dict[T, VarInfo]: ... +def unwrap_vars(var: dict[T, Var]) -> dict[T, VarInfo]: ... # type: ignore[misc] @overload @@ -348,6 +377,10 @@ def get_value(var: Var) -> Optional[_value_prop.PropValue]: ... def get_value(var: Optional[Var]) -> Optional[_value_prop.PropValue]: ... +@overload +def get_value(var: dict[T, Var]) -> dict[T, Optional[_value_prop.PropValue]]: ... # type: ignore[misc] + + @overload def get_value( var: Union[Sequence[Var], Iterable[Var]], @@ -356,10 +389,6 @@ def get_value( ]: ... -@overload -def get_value(var: dict[T, Var]) -> dict[T, Optional[_value_prop.PropValue]]: ... - - def get_value(var): if var is None: return None diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index 939a3aab..a3b2395c 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -1217,7 +1217,7 @@ def linear_classifier( .get_output_vars( X=get_value(X), ) - ._unpack_to_any() + .values() ) @@ -1508,7 +1508,7 @@ def svmclassifier( .get_output_vars( X=get_value(X), ) - ._unpack_to_any() + .values() ) @@ -1833,7 +1833,7 @@ def tree_ensemble_classifier( .get_output_vars( X=get_value(X), ) - ._unpack_to_any() + .values() ) diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index c2be0920..11645310 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -4687,7 +4687,7 @@ def batch_normalization( input_mean=get_value(input_mean), input_var=get_value(input_var), ) - ._unpack_to_any() + .values() ) @@ -6383,7 +6383,7 @@ def dropout( ratio=get_value(ratio), training_mode=get_value(training_mode), ) - ._unpack_to_any() + .values() ) @@ -6464,7 +6464,7 @@ def dynamic_quantize_linear( .get_output_vars( x=get_value(x), ) - ._unpack_to_any() + .values() ) @@ -7113,7 +7113,7 @@ def gru( sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), ) - ._unpack_to_any() + .values() ) @@ -8707,7 +8707,7 @@ def lstm( initial_c=get_value(initial_c), P=get_value(P), ) - ._unpack_to_any() + .values() ) @@ -8812,7 +8812,7 @@ def layer_normalization( Scale=get_value(Scale), B=get_value(B), ) - ._unpack_to_any() + .values() ) @@ -9678,7 +9678,7 @@ def max_pool( .get_output_vars( X=get_value(X), ) - ._unpack_to_any() + .values() ) @@ -11616,7 +11616,7 @@ def rnn( sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), ) - ._unpack_to_any() + .values() ) @@ -14678,7 +14678,7 @@ def softmax_cross_entropy_loss( labels=get_value(labels), weights=get_value(weights), ) - ._unpack_to_any() + .values() ) @@ -15571,7 +15571,7 @@ def top_k( X=get_value(X), K=get_value(K), ) - ._unpack_to_any() + .values() ) @@ -15869,7 +15869,7 @@ def unique( .get_output_vars( X=get_value(X), ) - ._unpack_to_any() + .values() ) diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 014763f8..e9bdebf9 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -1550,7 +1550,7 @@ def string_split( .get_output_vars( X=get_value(X), ) - ._unpack_to_any() + .values() ) diff --git a/tests/test_function.py b/tests/test_function.py index 83273766..7e78ef2e 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -56,8 +56,8 @@ def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: attrs["shift_outer"], outer_name="shift_outer", name="value_float" ) # type: ignore ) - x = inputs.X - return self.Outputs(op.add(op.mul(a, x), b)) + x = Var(inputs.X) + return self.Outputs(op.add(op.mul(a, x), b)._var_info) def linear_inner( x: Var, a: Union[float, _Ref[float]], b: Union[float, _Ref[float]] @@ -98,10 +98,10 @@ class Outputs(BaseOutputs): def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: return self.Outputs( linear( - inputs.X, + Var(inputs.X), _Ref(attrs["slope1"], outer_name="slope1", name="slope_outer"), _Ref(attrs["shift1"], outer_name="shift1", name="shift_outer"), - ) + )._var_info ) def linear_inner( @@ -142,7 +142,7 @@ class Outputs(BaseOutputs): outputs: Outputs def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: - x = inputs.X + x = Var(inputs.X) a = op.mul( linear( x, @@ -165,7 +165,7 @@ def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: ), ) y = op.add(a, b) - return self.Outputs(y) + return self.Outputs(y._var_info) def cubic_inner(x: Var, a3: float, a2: float, a1: float, a0: float) -> Var: return CubicFunction( @@ -175,8 +175,8 @@ def cubic_inner(x: Var, a3: float, a2: float, a1: float, a0: float) -> Var: a1=AttrFloat32(a1, name="a1"), a0=AttrFloat32(a0, name="a0"), ), - CubicFunction.Inputs(X=x), - ).outputs.Y + CubicFunction.Inputs(X=x._var_info), + ).get_output_vars()["Y"] return cubic_inner diff --git a/tests/test_value_propagation.py b/tests/test_value_propagation.py index c26d4de1..30cc678a 100644 --- a/tests/test_value_propagation.py +++ b/tests/test_value_propagation.py @@ -12,6 +12,7 @@ from spox import Var, _type_system from spox._graph import arguments, results from spox._shape import Shape +from spox._var import VarInfo from spox._value_prop import ORTValue, PropValue @@ -27,7 +28,7 @@ def value_prop_backend(request): def dummy_var(typ=None, value=None): """Function for creating a ``var`` without an operator but with a type and value.""" - return Var(None, typ, value) # type: ignore + return Var(VarInfo(None, typ), value) # type: ignore def assert_equal_value(var: Var, expected: ORTValue): diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index 514833c8..f0225a51 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -43,5 +43,5 @@ endfor %} ){% if schema.outputs | length <= 1 %}["{{ schema.outputs[0].name }}"]{% -else %}._unpack_to_any(){% +else %}.values(){% endif %} From 49e366cf786f274d591bb6f00ff738b800805232 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Mon, 4 Nov 2024 19:08:45 +0200 Subject: [PATCH 08/29] Add some proper typing --- src/spox/_fields.py | 87 +- src/spox/_graph.py | 52 +- src/spox/_internal_op.py | 8 +- src/spox/_node.py | 6 +- src/spox/_public.py | 14 +- src/spox/opset/ai/onnx/ml/v3.py | 529 ++-- src/spox/opset/ai/onnx/ml/v4.py | 46 +- src/spox/opset/ai/onnx/ml/v5.py | 67 +- src/spox/opset/ai/onnx/v17.py | 4420 +++++++++++++++++------------- src/spox/opset/ai/onnx/v18.py | 769 +++--- src/spox/opset/ai/onnx/v19.py | 561 ++-- src/spox/opset/ai/onnx/v20.py | 326 ++- src/spox/opset/ai/onnx/v21.py | 598 ++-- tests/test_adapt.py | 12 +- tests/test_custom_operator.py | 8 +- tests/test_function.py | 57 +- tests/test_value_propagation.py | 2 +- tools/templates/construct.jinja2 | 4 +- 18 files changed, 4374 insertions(+), 3192 deletions(-) diff --git a/src/spox/_fields.py b/src/spox/_fields.py index 5bd727be..1286b55e 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -34,6 +34,54 @@ class VarFieldKind(enum.Enum): VARIADIC = 2 +class BaseVars: + def _unpack_to_any(self) -> Any: + """Unpack the stored fields into a tuple of appropriate length, typed as Any.""" + return tuple(self.__dict__.values()) + + def _flatten(self) -> Iterable[tuple[str, Optional[Var]]]: + """Iterate over the pairs of names and values of fields in this object.""" + for key, value in self.__dict__.items(): + if value is None or isinstance(value, Var): + yield key, value + else: + yield from ((f"{key}_{i}", v) for i, v in enumerate(value)) + + def get_vars(self) -> dict[str, Var]: + """Return a flat mapping by name of all the VarInfos in this object.""" + return {key: var for key, var in self._flatten() if var is not None} + + +class BaseVarsMeta(type): + def __new__(cls, name, bases, namespace): + new_cls = super().__new__(cls, name, bases, namespace) + + if bases and "__annotations__" in namespace: + annotations: dict[str, Any] = {} + for name, typ in namespace["__annotations__"].items(): + if typ == VarInfo: + annotations[name] = Var + elif typ == Optional[VarInfo]: + annotations[name] = Optional[Var] + elif typ == Sequence[VarInfo]: + annotations[name] = Sequence[Var] + + vars_cls = dataclass( + type( + "Vars", + ( + BaseVars, + object, + ), + {"__annotations__": annotations}, + ) + ) # type: ignore + + setattr(new_cls, "Vars", vars_cls) + + return new_cls + + @dataclass class BaseVarInfos(BaseFields): def __post_init__(self): @@ -110,12 +158,45 @@ def fully_typed(self) -> bool: @dataclass -class BaseInputs(BaseVarInfos): - pass +class BaseInputs(BaseVarInfos, metaclass=BaseVarsMeta): + @dataclass + class Vars(BaseVars): + pass + + def vars(self, prop_values) -> Vars: + vars_structure: dict[str, Union[Var, Sequence[Var]]] = {} + + for field in dataclasses.fields(self): + field_type = self._get_field_type(field) + field_value = getattr(self, field.name) + + if field_type == VarFieldKind.SINGLE: + vars_structure[field.name] = Var(field_value, prop_values[field.name]) + + elif ( + field_type == VarFieldKind.OPTIONAL + and prop_values.get(field.name, None) is not None + ): + vars_structure[field.name] = Var(field_value, prop_values[field.name]) + + elif field_type == VarFieldKind.VARIADIC: + vars = [] + + for i, var_info in enumerate(field_value): + var_value = prop_values.get(f"{field.name}_{i}", None) + vars.append(Var(var_info, var_value)) + + vars_structure[field.name] = vars + + return self.Vars(**vars_structure) @dataclass -class BaseOutputs(BaseVarInfos): +class BaseOutputs(BaseVarInfos, metaclass=BaseVarsMeta): + @dataclass + class Vars(BaseVars): + pass + def _propagate_vars( self, prop_values={}, diff --git a/src/spox/_graph.py b/src/spox/_graph.py index 0470b289..f7a6999b 100644 --- a/src/spox/_graph.py +++ b/src/spox/_graph.py @@ -43,24 +43,32 @@ def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var for name, info in kwargs.items(): attr_name = AttrString(value=name, name="dummy") if isinstance(info, Type): - result[name] = Argument( - Argument.Attributes( - name=attr_name, - type=AttrType(value=info, name="dummy"), - default=None, - ), - BaseInputs(), - ).get_output_vars()["arg"] + result[name] = ( + Argument( + Argument.Attributes( + name=attr_name, + type=AttrType(value=info, name="dummy"), + default=None, + ), + BaseInputs(), + ) + .get_output_vars() + .arg + ) elif isinstance(info, np.ndarray): ty = Tensor(info.dtype, info.shape) - result[name] = Argument( - Argument.Attributes( - name=attr_name, - type=AttrType(value=ty, name="dummy"), - default=AttrTensor(value=info, name="dummy"), - ), - BaseInputs(), - ).get_output_vars()["arg"] + result[name] = ( + Argument( + Argument.Attributes( + name=attr_name, + type=AttrType(value=ty, name="dummy"), + default=AttrTensor(value=info, name="dummy"), + ), + BaseInputs(), + ) + .get_output_vars() + .arg + ) else: raise TypeError(f"Cannot construct argument from {type(info)}.") return result @@ -110,10 +118,14 @@ def initializer(arr: np.ndarray) -> Var: ------- Var which is always equal to the respective value provided by `arr`. """ - return _Initializer( - _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), - BaseInputs(), - ).get_output_vars()["arg"] + return ( + _Initializer( + _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), + BaseInputs(), + ) + .get_output_vars() + .arg + ) @dataclass(frozen=True, eq=False) diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index f734aff1..835c451b 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -213,9 +213,11 @@ def intros(*args: Var) -> Sequence[Var]: Sequence[Var] Vars of the same value as ``args``, but with a shared dependency. """ - return _Introduce( - None, _Introduce.Inputs(unwrap_vars(args)), out_variadic=len(args) - ).get_output_vars()["outputs"] + return ( + _Introduce(None, _Introduce.Inputs(unwrap_vars(args)), out_variadic=len(args)) + .get_output_vars() + .outputs + ) def intro(*args: Var) -> Var: diff --git a/src/spox/_node.py b/src/spox/_node.py index ce69b9b1..85d0ba31 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -236,8 +236,10 @@ def inference(self, infer_types: bool = True): def get_output_vars(self, flatten_variadic=False, **initializers): # After typing everything, try to get values for outputs out_values = self.propagate_values(initializers) - return self.outputs._propagate_vars( - out_values, flatten_variadic=flatten_variadic + return type(self.outputs).Vars( + **self.outputs._propagate_vars( + out_values, flatten_variadic=flatten_variadic + ) ) def validate_types(self) -> None: diff --git a/src/spox/_public.py b/src/spox/_public.py index 20385fd3..a3b77dab 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -35,9 +35,13 @@ def argument(typ: Type) -> Var: An unnamed argument variable of given type that may be used as a model input to build a graph. """ - return _internal_op.Argument( - _internal_op.Argument.Attributes(type=AttrType(typ, "dummy"), default=None) - ).get_output_vars()["arg"] + return ( + _internal_op.Argument( + _internal_op.Argument.Attributes(type=AttrType(typ, "dummy"), default=None) + ) + .get_output_vars() + .arg + ) @contextlib.contextmanager @@ -303,9 +307,7 @@ def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: model=model, ) - return dict( - zip(out_names, node.get_output_vars(flatten_variadic=True).values()) - ) + return dict(zip(out_names, node.get_output_vars().get_vars().values())) return inline_inner diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index a3b2395c..c80ce52d 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -662,16 +662,20 @@ def array_feature_extractor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - return _ArrayFeatureExtractor( - _ArrayFeatureExtractor.Attributes(), - _ArrayFeatureExtractor.Inputs( - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ).get_output_vars( - X=get_value(X), - Y=get_value(Y), - )["Z"] + return ( + _ArrayFeatureExtractor( + _ArrayFeatureExtractor.Attributes(), + _ArrayFeatureExtractor.Inputs( + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + X=get_value(X), + Y=get_value(Y), + ) + .Z + ) def binarizer( @@ -705,16 +709,20 @@ def binarizer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _Binarizer( - _Binarizer.Attributes( - threshold=AttrFloat32(threshold, name="threshold"), - ), - _Binarizer.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Binarizer( + _Binarizer.Attributes( + threshold=AttrFloat32(threshold, name="threshold"), + ), + _Binarizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def cast_map( @@ -764,18 +772,22 @@ def cast_map( - T1: `map(int64,tensor(float))`, `map(int64,tensor(string))` - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return _CastMap( - _CastMap.Attributes( - cast_to=AttrString(cast_to, name="cast_to"), - map_form=AttrString(map_form, name="map_form"), - max_map=AttrInt64(max_map, name="max_map"), - ), - _CastMap.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _CastMap( + _CastMap.Attributes( + cast_to=AttrString(cast_to, name="cast_to"), + map_form=AttrString(map_form, name="map_form"), + max_map=AttrInt64(max_map, name="max_map"), + ), + _CastMap.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def category_mapper( @@ -833,19 +845,23 @@ def category_mapper( - T1: `tensor(int64)`, `tensor(string)` - T2: `tensor(int64)`, `tensor(string)` """ - return _CategoryMapper( - _CategoryMapper.Attributes( - cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), - cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - ), - _CategoryMapper.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _CategoryMapper( + _CategoryMapper.Attributes( + cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), + cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + ), + _CategoryMapper.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def dict_vectorizer( @@ -898,21 +914,25 @@ def dict_vectorizer( - T1: `map(int64,tensor(double))`, `map(int64,tensor(float))`, `map(int64,tensor(string))`, `map(string,tensor(double))`, `map(string,tensor(float))`, `map(string,tensor(int64))` - T2: `tensor(double)`, `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return _DictVectorizer( - _DictVectorizer.Attributes( - int64_vocabulary=AttrInt64s.maybe( - int64_vocabulary, name="int64_vocabulary" + return ( + _DictVectorizer( + _DictVectorizer.Attributes( + int64_vocabulary=AttrInt64s.maybe( + int64_vocabulary, name="int64_vocabulary" + ), + string_vocabulary=AttrStrings.maybe( + string_vocabulary, name="string_vocabulary" + ), ), - string_vocabulary=AttrStrings.maybe( - string_vocabulary, name="string_vocabulary" + _DictVectorizer.Inputs( + X=unwrap_vars(X), ), - ), - _DictVectorizer.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def feature_vectorizer( @@ -949,16 +969,22 @@ def feature_vectorizer( Type constraints: - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _FeatureVectorizer( - _FeatureVectorizer.Attributes( - inputdimensions=AttrInt64s.maybe(inputdimensions, name="inputdimensions"), - ), - _FeatureVectorizer.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _FeatureVectorizer( + _FeatureVectorizer.Attributes( + inputdimensions=AttrInt64s.maybe( + inputdimensions, name="inputdimensions" + ), + ), + _FeatureVectorizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def imputer( @@ -1016,27 +1042,31 @@ def imputer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _Imputer( - _Imputer.Attributes( - imputed_value_floats=AttrFloat32s.maybe( - imputed_value_floats, name="imputed_value_floats" - ), - imputed_value_int64s=AttrInt64s.maybe( - imputed_value_int64s, name="imputed_value_int64s" - ), - replaced_value_float=AttrFloat32( - replaced_value_float, name="replaced_value_float" + return ( + _Imputer( + _Imputer.Attributes( + imputed_value_floats=AttrFloat32s.maybe( + imputed_value_floats, name="imputed_value_floats" + ), + imputed_value_int64s=AttrInt64s.maybe( + imputed_value_int64s, name="imputed_value_int64s" + ), + replaced_value_float=AttrFloat32( + replaced_value_float, name="replaced_value_float" + ), + replaced_value_int64=AttrInt64( + replaced_value_int64, name="replaced_value_int64" + ), ), - replaced_value_int64=AttrInt64( - replaced_value_int64, name="replaced_value_int64" + _Imputer.Inputs( + X=unwrap_vars(X), ), - ), - _Imputer.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def label_encoder( @@ -1119,24 +1149,28 @@ def label_encoder( - T1: `tensor(float)`, `tensor(int64)`, `tensor(string)` - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return _LabelEncoder( - _LabelEncoder.Attributes( - default_float=AttrFloat32(default_float, name="default_float"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), - keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), - keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), - values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), - values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), - values_strings=AttrStrings.maybe(values_strings, name="values_strings"), - ), - _LabelEncoder.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _LabelEncoder( + _LabelEncoder.Attributes( + default_float=AttrFloat32(default_float, name="default_float"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), + keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), + keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), + values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), + values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), + values_strings=AttrStrings.maybe(values_strings, name="values_strings"), + ), + _LabelEncoder.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def linear_classifier( @@ -1217,7 +1251,7 @@ def linear_classifier( .get_output_vars( X=get_value(X), ) - .values() + ._unpack_to_any() ) @@ -1270,19 +1304,23 @@ def linear_regressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _LinearRegressor( - _LinearRegressor.Attributes( - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), - post_transform=AttrString(post_transform, name="post_transform"), - targets=AttrInt64(targets, name="targets"), - ), - _LinearRegressor.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _LinearRegressor( + _LinearRegressor.Attributes( + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), + post_transform=AttrString(post_transform, name="post_transform"), + targets=AttrInt64(targets, name="targets"), + ), + _LinearRegressor.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def normalizer( @@ -1321,16 +1359,20 @@ def normalizer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _Normalizer( - _Normalizer.Attributes( - norm=AttrString(norm, name="norm"), - ), - _Normalizer.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Normalizer( + _Normalizer.Attributes( + norm=AttrString(norm, name="norm"), + ), + _Normalizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def one_hot_encoder( @@ -1382,18 +1424,22 @@ def one_hot_encoder( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - return _OneHotEncoder( - _OneHotEncoder.Attributes( - cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), - cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), - zeros=AttrInt64(zeros, name="zeros"), - ), - _OneHotEncoder.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _OneHotEncoder( + _OneHotEncoder.Attributes( + cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), + cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), + zeros=AttrInt64(zeros, name="zeros"), + ), + _OneHotEncoder.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def svmclassifier( @@ -1508,7 +1554,7 @@ def svmclassifier( .get_output_vars( X=get_value(X), ) - .values() + ._unpack_to_any() ) @@ -1573,23 +1619,29 @@ def svmregressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _SVMRegressor( - _SVMRegressor.Attributes( - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), - kernel_type=AttrString(kernel_type, name="kernel_type"), - n_supports=AttrInt64(n_supports, name="n_supports"), - one_class=AttrInt64(one_class, name="one_class"), - post_transform=AttrString(post_transform, name="post_transform"), - rho=AttrFloat32s.maybe(rho, name="rho"), - support_vectors=AttrFloat32s.maybe(support_vectors, name="support_vectors"), - ), - _SVMRegressor.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _SVMRegressor( + _SVMRegressor.Attributes( + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), + kernel_type=AttrString(kernel_type, name="kernel_type"), + n_supports=AttrInt64(n_supports, name="n_supports"), + one_class=AttrInt64(one_class, name="one_class"), + post_transform=AttrString(post_transform, name="post_transform"), + rho=AttrFloat32s.maybe(rho, name="rho"), + support_vectors=AttrFloat32s.maybe( + support_vectors, name="support_vectors" + ), + ), + _SVMRegressor.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def scaler( @@ -1631,17 +1683,21 @@ def scaler( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _Scaler( - _Scaler.Attributes( - offset=AttrFloat32s.maybe(offset, name="offset"), - scale=AttrFloat32s.maybe(scale, name="scale"), - ), - _Scaler.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Scaler( + _Scaler.Attributes( + offset=AttrFloat32s.maybe(offset, name="offset"), + scale=AttrFloat32s.maybe(scale, name="scale"), + ), + _Scaler.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def tree_ensemble_classifier( @@ -1833,7 +1889,7 @@ def tree_ensemble_classifier( .get_output_vars( X=get_value(X), ) - .values() + ._unpack_to_any() ) @@ -1969,54 +2025,63 @@ def tree_ensemble_regressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _TreeEnsembleRegressor( - _TreeEnsembleRegressor.Attributes( - aggregate_function=AttrString( - aggregate_function, name="aggregate_function" - ), - base_values=AttrFloat32s.maybe(base_values, name="base_values"), - base_values_as_tensor=AttrTensor.maybe( - base_values_as_tensor, name="base_values_as_tensor" - ), - n_targets=AttrInt64.maybe(n_targets, name="n_targets"), - nodes_falsenodeids=AttrInt64s.maybe( - nodes_falsenodeids, name="nodes_falsenodeids" - ), - nodes_featureids=AttrInt64s.maybe( - nodes_featureids, name="nodes_featureids" - ), - nodes_hitrates=AttrFloat32s.maybe(nodes_hitrates, name="nodes_hitrates"), - nodes_hitrates_as_tensor=AttrTensor.maybe( - nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor" - ), - nodes_missing_value_tracks_true=AttrInt64s.maybe( - nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true" - ), - nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), - nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), - nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), - nodes_truenodeids=AttrInt64s.maybe( - nodes_truenodeids, name="nodes_truenodeids" - ), - nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), - nodes_values_as_tensor=AttrTensor.maybe( - nodes_values_as_tensor, name="nodes_values_as_tensor" + return ( + _TreeEnsembleRegressor( + _TreeEnsembleRegressor.Attributes( + aggregate_function=AttrString( + aggregate_function, name="aggregate_function" + ), + base_values=AttrFloat32s.maybe(base_values, name="base_values"), + base_values_as_tensor=AttrTensor.maybe( + base_values_as_tensor, name="base_values_as_tensor" + ), + n_targets=AttrInt64.maybe(n_targets, name="n_targets"), + nodes_falsenodeids=AttrInt64s.maybe( + nodes_falsenodeids, name="nodes_falsenodeids" + ), + nodes_featureids=AttrInt64s.maybe( + nodes_featureids, name="nodes_featureids" + ), + nodes_hitrates=AttrFloat32s.maybe( + nodes_hitrates, name="nodes_hitrates" + ), + nodes_hitrates_as_tensor=AttrTensor.maybe( + nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor" + ), + nodes_missing_value_tracks_true=AttrInt64s.maybe( + nodes_missing_value_tracks_true, + name="nodes_missing_value_tracks_true", + ), + nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), + nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), + nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), + nodes_truenodeids=AttrInt64s.maybe( + nodes_truenodeids, name="nodes_truenodeids" + ), + nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), + nodes_values_as_tensor=AttrTensor.maybe( + nodes_values_as_tensor, name="nodes_values_as_tensor" + ), + post_transform=AttrString(post_transform, name="post_transform"), + target_ids=AttrInt64s.maybe(target_ids, name="target_ids"), + target_nodeids=AttrInt64s.maybe(target_nodeids, name="target_nodeids"), + target_treeids=AttrInt64s.maybe(target_treeids, name="target_treeids"), + target_weights=AttrFloat32s.maybe( + target_weights, name="target_weights" + ), + target_weights_as_tensor=AttrTensor.maybe( + target_weights_as_tensor, name="target_weights_as_tensor" + ), ), - post_transform=AttrString(post_transform, name="post_transform"), - target_ids=AttrInt64s.maybe(target_ids, name="target_ids"), - target_nodeids=AttrInt64s.maybe(target_nodeids, name="target_nodeids"), - target_treeids=AttrInt64s.maybe(target_treeids, name="target_treeids"), - target_weights=AttrFloat32s.maybe(target_weights, name="target_weights"), - target_weights_as_tensor=AttrTensor.maybe( - target_weights_as_tensor, name="target_weights_as_tensor" + _TreeEnsembleRegressor.Inputs( + X=unwrap_vars(X), ), - ), - _TreeEnsembleRegressor.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def zip_map( @@ -2059,21 +2124,25 @@ def zip_map( Type constraints: - T: `seq(map(int64,tensor(float)))`, `seq(map(string,tensor(float)))` """ - return _ZipMap( - _ZipMap.Attributes( - classlabels_int64s=AttrInt64s.maybe( - classlabels_int64s, name="classlabels_int64s" + return ( + _ZipMap( + _ZipMap.Attributes( + classlabels_int64s=AttrInt64s.maybe( + classlabels_int64s, name="classlabels_int64s" + ), + classlabels_strings=AttrStrings.maybe( + classlabels_strings, name="classlabels_strings" + ), ), - classlabels_strings=AttrStrings.maybe( - classlabels_strings, name="classlabels_strings" + _ZipMap.Inputs( + X=unwrap_vars(X), ), - ), - _ZipMap.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Z"] + ) + .get_output_vars( + X=get_value(X), + ) + .Z + ) _OPERATORS = { diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index c9247b26..2e4871c8 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -191,27 +191,31 @@ def label_encoder( - T1: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` - T2: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - return _LabelEncoder( - _LabelEncoder.Attributes( - default_float=AttrFloat32(default_float, name="default_float"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - default_tensor=AttrTensor.maybe(default_tensor, name="default_tensor"), - keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), - keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), - keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), - keys_tensor=AttrTensor.maybe(keys_tensor, name="keys_tensor"), - values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), - values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), - values_strings=AttrStrings.maybe(values_strings, name="values_strings"), - values_tensor=AttrTensor.maybe(values_tensor, name="values_tensor"), - ), - _LabelEncoder.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _LabelEncoder( + _LabelEncoder.Attributes( + default_float=AttrFloat32(default_float, name="default_float"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + default_tensor=AttrTensor.maybe(default_tensor, name="default_tensor"), + keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), + keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), + keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), + keys_tensor=AttrTensor.maybe(keys_tensor, name="keys_tensor"), + values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), + values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), + values_strings=AttrStrings.maybe(values_strings, name="values_strings"), + values_tensor=AttrTensor.maybe(values_tensor, name="values_tensor"), + ), + _LabelEncoder.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) _OPERATORS = { diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index 6843a8ce..c35f6c9a 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -224,37 +224,46 @@ def tree_ensemble( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _TreeEnsemble( - _TreeEnsemble.Attributes( - aggregate_function=AttrInt64(aggregate_function, name="aggregate_function"), - leaf_targetids=AttrInt64s(leaf_targetids, name="leaf_targetids"), - leaf_weights=AttrTensor(leaf_weights, name="leaf_weights"), - membership_values=AttrTensor.maybe( - membership_values, name="membership_values" + return ( + _TreeEnsemble( + _TreeEnsemble.Attributes( + aggregate_function=AttrInt64( + aggregate_function, name="aggregate_function" + ), + leaf_targetids=AttrInt64s(leaf_targetids, name="leaf_targetids"), + leaf_weights=AttrTensor(leaf_weights, name="leaf_weights"), + membership_values=AttrTensor.maybe( + membership_values, name="membership_values" + ), + n_targets=AttrInt64.maybe(n_targets, name="n_targets"), + nodes_falseleafs=AttrInt64s(nodes_falseleafs, name="nodes_falseleafs"), + nodes_falsenodeids=AttrInt64s( + nodes_falsenodeids, name="nodes_falsenodeids" + ), + nodes_featureids=AttrInt64s(nodes_featureids, name="nodes_featureids"), + nodes_hitrates=AttrTensor.maybe(nodes_hitrates, name="nodes_hitrates"), + nodes_missing_value_tracks_true=AttrInt64s.maybe( + nodes_missing_value_tracks_true, + name="nodes_missing_value_tracks_true", + ), + nodes_modes=AttrTensor(nodes_modes, name="nodes_modes"), + nodes_splits=AttrTensor(nodes_splits, name="nodes_splits"), + nodes_trueleafs=AttrInt64s(nodes_trueleafs, name="nodes_trueleafs"), + nodes_truenodeids=AttrInt64s( + nodes_truenodeids, name="nodes_truenodeids" + ), + post_transform=AttrInt64(post_transform, name="post_transform"), + tree_roots=AttrInt64s(tree_roots, name="tree_roots"), ), - n_targets=AttrInt64.maybe(n_targets, name="n_targets"), - nodes_falseleafs=AttrInt64s(nodes_falseleafs, name="nodes_falseleafs"), - nodes_falsenodeids=AttrInt64s( - nodes_falsenodeids, name="nodes_falsenodeids" + _TreeEnsemble.Inputs( + X=unwrap_vars(X), ), - nodes_featureids=AttrInt64s(nodes_featureids, name="nodes_featureids"), - nodes_hitrates=AttrTensor.maybe(nodes_hitrates, name="nodes_hitrates"), - nodes_missing_value_tracks_true=AttrInt64s.maybe( - nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true" - ), - nodes_modes=AttrTensor(nodes_modes, name="nodes_modes"), - nodes_splits=AttrTensor(nodes_splits, name="nodes_splits"), - nodes_trueleafs=AttrInt64s(nodes_trueleafs, name="nodes_trueleafs"), - nodes_truenodeids=AttrInt64s(nodes_truenodeids, name="nodes_truenodeids"), - post_transform=AttrInt64(post_transform, name="post_transform"), - tree_roots=AttrInt64s(tree_roots, name="tree_roots"), - ), - _TreeEnsemble.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) _OPERATORS = { diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 11645310..cc4ffc60 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -3958,14 +3958,18 @@ def abs( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Abs( - _Abs.Attributes(), - _Abs.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Abs( + _Abs.Attributes(), + _Abs.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def acos( @@ -3994,14 +3998,18 @@ def acos( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Acos( - _Acos.Attributes(), - _Acos.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Acos( + _Acos.Attributes(), + _Acos.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def acosh( @@ -4031,14 +4039,18 @@ def acosh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Acosh( - _Acosh.Attributes(), - _Acosh.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Acosh( + _Acosh.Attributes(), + _Acosh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def add( @@ -4078,16 +4090,20 @@ def add( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Add( - _Add.Attributes(), - _Add.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Add( + _Add.Attributes(), + _Add.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def and_( @@ -4126,16 +4142,20 @@ def and_( - T: `tensor(bool)` - T1: `tensor(bool)` """ - return _And( - _And.Attributes(), - _And.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _And( + _And.Attributes(), + _And.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def arg_max( @@ -4186,18 +4206,24 @@ def arg_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ArgMax( - _ArgMax.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - select_last_index=AttrInt64(select_last_index, name="select_last_index"), - ), - _ArgMax.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ArgMax( + _ArgMax.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + select_last_index=AttrInt64( + select_last_index, name="select_last_index" + ), + ), + _ArgMax.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def arg_min( @@ -4248,18 +4274,24 @@ def arg_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ArgMin( - _ArgMin.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - select_last_index=AttrInt64(select_last_index, name="select_last_index"), - ), - _ArgMin.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ArgMin( + _ArgMin.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + select_last_index=AttrInt64( + select_last_index, name="select_last_index" + ), + ), + _ArgMin.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def asin( @@ -4288,14 +4320,18 @@ def asin( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Asin( - _Asin.Attributes(), - _Asin.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Asin( + _Asin.Attributes(), + _Asin.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def asinh( @@ -4324,14 +4360,18 @@ def asinh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Asinh( - _Asinh.Attributes(), - _Asinh.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Asinh( + _Asinh.Attributes(), + _Asinh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def atan( @@ -4360,14 +4400,18 @@ def atan( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Atan( - _Atan.Attributes(), - _Atan.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Atan( + _Atan.Attributes(), + _Atan.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def atanh( @@ -4397,14 +4441,18 @@ def atanh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Atanh( - _Atanh.Attributes(), - _Atanh.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Atanh( + _Atanh.Attributes(), + _Atanh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def average_pool( @@ -4528,21 +4576,27 @@ def average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _AveragePool( - _AveragePool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - count_include_pad=AttrInt64(count_include_pad, name="count_include_pad"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _AveragePool.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _AveragePool( + _AveragePool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + count_include_pad=AttrInt64( + count_include_pad, name="count_include_pad" + ), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _AveragePool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def batch_normalization( @@ -4687,7 +4741,7 @@ def batch_normalization( input_mean=get_value(input_mean), input_var=get_value(input_var), ) - .values() + ._unpack_to_any() ) @@ -4736,17 +4790,21 @@ def bernoulli( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Bernoulli( - _Bernoulli.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), - _Bernoulli.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Bernoulli( + _Bernoulli.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), + _Bernoulli.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def bit_shift( @@ -4799,18 +4857,22 @@ def bit_shift( Type constraints: - T: `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitShift( - _BitShift.Attributes( - direction=AttrString(direction, name="direction"), - ), - _BitShift.Inputs( - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ).get_output_vars( - X=get_value(X), - Y=get_value(Y), - )["Z"] + return ( + _BitShift( + _BitShift.Attributes( + direction=AttrString(direction, name="direction"), + ), + _BitShift.Inputs( + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + X=get_value(X), + Y=get_value(Y), + ) + .Z + ) def blackman_window( @@ -4854,17 +4916,21 @@ def blackman_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BlackmanWindow( - _BlackmanWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), - _BlackmanWindow.Inputs( - size=unwrap_vars(size), - ), - ).get_output_vars( - size=get_value(size), - )["output"] + return ( + _BlackmanWindow( + _BlackmanWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), + _BlackmanWindow.Inputs( + size=unwrap_vars(size), + ), + ) + .get_output_vars( + size=get_value(size), + ) + .output + ) def cast( @@ -4949,16 +5015,20 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Cast( - _Cast.Attributes( - to=AttrDtype(to, name="to"), - ), - _Cast.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Cast( + _Cast.Attributes( + to=AttrDtype(to, name="to"), + ), + _Cast.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def cast_like( @@ -4995,16 +5065,20 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _CastLike( - _CastLike.Attributes(), - _CastLike.Inputs( - input=unwrap_vars(input), - target_type=unwrap_vars(target_type), - ), - ).get_output_vars( - input=get_value(input), - target_type=get_value(target_type), - )["output"] + return ( + _CastLike( + _CastLike.Attributes(), + _CastLike.Inputs( + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), + ), + ) + .get_output_vars( + input=get_value(input), + target_type=get_value(target_type), + ) + .output + ) def ceil( @@ -5035,14 +5109,18 @@ def ceil( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Ceil( - _Ceil.Attributes(), - _Ceil.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Ceil( + _Ceil.Attributes(), + _Ceil.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def celu( @@ -5081,16 +5159,20 @@ def celu( Type constraints: - T: `tensor(float)` """ - return _Celu( - _Celu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), - _Celu.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Celu( + _Celu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), + _Celu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def clip( @@ -5130,18 +5212,22 @@ def clip( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Clip( - _Clip.Attributes(), - _Clip.Inputs( - input=unwrap_vars(input), - min=unwrap_vars(min), - max=unwrap_vars(max), - ), - ).get_output_vars( - input=get_value(input), - min=get_value(min), - max=get_value(max), - )["output"] + return ( + _Clip( + _Clip.Attributes(), + _Clip.Inputs( + input=unwrap_vars(input), + min=unwrap_vars(min), + max=unwrap_vars(max), + ), + ) + .get_output_vars( + input=get_value(input), + min=get_value(min), + max=get_value(max), + ) + .output + ) def compress( @@ -5190,18 +5276,22 @@ def compress( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - return _Compress( - _Compress.Attributes( - axis=AttrInt64.maybe(axis, name="axis"), - ), - _Compress.Inputs( - input=unwrap_vars(input), - condition=unwrap_vars(condition), - ), - ).get_output_vars( - input=get_value(input), - condition=get_value(condition), - )["output"] + return ( + _Compress( + _Compress.Attributes( + axis=AttrInt64.maybe(axis, name="axis"), + ), + _Compress.Inputs( + input=unwrap_vars(input), + condition=unwrap_vars(condition), + ), + ) + .get_output_vars( + input=get_value(input), + condition=get_value(condition), + ) + .output + ) def concat( @@ -5237,16 +5327,20 @@ def concat( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Concat( - _Concat.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Concat.Inputs( - inputs=unwrap_vars(inputs), - ), - ).get_output_vars( - inputs=get_value(inputs), - )["concat_result"] + return ( + _Concat( + _Concat.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Concat.Inputs( + inputs=unwrap_vars(inputs), + ), + ) + .get_output_vars( + inputs=get_value(inputs), + ) + .concat_result + ) def concat_from_sequence( @@ -5291,17 +5385,21 @@ def concat_from_sequence( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ConcatFromSequence( - _ConcatFromSequence.Attributes( - axis=AttrInt64(axis, name="axis"), - new_axis=AttrInt64(new_axis, name="new_axis"), - ), - _ConcatFromSequence.Inputs( - input_sequence=unwrap_vars(input_sequence), - ), - ).get_output_vars( - input_sequence=get_value(input_sequence), - )["concat_result"] + return ( + _ConcatFromSequence( + _ConcatFromSequence.Attributes( + axis=AttrInt64(axis, name="axis"), + new_axis=AttrInt64(new_axis, name="new_axis"), + ), + _ConcatFromSequence.Inputs( + input_sequence=unwrap_vars(input_sequence), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + ) + .concat_result + ) def constant( @@ -5359,18 +5457,22 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), - _Constant.Inputs(), - ).get_output_vars()["output"] + return ( + _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), + _Constant.Inputs(), + ) + .get_output_vars() + .output + ) def constant_of_shape( @@ -5410,16 +5512,20 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), - _ConstantOfShape.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), + _ConstantOfShape.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def conv( @@ -5519,25 +5625,29 @@ def conv( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Conv( - _Conv.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _Conv.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - B=unwrap_vars(B), - ), - ).get_output_vars( - X=get_value(X), - W=get_value(W), - B=get_value(B), - )["Y"] + return ( + _Conv( + _Conv.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _Conv.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + B=get_value(B), + ) + .Y + ) def conv_integer( @@ -5648,27 +5758,31 @@ def conv_integer( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int32)` """ - return _ConvInteger( - _ConvInteger.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _ConvInteger.Inputs( - x=unwrap_vars(x), - w=unwrap_vars(w), - x_zero_point=unwrap_vars(x_zero_point), - w_zero_point=unwrap_vars(w_zero_point), - ), - ).get_output_vars( - x=get_value(x), - w=get_value(w), - x_zero_point=get_value(x_zero_point), - w_zero_point=get_value(w_zero_point), - )["y"] + return ( + _ConvInteger( + _ConvInteger.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _ConvInteger.Inputs( + x=unwrap_vars(x), + w=unwrap_vars(w), + x_zero_point=unwrap_vars(x_zero_point), + w_zero_point=unwrap_vars(w_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + w=get_value(w), + x_zero_point=get_value(x_zero_point), + w_zero_point=get_value(w_zero_point), + ) + .y + ) def conv_transpose( @@ -5799,27 +5913,31 @@ def conv_transpose( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _ConvTranspose( - _ConvTranspose.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - output_padding=AttrInt64s.maybe(output_padding, name="output_padding"), - output_shape=AttrInt64s.maybe(output_shape, name="output_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _ConvTranspose.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - B=unwrap_vars(B), - ), - ).get_output_vars( - X=get_value(X), - W=get_value(W), - B=get_value(B), - )["Y"] + return ( + _ConvTranspose( + _ConvTranspose.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + output_padding=AttrInt64s.maybe(output_padding, name="output_padding"), + output_shape=AttrInt64s.maybe(output_shape, name="output_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _ConvTranspose.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + B=get_value(B), + ) + .Y + ) def cos( @@ -5847,14 +5965,18 @@ def cos( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Cos( - _Cos.Attributes(), - _Cos.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Cos( + _Cos.Attributes(), + _Cos.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def cosh( @@ -5882,14 +6004,18 @@ def cosh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Cosh( - _Cosh.Attributes(), - _Cosh.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Cosh( + _Cosh.Attributes(), + _Cosh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def cumsum( @@ -5957,19 +6083,23 @@ def cumsum( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - T2: `tensor(int32)`, `tensor(int64)` """ - return _CumSum( - _CumSum.Attributes( - exclusive=AttrInt64(exclusive, name="exclusive"), - reverse=AttrInt64(reverse, name="reverse"), - ), - _CumSum.Inputs( - x=unwrap_vars(x), - axis=unwrap_vars(axis), - ), - ).get_output_vars( - x=get_value(x), - axis=get_value(axis), - )["y"] + return ( + _CumSum( + _CumSum.Attributes( + exclusive=AttrInt64(exclusive, name="exclusive"), + reverse=AttrInt64(reverse, name="reverse"), + ), + _CumSum.Inputs( + x=unwrap_vars(x), + axis=unwrap_vars(axis), + ), + ) + .get_output_vars( + x=get_value(x), + axis=get_value(axis), + ) + .y + ) def dft( @@ -6045,20 +6175,24 @@ def dft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - return _DFT( - _DFT.Attributes( - axis=AttrInt64(axis, name="axis"), - inverse=AttrInt64(inverse, name="inverse"), - onesided=AttrInt64(onesided, name="onesided"), - ), - _DFT.Inputs( - input=unwrap_vars(input), - dft_length=unwrap_vars(dft_length), - ), - ).get_output_vars( - input=get_value(input), - dft_length=get_value(dft_length), - )["output"] + return ( + _DFT( + _DFT.Attributes( + axis=AttrInt64(axis, name="axis"), + inverse=AttrInt64(inverse, name="inverse"), + onesided=AttrInt64(onesided, name="onesided"), + ), + _DFT.Inputs( + input=unwrap_vars(input), + dft_length=unwrap_vars(dft_length), + ), + ) + .get_output_vars( + input=get_value(input), + dft_length=get_value(dft_length), + ) + .output + ) def depth_to_space( @@ -6123,17 +6257,21 @@ def depth_to_space( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _DepthToSpace( - _DepthToSpace.Attributes( - blocksize=AttrInt64(blocksize, name="blocksize"), - mode=AttrString(mode, name="mode"), - ), - _DepthToSpace.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _DepthToSpace( + _DepthToSpace.Attributes( + blocksize=AttrInt64(blocksize, name="blocksize"), + mode=AttrString(mode, name="mode"), + ), + _DepthToSpace.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def dequantize_linear( @@ -6186,20 +6324,24 @@ def dequantize_linear( Type constraints: - T: `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` """ - return _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _DequantizeLinear.Inputs( - x=unwrap_vars(x), - x_scale=unwrap_vars(x_scale), - x_zero_point=unwrap_vars(x_zero_point), - ), - ).get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - )["y"] + return ( + _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _DequantizeLinear.Inputs( + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + ) + .y + ) def det( @@ -6232,14 +6374,18 @@ def det( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Det( - _Det.Attributes(), - _Det.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Det( + _Det.Attributes(), + _Det.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def div( @@ -6279,16 +6425,20 @@ def div( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Div( - _Div.Attributes(), - _Div.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Div( + _Div.Attributes(), + _Div.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def dropout( @@ -6383,7 +6533,7 @@ def dropout( ratio=get_value(ratio), training_mode=get_value(training_mode), ) - .values() + ._unpack_to_any() ) @@ -6464,7 +6614,7 @@ def dynamic_quantize_linear( .get_output_vars( x=get_value(x), ) - .values() + ._unpack_to_any() ) @@ -6530,16 +6680,20 @@ def einsum( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Einsum( - _Einsum.Attributes( - equation=AttrString(equation, name="equation"), - ), - _Einsum.Inputs( - Inputs=unwrap_vars(Inputs), - ), - ).get_output_vars( - Inputs=get_value(Inputs), - )["Output"] + return ( + _Einsum( + _Einsum.Attributes( + equation=AttrString(equation, name="equation"), + ), + _Einsum.Inputs( + Inputs=unwrap_vars(Inputs), + ), + ) + .get_output_vars( + Inputs=get_value(Inputs), + ) + .Output + ) def elu( @@ -6575,16 +6729,20 @@ def elu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Elu( - _Elu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), - _Elu.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Elu( + _Elu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), + _Elu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def equal( @@ -6623,16 +6781,20 @@ def equal( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - return _Equal( - _Equal.Attributes(), - _Equal.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Equal( + _Equal.Attributes(), + _Equal.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def erf( @@ -6661,14 +6823,18 @@ def erf( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Erf( - _Erf.Attributes(), - _Erf.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Erf( + _Erf.Attributes(), + _Erf.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def exp( @@ -6696,14 +6862,18 @@ def exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Exp( - _Exp.Attributes(), - _Exp.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Exp( + _Exp.Attributes(), + _Exp.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def expand( @@ -6744,16 +6914,20 @@ def expand( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Expand( - _Expand.Attributes(), - _Expand.Inputs( - input=unwrap_vars(input), - shape=unwrap_vars(shape), - ), - ).get_output_vars( - input=get_value(input), - shape=get_value(shape), - )["output"] + return ( + _Expand( + _Expand.Attributes(), + _Expand.Inputs( + input=unwrap_vars(input), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + input=get_value(input), + shape=get_value(shape), + ) + .output + ) def eye_like( @@ -6804,17 +6978,21 @@ def eye_like( - T1: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _EyeLike( - _EyeLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - k=AttrInt64(k, name="k"), - ), - _EyeLike.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _EyeLike( + _EyeLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + k=AttrInt64(k, name="k"), + ), + _EyeLike.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def flatten( @@ -6856,16 +7034,20 @@ def flatten( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Flatten( - _Flatten.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Flatten.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Flatten( + _Flatten.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Flatten.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def floor( @@ -6896,14 +7078,18 @@ def floor( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Floor( - _Floor.Attributes(), - _Floor.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Floor( + _Floor.Attributes(), + _Floor.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def gru( @@ -7113,7 +7299,7 @@ def gru( sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), ) - .values() + ._unpack_to_any() ) @@ -7203,18 +7389,22 @@ def gather( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _Gather( - _Gather.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Gather.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - ), - ).get_output_vars( - data=get_value(data), - indices=get_value(indices), - )["output"] + return ( + _Gather( + _Gather.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Gather.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + ) + .output + ) def gather_elements( @@ -7311,18 +7501,22 @@ def gather_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _GatherElements( - _GatherElements.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _GatherElements.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - ), - ).get_output_vars( - data=get_value(data), - indices=get_value(indices), - )["output"] + return ( + _GatherElements( + _GatherElements.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _GatherElements.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + ) + .output + ) def gather_nd( @@ -7464,18 +7658,22 @@ def gather_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _GatherND( - _GatherND.Attributes( - batch_dims=AttrInt64(batch_dims, name="batch_dims"), - ), - _GatherND.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - ), - ).get_output_vars( - data=get_value(data), - indices=get_value(indices), - )["output"] + return ( + _GatherND( + _GatherND.Attributes( + batch_dims=AttrInt64(batch_dims, name="batch_dims"), + ), + _GatherND.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + ) + .output + ) def gemm( @@ -7551,23 +7749,27 @@ def gemm( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _Gemm( - _Gemm.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - transA=AttrInt64(transA, name="transA"), - transB=AttrInt64(transB, name="transB"), - ), - _Gemm.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - C=unwrap_vars(C), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - C=get_value(C), - )["Y"] + return ( + _Gemm( + _Gemm.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + transA=AttrInt64(transA, name="transA"), + transB=AttrInt64(transB, name="transB"), + ), + _Gemm.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + C=unwrap_vars(C), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + C=get_value(C), + ) + .Y + ) def global_average_pool( @@ -7604,14 +7806,18 @@ def global_average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GlobalAveragePool( - _GlobalAveragePool.Attributes(), - _GlobalAveragePool.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _GlobalAveragePool( + _GlobalAveragePool.Attributes(), + _GlobalAveragePool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def global_lp_pool( @@ -7653,16 +7859,20 @@ def global_lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GlobalLpPool( - _GlobalLpPool.Attributes( - p=AttrInt64(p, name="p"), - ), - _GlobalLpPool.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _GlobalLpPool( + _GlobalLpPool.Attributes( + p=AttrInt64(p, name="p"), + ), + _GlobalLpPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def global_max_pool( @@ -7699,14 +7909,18 @@ def global_max_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GlobalMaxPool( - _GlobalMaxPool.Attributes(), - _GlobalMaxPool.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _GlobalMaxPool( + _GlobalMaxPool.Attributes(), + _GlobalMaxPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def greater( @@ -7745,16 +7959,20 @@ def greater( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - return _Greater( - _Greater.Attributes(), - _Greater.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Greater( + _Greater.Attributes(), + _Greater.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def greater_or_equal( @@ -7793,16 +8011,20 @@ def greater_or_equal( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - return _GreaterOrEqual( - _GreaterOrEqual.Attributes(), - _GreaterOrEqual.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _GreaterOrEqual( + _GreaterOrEqual.Attributes(), + _GreaterOrEqual.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def grid_sample( @@ -7887,20 +8109,24 @@ def grid_sample( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GridSample( - _GridSample.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - mode=AttrString(mode, name="mode"), - padding_mode=AttrString(padding_mode, name="padding_mode"), - ), - _GridSample.Inputs( - X=unwrap_vars(X), - grid=unwrap_vars(grid), - ), - ).get_output_vars( - X=get_value(X), - grid=get_value(grid), - )["Y"] + return ( + _GridSample( + _GridSample.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + mode=AttrString(mode, name="mode"), + padding_mode=AttrString(padding_mode, name="padding_mode"), + ), + _GridSample.Inputs( + X=unwrap_vars(X), + grid=unwrap_vars(grid), + ), + ) + .get_output_vars( + X=get_value(X), + grid=get_value(grid), + ) + .Y + ) def hamming_window( @@ -7944,17 +8170,21 @@ def hamming_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _HammingWindow( - _HammingWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), - _HammingWindow.Inputs( - size=unwrap_vars(size), - ), - ).get_output_vars( - size=get_value(size), - )["output"] + return ( + _HammingWindow( + _HammingWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), + _HammingWindow.Inputs( + size=unwrap_vars(size), + ), + ) + .get_output_vars( + size=get_value(size), + ) + .output + ) def hann_window( @@ -7998,17 +8228,21 @@ def hann_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _HannWindow( - _HannWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), - _HannWindow.Inputs( - size=unwrap_vars(size), - ), - ).get_output_vars( - size=get_value(size), - )["output"] + return ( + _HannWindow( + _HannWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), + _HannWindow.Inputs( + size=unwrap_vars(size), + ), + ) + .get_output_vars( + size=get_value(size), + ) + .output + ) def hard_sigmoid( @@ -8047,17 +8281,21 @@ def hard_sigmoid( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _HardSigmoid( - _HardSigmoid.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - ), - _HardSigmoid.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _HardSigmoid( + _HardSigmoid.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + ), + _HardSigmoid.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def hard_swish( @@ -8088,14 +8326,18 @@ def hard_swish( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _HardSwish( - _HardSwish.Attributes(), - _HardSwish.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _HardSwish( + _HardSwish.Attributes(), + _HardSwish.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def hardmax( @@ -8137,16 +8379,20 @@ def hardmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Hardmax( - _Hardmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Hardmax.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Hardmax( + _Hardmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Hardmax.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def identity( @@ -8174,14 +8420,18 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Identity( - _Identity.Attributes(), - _Identity.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Identity( + _Identity.Attributes(), + _Identity.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def if_( @@ -8238,18 +8488,22 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - return _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), - _If.Inputs( - cond=unwrap_vars(cond), - ), - out_variadic=len(_else_branch_subgraph.requested_results), - ).get_output_vars( - cond=get_value(cond), - )["outputs"] + return ( + _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), + _If.Inputs( + cond=unwrap_vars(cond), + ), + out_variadic=len(_else_branch_subgraph.requested_results), + ) + .get_output_vars( + cond=get_value(cond), + ) + .outputs + ) def instance_normalization( @@ -8298,20 +8552,24 @@ def instance_normalization( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _InstanceNormalization( - _InstanceNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - ), - _InstanceNormalization.Inputs( - input=unwrap_vars(input), - scale=unwrap_vars(scale), - B=unwrap_vars(B), - ), - ).get_output_vars( - input=get_value(input), - scale=get_value(scale), - B=get_value(B), - )["output"] + return ( + _InstanceNormalization( + _InstanceNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + ), + _InstanceNormalization.Inputs( + input=unwrap_vars(input), + scale=unwrap_vars(scale), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + input=get_value(input), + scale=get_value(scale), + B=get_value(B), + ) + .output + ) def isinf( @@ -8353,17 +8611,21 @@ def isinf( - T1: `tensor(double)`, `tensor(float)` - T2: `tensor(bool)` """ - return _IsInf( - _IsInf.Attributes( - detect_negative=AttrInt64(detect_negative, name="detect_negative"), - detect_positive=AttrInt64(detect_positive, name="detect_positive"), - ), - _IsInf.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _IsInf( + _IsInf.Attributes( + detect_negative=AttrInt64(detect_negative, name="detect_negative"), + detect_positive=AttrInt64(detect_positive, name="detect_positive"), + ), + _IsInf.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def isnan( @@ -8392,14 +8654,18 @@ def isnan( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bool)` """ - return _IsNaN( - _IsNaN.Attributes(), - _IsNaN.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _IsNaN( + _IsNaN.Attributes(), + _IsNaN.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def lrn( @@ -8461,19 +8727,23 @@ def lrn( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _LRN( - _LRN.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - bias=AttrFloat32(bias, name="bias"), - size=AttrInt64(size, name="size"), - ), - _LRN.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _LRN( + _LRN.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + bias=AttrFloat32(bias, name="bias"), + size=AttrInt64(size, name="size"), + ), + _LRN.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def lstm( @@ -8707,7 +8977,7 @@ def lstm( initial_c=get_value(initial_c), P=get_value(P), ) - .values() + ._unpack_to_any() ) @@ -8812,7 +9082,7 @@ def layer_normalization( Scale=get_value(Scale), B=get_value(B), ) - .values() + ._unpack_to_any() ) @@ -8849,16 +9119,20 @@ def leaky_relu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _LeakyRelu( - _LeakyRelu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), - _LeakyRelu.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _LeakyRelu( + _LeakyRelu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), + _LeakyRelu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def less( @@ -8897,16 +9171,20 @@ def less( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - return _Less( - _Less.Attributes(), - _Less.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Less( + _Less.Attributes(), + _Less.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def less_or_equal( @@ -8945,16 +9223,20 @@ def less_or_equal( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - return _LessOrEqual( - _LessOrEqual.Attributes(), - _LessOrEqual.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _LessOrEqual( + _LessOrEqual.Attributes(), + _LessOrEqual.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def log( @@ -8982,14 +9264,18 @@ def log( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Log( - _Log.Attributes(), - _Log.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Log( + _Log.Attributes(), + _Log.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def log_softmax( @@ -9030,16 +9316,20 @@ def log_softmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _LogSoftmax( - _LogSoftmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _LogSoftmax.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _LogSoftmax( + _LogSoftmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _LogSoftmax.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def loop( @@ -9223,21 +9513,25 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - return _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), - _Loop.Inputs( - M=unwrap_vars(M), - cond=unwrap_vars(cond), - v_initial=unwrap_vars(v_initial), - ), - out_variadic=len(_body_subgraph.requested_results) - 1, - ).get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), - )["v_final_and_scan_outputs"] + return ( + _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), + _Loop.Inputs( + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), + ), + out_variadic=len(_body_subgraph.requested_results) - 1, + ) + .get_output_vars( + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), + ) + .v_final_and_scan_outputs + ) def lp_normalization( @@ -9274,17 +9568,21 @@ def lp_normalization( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _LpNormalization( - _LpNormalization.Attributes( - axis=AttrInt64(axis, name="axis"), - p=AttrInt64(p, name="p"), - ), - _LpNormalization.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _LpNormalization( + _LpNormalization.Attributes( + axis=AttrInt64(axis, name="axis"), + p=AttrInt64(p, name="p"), + ), + _LpNormalization.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def lp_pool( @@ -9358,20 +9656,24 @@ def lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _LpPool( - _LpPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - p=AttrInt64(p, name="p"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _LpPool.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _LpPool( + _LpPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + p=AttrInt64(p, name="p"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _LpPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def matmul( @@ -9404,16 +9706,20 @@ def matmul( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _MatMul( - _MatMul.Attributes(), - _MatMul.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["Y"] + return ( + _MatMul( + _MatMul.Attributes(), + _MatMul.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .Y + ) def matmul_integer( @@ -9468,20 +9774,24 @@ def matmul_integer( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int32)` """ - return _MatMulInteger( - _MatMulInteger.Attributes(), - _MatMulInteger.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - a_zero_point=unwrap_vars(a_zero_point), - b_zero_point=unwrap_vars(b_zero_point), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - a_zero_point=get_value(a_zero_point), - b_zero_point=get_value(b_zero_point), - )["Y"] + return ( + _MatMulInteger( + _MatMulInteger.Attributes(), + _MatMulInteger.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + a_zero_point=unwrap_vars(a_zero_point), + b_zero_point=unwrap_vars(b_zero_point), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + a_zero_point=get_value(a_zero_point), + b_zero_point=get_value(b_zero_point), + ) + .Y + ) def max( @@ -9513,14 +9823,18 @@ def max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Max( - _Max.Attributes(), - _Max.Inputs( - data_0=unwrap_vars(data_0), - ), - ).get_output_vars( - data_0=get_value(data_0), - )["max"] + return ( + _Max( + _Max.Attributes(), + _Max.Inputs( + data_0=unwrap_vars(data_0), + ), + ) + .get_output_vars( + data_0=get_value(data_0), + ) + .max + ) def max_pool( @@ -9678,7 +9992,7 @@ def max_pool( .get_output_vars( X=get_value(X), ) - .values() + ._unpack_to_any() ) @@ -9727,19 +10041,23 @@ def max_roi_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _MaxRoiPool( - _MaxRoiPool.Attributes( - pooled_shape=AttrInt64s(pooled_shape, name="pooled_shape"), - spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), - ), - _MaxRoiPool.Inputs( - X=unwrap_vars(X), - rois=unwrap_vars(rois), - ), - ).get_output_vars( - X=get_value(X), - rois=get_value(rois), - )["Y"] + return ( + _MaxRoiPool( + _MaxRoiPool.Attributes( + pooled_shape=AttrInt64s(pooled_shape, name="pooled_shape"), + spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), + ), + _MaxRoiPool.Inputs( + X=unwrap_vars(X), + rois=unwrap_vars(rois), + ), + ) + .get_output_vars( + X=get_value(X), + rois=get_value(rois), + ) + .Y + ) def max_unpool( @@ -9838,22 +10156,26 @@ def max_unpool( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - return _MaxUnpool( - _MaxUnpool.Attributes( - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _MaxUnpool.Inputs( - X=unwrap_vars(X), - I=unwrap_vars(I), - output_shape=unwrap_vars(output_shape), - ), - ).get_output_vars( - X=get_value(X), - I=get_value(I), - output_shape=get_value(output_shape), - )["output"] + return ( + _MaxUnpool( + _MaxUnpool.Attributes( + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _MaxUnpool.Inputs( + X=unwrap_vars(X), + I=unwrap_vars(I), + output_shape=unwrap_vars(output_shape), + ), + ) + .get_output_vars( + X=get_value(X), + I=get_value(I), + output_shape=get_value(output_shape), + ) + .output + ) def mean( @@ -9885,14 +10207,18 @@ def mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Mean( - _Mean.Attributes(), - _Mean.Inputs( - data_0=unwrap_vars(data_0), - ), - ).get_output_vars( - data_0=get_value(data_0), - )["mean"] + return ( + _Mean( + _Mean.Attributes(), + _Mean.Inputs( + data_0=unwrap_vars(data_0), + ), + ) + .get_output_vars( + data_0=get_value(data_0), + ) + .mean + ) def mean_variance_normalization( @@ -9930,16 +10256,20 @@ def mean_variance_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _MeanVarianceNormalization( - _MeanVarianceNormalization.Attributes( - axes=AttrInt64s(axes, name="axes"), - ), - _MeanVarianceNormalization.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _MeanVarianceNormalization( + _MeanVarianceNormalization.Attributes( + axes=AttrInt64s(axes, name="axes"), + ), + _MeanVarianceNormalization.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def mel_weight_matrix( @@ -10016,24 +10346,28 @@ def mel_weight_matrix( - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T3: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _MelWeightMatrix( - _MelWeightMatrix.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - ), - _MelWeightMatrix.Inputs( - num_mel_bins=unwrap_vars(num_mel_bins), - dft_length=unwrap_vars(dft_length), - sample_rate=unwrap_vars(sample_rate), - lower_edge_hertz=unwrap_vars(lower_edge_hertz), - upper_edge_hertz=unwrap_vars(upper_edge_hertz), - ), - ).get_output_vars( - num_mel_bins=get_value(num_mel_bins), - dft_length=get_value(dft_length), - sample_rate=get_value(sample_rate), - lower_edge_hertz=get_value(lower_edge_hertz), - upper_edge_hertz=get_value(upper_edge_hertz), - )["output"] + return ( + _MelWeightMatrix( + _MelWeightMatrix.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + ), + _MelWeightMatrix.Inputs( + num_mel_bins=unwrap_vars(num_mel_bins), + dft_length=unwrap_vars(dft_length), + sample_rate=unwrap_vars(sample_rate), + lower_edge_hertz=unwrap_vars(lower_edge_hertz), + upper_edge_hertz=unwrap_vars(upper_edge_hertz), + ), + ) + .get_output_vars( + num_mel_bins=get_value(num_mel_bins), + dft_length=get_value(dft_length), + sample_rate=get_value(sample_rate), + lower_edge_hertz=get_value(lower_edge_hertz), + upper_edge_hertz=get_value(upper_edge_hertz), + ) + .output + ) def min( @@ -10065,14 +10399,18 @@ def min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Min( - _Min.Attributes(), - _Min.Inputs( - data_0=unwrap_vars(data_0), - ), - ).get_output_vars( - data_0=get_value(data_0), - )["min"] + return ( + _Min( + _Min.Attributes(), + _Min.Inputs( + data_0=unwrap_vars(data_0), + ), + ) + .get_output_vars( + data_0=get_value(data_0), + ) + .min + ) def mod( @@ -10127,18 +10465,22 @@ def mod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Mod( - _Mod.Attributes( - fmod=AttrInt64(fmod, name="fmod"), - ), - _Mod.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Mod( + _Mod.Attributes( + fmod=AttrInt64(fmod, name="fmod"), + ), + _Mod.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def mul( @@ -10178,16 +10520,20 @@ def mul( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Mul( - _Mul.Attributes(), - _Mul.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Mul( + _Mul.Attributes(), + _Mul.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def multinomial( @@ -10237,18 +10583,22 @@ def multinomial( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - return _Multinomial( - _Multinomial.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - sample_size=AttrInt64(sample_size, name="sample_size"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), - _Multinomial.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Multinomial( + _Multinomial.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + sample_size=AttrInt64(sample_size, name="sample_size"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), + _Multinomial.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def neg( @@ -10278,14 +10628,18 @@ def neg( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ - return _Neg( - _Neg.Attributes(), - _Neg.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Neg( + _Neg.Attributes(), + _Neg.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def negative_log_likelihood_loss( @@ -10445,21 +10799,25 @@ def negative_log_likelihood_loss( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _NegativeLogLikelihoodLoss( - _NegativeLogLikelihoodLoss.Attributes( - ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), - reduction=AttrString(reduction, name="reduction"), - ), - _NegativeLogLikelihoodLoss.Inputs( - input=unwrap_vars(input), - target=unwrap_vars(target), - weight=unwrap_vars(weight), - ), - ).get_output_vars( - input=get_value(input), - target=get_value(target), - weight=get_value(weight), - )["loss"] + return ( + _NegativeLogLikelihoodLoss( + _NegativeLogLikelihoodLoss.Attributes( + ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), + reduction=AttrString(reduction, name="reduction"), + ), + _NegativeLogLikelihoodLoss.Inputs( + input=unwrap_vars(input), + target=unwrap_vars(target), + weight=unwrap_vars(weight), + ), + ) + .get_output_vars( + input=get_value(input), + target=get_value(target), + weight=get_value(weight), + ) + .loss + ) def non_max_suppression( @@ -10528,24 +10886,28 @@ def non_max_suppression( Signature: ``ai.onnx@11::NonMaxSuppression``. """ - return _NonMaxSuppression( - _NonMaxSuppression.Attributes( - center_point_box=AttrInt64(center_point_box, name="center_point_box"), - ), - _NonMaxSuppression.Inputs( - boxes=unwrap_vars(boxes), - scores=unwrap_vars(scores), - max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), - iou_threshold=unwrap_vars(iou_threshold), - score_threshold=unwrap_vars(score_threshold), - ), - ).get_output_vars( - boxes=get_value(boxes), - scores=get_value(scores), - max_output_boxes_per_class=get_value(max_output_boxes_per_class), - iou_threshold=get_value(iou_threshold), - score_threshold=get_value(score_threshold), - )["selected_indices"] + return ( + _NonMaxSuppression( + _NonMaxSuppression.Attributes( + center_point_box=AttrInt64(center_point_box, name="center_point_box"), + ), + _NonMaxSuppression.Inputs( + boxes=unwrap_vars(boxes), + scores=unwrap_vars(scores), + max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), + iou_threshold=unwrap_vars(iou_threshold), + score_threshold=unwrap_vars(score_threshold), + ), + ) + .get_output_vars( + boxes=get_value(boxes), + scores=get_value(scores), + max_output_boxes_per_class=get_value(max_output_boxes_per_class), + iou_threshold=get_value(iou_threshold), + score_threshold=get_value(score_threshold), + ) + .selected_indices + ) def non_zero( @@ -10577,14 +10939,18 @@ def non_zero( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _NonZero( - _NonZero.Attributes(), - _NonZero.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _NonZero( + _NonZero.Attributes(), + _NonZero.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def not_( @@ -10612,14 +10978,18 @@ def not_( Type constraints: - T: `tensor(bool)` """ - return _Not( - _Not.Attributes(), - _Not.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Not( + _Not.Attributes(), + _Not.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def one_hot( @@ -10703,20 +11073,24 @@ def one_hot( - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T3: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _OneHot( - _OneHot.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _OneHot.Inputs( - indices=unwrap_vars(indices), - depth=unwrap_vars(depth), - values=unwrap_vars(values), - ), - ).get_output_vars( - indices=get_value(indices), - depth=get_value(depth), - values=get_value(values), - )["output"] + return ( + _OneHot( + _OneHot.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _OneHot.Inputs( + indices=unwrap_vars(indices), + depth=unwrap_vars(depth), + values=unwrap_vars(values), + ), + ) + .get_output_vars( + indices=get_value(indices), + depth=get_value(depth), + values=get_value(values), + ) + .output + ) def optional( @@ -10752,16 +11126,20 @@ def optional( - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` """ - return _Optional( - _Optional.Attributes( - type=AttrType.maybe(type, name="type"), - ), - _Optional.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Optional( + _Optional.Attributes( + type=AttrType.maybe(type, name="type"), + ), + _Optional.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def optional_get_element( @@ -10792,14 +11170,18 @@ def optional_get_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _OptionalGetElement( - _OptionalGetElement.Attributes(), - _OptionalGetElement.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _OptionalGetElement( + _OptionalGetElement.Attributes(), + _OptionalGetElement.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def optional_has_element( @@ -10830,14 +11212,18 @@ def optional_has_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - B: `tensor(bool)` """ - return _OptionalHasElement( - _OptionalHasElement.Attributes(), - _OptionalHasElement.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _OptionalHasElement( + _OptionalHasElement.Attributes(), + _OptionalHasElement.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def or_( @@ -10876,16 +11262,20 @@ def or_( - T: `tensor(bool)` - T1: `tensor(bool)` """ - return _Or( - _Or.Attributes(), - _Or.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Or( + _Or.Attributes(), + _Or.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def prelu( @@ -10924,16 +11314,20 @@ def prelu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _PRelu( - _PRelu.Attributes(), - _PRelu.Inputs( - X=unwrap_vars(X), - slope=unwrap_vars(slope), - ), - ).get_output_vars( - X=get_value(X), - slope=get_value(slope), - )["Y"] + return ( + _PRelu( + _PRelu.Attributes(), + _PRelu.Inputs( + X=unwrap_vars(X), + slope=unwrap_vars(slope), + ), + ) + .get_output_vars( + X=get_value(X), + slope=get_value(slope), + ) + .Y + ) def pad( @@ -11030,20 +11424,24 @@ def pad( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), - _Pad.Inputs( - data=unwrap_vars(data), - pads=unwrap_vars(pads), - constant_value=unwrap_vars(constant_value), - ), - ).get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - )["output"] + return ( + _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), + _Pad.Inputs( + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + ), + ) + .get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + ) + .output + ) def pow( @@ -11081,16 +11479,20 @@ def pow( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)` - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Pow( - _Pow.Attributes(), - _Pow.Inputs( - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ).get_output_vars( - X=get_value(X), - Y=get_value(Y), - )["Z"] + return ( + _Pow( + _Pow.Attributes(), + _Pow.Inputs( + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + X=get_value(X), + Y=get_value(Y), + ) + .Z + ) def qlinear_conv( @@ -11233,37 +11635,41 @@ def qlinear_conv( - T3: `tensor(int8)`, `tensor(uint8)` - T4: `tensor(int32)` """ - return _QLinearConv( - _QLinearConv.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _QLinearConv.Inputs( - x=unwrap_vars(x), - x_scale=unwrap_vars(x_scale), - x_zero_point=unwrap_vars(x_zero_point), - w=unwrap_vars(w), - w_scale=unwrap_vars(w_scale), - w_zero_point=unwrap_vars(w_zero_point), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - B=unwrap_vars(B), - ), - ).get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - w=get_value(w), - w_scale=get_value(w_scale), - w_zero_point=get_value(w_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - B=get_value(B), - )["y"] + return ( + _QLinearConv( + _QLinearConv.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _QLinearConv.Inputs( + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + w=unwrap_vars(w), + w_scale=unwrap_vars(w_scale), + w_zero_point=unwrap_vars(w_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + w=get_value(w), + w_scale=get_value(w_scale), + w_zero_point=get_value(w_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + B=get_value(B), + ) + .y + ) def qlinear_matmul( @@ -11338,28 +11744,32 @@ def qlinear_matmul( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int8)`, `tensor(uint8)` """ - return _QLinearMatMul( - _QLinearMatMul.Attributes(), - _QLinearMatMul.Inputs( - a=unwrap_vars(a), - a_scale=unwrap_vars(a_scale), - a_zero_point=unwrap_vars(a_zero_point), - b=unwrap_vars(b), - b_scale=unwrap_vars(b_scale), - b_zero_point=unwrap_vars(b_zero_point), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ).get_output_vars( - a=get_value(a), - a_scale=get_value(a_scale), - a_zero_point=get_value(a_zero_point), - b=get_value(b), - b_scale=get_value(b_scale), - b_zero_point=get_value(b_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - )["y"] + return ( + _QLinearMatMul( + _QLinearMatMul.Attributes(), + _QLinearMatMul.Inputs( + a=unwrap_vars(a), + a_scale=unwrap_vars(a_scale), + a_zero_point=unwrap_vars(a_zero_point), + b=unwrap_vars(b), + b_scale=unwrap_vars(b_scale), + b_zero_point=unwrap_vars(b_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + a=get_value(a), + a_scale=get_value(a_scale), + a_zero_point=get_value(a_zero_point), + b=get_value(b), + b_scale=get_value(b_scale), + b_zero_point=get_value(b_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) def quantize_linear( @@ -11416,20 +11826,24 @@ def quantize_linear( - T1: `tensor(float)`, `tensor(int32)` - T2: `tensor(int8)`, `tensor(uint8)` """ - return _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _QuantizeLinear.Inputs( - x=unwrap_vars(x), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ).get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - )["y"] + return ( + _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _QuantizeLinear.Inputs( + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) def rnn( @@ -11616,7 +12030,7 @@ def rnn( sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), ) - .values() + ._unpack_to_any() ) @@ -11671,16 +12085,20 @@ def random_normal( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _RandomNormal( - _RandomNormal.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - mean=AttrFloat32(mean, name="mean"), - scale=AttrFloat32(scale, name="scale"), - seed=AttrFloat32.maybe(seed, name="seed"), - shape=AttrInt64s(shape, name="shape"), - ), - _RandomNormal.Inputs(), - ).get_output_vars()["output"] + return ( + _RandomNormal( + _RandomNormal.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + mean=AttrFloat32(mean, name="mean"), + scale=AttrFloat32(scale, name="scale"), + seed=AttrFloat32.maybe(seed, name="seed"), + shape=AttrInt64s(shape, name="shape"), + ), + _RandomNormal.Inputs(), + ) + .get_output_vars() + .output + ) def random_normal_like( @@ -11736,19 +12154,23 @@ def random_normal_like( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _RandomNormalLike( - _RandomNormalLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - mean=AttrFloat32(mean, name="mean"), - scale=AttrFloat32(scale, name="scale"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), - _RandomNormalLike.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _RandomNormalLike( + _RandomNormalLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + mean=AttrFloat32(mean, name="mean"), + scale=AttrFloat32(scale, name="scale"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), + _RandomNormalLike.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def random_uniform( @@ -11801,16 +12223,20 @@ def random_uniform( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _RandomUniform( - _RandomUniform.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - high=AttrFloat32(high, name="high"), - low=AttrFloat32(low, name="low"), - seed=AttrFloat32.maybe(seed, name="seed"), - shape=AttrInt64s(shape, name="shape"), - ), - _RandomUniform.Inputs(), - ).get_output_vars()["output"] + return ( + _RandomUniform( + _RandomUniform.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + high=AttrFloat32(high, name="high"), + low=AttrFloat32(low, name="low"), + seed=AttrFloat32.maybe(seed, name="seed"), + shape=AttrInt64s(shape, name="shape"), + ), + _RandomUniform.Inputs(), + ) + .get_output_vars() + .output + ) def random_uniform_like( @@ -11866,19 +12292,23 @@ def random_uniform_like( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _RandomUniformLike( - _RandomUniformLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - high=AttrFloat32(high, name="high"), - low=AttrFloat32(low, name="low"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), - _RandomUniformLike.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _RandomUniformLike( + _RandomUniformLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + high=AttrFloat32(high, name="high"), + low=AttrFloat32(low, name="low"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), + _RandomUniformLike.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def range( @@ -11945,18 +12375,22 @@ def range( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)` """ - return _Range( - _Range.Attributes(), - _Range.Inputs( - start=unwrap_vars(start), - limit=unwrap_vars(limit), - delta=unwrap_vars(delta), - ), - ).get_output_vars( - start=get_value(start), - limit=get_value(limit), - delta=get_value(delta), - )["output"] + return ( + _Range( + _Range.Attributes(), + _Range.Inputs( + start=unwrap_vars(start), + limit=unwrap_vars(limit), + delta=unwrap_vars(delta), + ), + ) + .get_output_vars( + start=get_value(start), + limit=get_value(limit), + delta=get_value(delta), + ) + .output + ) def reciprocal( @@ -11986,14 +12420,18 @@ def reciprocal( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Reciprocal( - _Reciprocal.Attributes(), - _Reciprocal.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Reciprocal( + _Reciprocal.Attributes(), + _Reciprocal.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def reduce_l1( @@ -12040,17 +12478,21 @@ def reduce_l1( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceL1( - _ReduceL1.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceL1.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceL1( + _ReduceL1.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceL1.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def reduce_l2( @@ -12097,17 +12539,21 @@ def reduce_l2( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceL2( - _ReduceL2.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceL2.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceL2( + _ReduceL2.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceL2.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def reduce_log_sum( @@ -12155,17 +12601,21 @@ def reduce_log_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceLogSum( - _ReduceLogSum.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceLogSum.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceLogSum( + _ReduceLogSum.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceLogSum.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def reduce_log_sum_exp( @@ -12213,17 +12663,21 @@ def reduce_log_sum_exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceLogSumExp( - _ReduceLogSumExp.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceLogSumExp.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceLogSumExp( + _ReduceLogSumExp.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceLogSumExp.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def reduce_max( @@ -12272,17 +12726,21 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReduceMax( - _ReduceMax.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceMax.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceMax( + _ReduceMax.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceMax.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def reduce_mean( @@ -12329,17 +12787,21 @@ def reduce_mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceMean( - _ReduceMean.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceMean.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceMean( + _ReduceMean.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceMean.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def reduce_min( @@ -12387,17 +12849,21 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReduceMin( - _ReduceMin.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceMin.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceMin( + _ReduceMin.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceMin.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def reduce_prod( @@ -12444,17 +12910,21 @@ def reduce_prod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceProd( - _ReduceProd.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceProd.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceProd( + _ReduceProd.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceProd.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def reduce_sum( @@ -12510,21 +12980,25 @@ def reduce_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceSum( - _ReduceSum.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceSum.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + return ( + _ReduceSum( + _ReduceSum.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceSum.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_sum_square( @@ -12571,17 +13045,21 @@ def reduce_sum_square( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceSumSquare( - _ReduceSumSquare.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceSumSquare.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["reduced"] + return ( + _ReduceSumSquare( + _ReduceSumSquare.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceSumSquare.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) def relu( @@ -12611,14 +13089,18 @@ def relu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ - return _Relu( - _Relu.Attributes(), - _Relu.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Relu( + _Relu.Attributes(), + _Relu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def reshape( @@ -12672,18 +13154,22 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), - _Reshape.Inputs( - data=unwrap_vars(data), - shape=unwrap_vars(shape), - ), - ).get_output_vars( - data=get_value(data), - shape=get_value(shape), - )["reshaped"] + return ( + _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), + _Reshape.Inputs( + data=unwrap_vars(data), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + data=get_value(data), + shape=get_value(shape), + ) + .reshaped + ) def resize( @@ -12805,31 +13291,36 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Resize( - _Resize.Attributes( - coordinate_transformation_mode=AttrString( - coordinate_transformation_mode, name="coordinate_transformation_mode" - ), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32( - extrapolation_value, name="extrapolation_value" - ), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), - _Resize.Inputs( - X=unwrap_vars(X), - roi=unwrap_vars(roi), - scales=unwrap_vars(scales), - sizes=unwrap_vars(sizes), - ), - ).get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), - )["Y"] + return ( + _Resize( + _Resize.Attributes( + coordinate_transformation_mode=AttrString( + coordinate_transformation_mode, + name="coordinate_transformation_mode", + ), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32( + extrapolation_value, name="extrapolation_value" + ), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), + ), + _Resize.Inputs( + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), + ), + ) + .get_output_vars( + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), + ) + .Y + ) def reverse_sequence( @@ -12894,19 +13385,23 @@ def reverse_sequence( Type constraints: - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReverseSequence( - _ReverseSequence.Attributes( - batch_axis=AttrInt64(batch_axis, name="batch_axis"), - time_axis=AttrInt64(time_axis, name="time_axis"), - ), - _ReverseSequence.Inputs( - input=unwrap_vars(input), - sequence_lens=unwrap_vars(sequence_lens), - ), - ).get_output_vars( - input=get_value(input), - sequence_lens=get_value(sequence_lens), - )["Y"] + return ( + _ReverseSequence( + _ReverseSequence.Attributes( + batch_axis=AttrInt64(batch_axis, name="batch_axis"), + time_axis=AttrInt64(time_axis, name="time_axis"), + ), + _ReverseSequence.Inputs( + input=unwrap_vars(input), + sequence_lens=unwrap_vars(sequence_lens), + ), + ) + .get_output_vars( + input=get_value(input), + sequence_lens=get_value(sequence_lens), + ) + .Y + ) def roi_align( @@ -12996,27 +13491,32 @@ def roi_align( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - return _RoiAlign( - _RoiAlign.Attributes( - coordinate_transformation_mode=AttrString( - coordinate_transformation_mode, name="coordinate_transformation_mode" - ), - mode=AttrString(mode, name="mode"), - output_height=AttrInt64(output_height, name="output_height"), - output_width=AttrInt64(output_width, name="output_width"), - sampling_ratio=AttrInt64(sampling_ratio, name="sampling_ratio"), - spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), - ), - _RoiAlign.Inputs( - X=unwrap_vars(X), - rois=unwrap_vars(rois), - batch_indices=unwrap_vars(batch_indices), - ), - ).get_output_vars( - X=get_value(X), - rois=get_value(rois), - batch_indices=get_value(batch_indices), - )["Y"] + return ( + _RoiAlign( + _RoiAlign.Attributes( + coordinate_transformation_mode=AttrString( + coordinate_transformation_mode, + name="coordinate_transformation_mode", + ), + mode=AttrString(mode, name="mode"), + output_height=AttrInt64(output_height, name="output_height"), + output_width=AttrInt64(output_width, name="output_width"), + sampling_ratio=AttrInt64(sampling_ratio, name="sampling_ratio"), + spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), + ), + _RoiAlign.Inputs( + X=unwrap_vars(X), + rois=unwrap_vars(rois), + batch_indices=unwrap_vars(batch_indices), + ), + ) + .get_output_vars( + X=get_value(X), + rois=get_value(rois), + batch_indices=get_value(batch_indices), + ) + .Y + ) def round( @@ -13058,14 +13558,18 @@ def round( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Round( - _Round.Attributes(), - _Round.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Round( + _Round.Attributes(), + _Round.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def stft( @@ -13129,22 +13633,26 @@ def stft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - return _STFT( - _STFT.Attributes( - onesided=AttrInt64(onesided, name="onesided"), - ), - _STFT.Inputs( - signal=unwrap_vars(signal), - frame_step=unwrap_vars(frame_step), - window=unwrap_vars(window), - frame_length=unwrap_vars(frame_length), - ), - ).get_output_vars( - signal=get_value(signal), - frame_step=get_value(frame_step), - window=get_value(window), - frame_length=get_value(frame_length), - )["output"] + return ( + _STFT( + _STFT.Attributes( + onesided=AttrInt64(onesided, name="onesided"), + ), + _STFT.Inputs( + signal=unwrap_vars(signal), + frame_step=unwrap_vars(frame_step), + window=unwrap_vars(window), + frame_length=unwrap_vars(frame_length), + ), + ) + .get_output_vars( + signal=get_value(signal), + frame_step=get_value(frame_step), + window=get_value(window), + frame_length=get_value(frame_length), + ) + .output + ) def scan( @@ -13368,28 +13876,36 @@ def scan( ], body, ) - return _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), - scan_input_directions=AttrInt64s.maybe( - scan_input_directions, name="scan_input_directions" - ), - scan_output_axes=AttrInt64s.maybe( - scan_output_axes, name="scan_output_axes" - ), - scan_output_directions=AttrInt64s.maybe( - scan_output_directions, name="scan_output_directions" - ), - ), - _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), - ), - out_variadic=len(_body_subgraph.requested_results), - ).get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), - )["final_state_and_scan_outputs"] + return ( + _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe( + scan_input_axes, name="scan_input_axes" + ), + scan_input_directions=AttrInt64s.maybe( + scan_input_directions, name="scan_input_directions" + ), + scan_output_axes=AttrInt64s.maybe( + scan_output_axes, name="scan_output_axes" + ), + scan_output_directions=AttrInt64s.maybe( + scan_output_directions, name="scan_output_directions" + ), + ), + _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars( + initial_state_and_scan_inputs + ), + ), + out_variadic=len(_body_subgraph.requested_results), + ) + .get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + ) + .final_state_and_scan_outputs + ) def scatter_elements( @@ -13512,21 +14028,25 @@ def scatter_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _ScatterElements( - _ScatterElements.Attributes( - axis=AttrInt64(axis, name="axis"), - reduction=AttrString(reduction, name="reduction"), - ), - _ScatterElements.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - updates=unwrap_vars(updates), - ), - ).get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), - )["output"] + return ( + _ScatterElements( + _ScatterElements.Attributes( + axis=AttrInt64(axis, name="axis"), + reduction=AttrString(reduction, name="reduction"), + ), + _ScatterElements.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), + ) + .output + ) def scatter_nd( @@ -13638,20 +14158,24 @@ def scatter_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ScatterND( - _ScatterND.Attributes( - reduction=AttrString(reduction, name="reduction"), - ), - _ScatterND.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - updates=unwrap_vars(updates), - ), - ).get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), - )["output"] + return ( + _ScatterND( + _ScatterND.Attributes( + reduction=AttrString(reduction, name="reduction"), + ), + _ScatterND.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), + ) + .output + ) def selu( @@ -13693,17 +14217,21 @@ def selu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Selu( - _Selu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - gamma=AttrFloat32(gamma, name="gamma"), - ), - _Selu.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Selu( + _Selu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + gamma=AttrFloat32(gamma, name="gamma"), + ), + _Selu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def sequence_at( @@ -13744,16 +14272,20 @@ def sequence_at( - I: `tensor(int32)`, `tensor(int64)` - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _SequenceAt( - _SequenceAt.Attributes(), - _SequenceAt.Inputs( - input_sequence=unwrap_vars(input_sequence), - position=unwrap_vars(position), - ), - ).get_output_vars( - input_sequence=get_value(input_sequence), - position=get_value(position), - )["tensor"] + return ( + _SequenceAt( + _SequenceAt.Attributes(), + _SequenceAt.Inputs( + input_sequence=unwrap_vars(input_sequence), + position=unwrap_vars(position), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + position=get_value(position), + ) + .tensor + ) def sequence_construct( @@ -13783,14 +14315,18 @@ def sequence_construct( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - return _SequenceConstruct( - _SequenceConstruct.Attributes(), - _SequenceConstruct.Inputs( - inputs=unwrap_vars(inputs), - ), - ).get_output_vars( - inputs=get_value(inputs), - )["output_sequence"] + return ( + _SequenceConstruct( + _SequenceConstruct.Attributes(), + _SequenceConstruct.Inputs( + inputs=unwrap_vars(inputs), + ), + ) + .get_output_vars( + inputs=get_value(inputs), + ) + .output_sequence + ) def sequence_empty( @@ -13820,12 +14356,16 @@ def sequence_empty( Type constraints: - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - return _SequenceEmpty( - _SequenceEmpty.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - ), - _SequenceEmpty.Inputs(), - ).get_output_vars()["output"] + return ( + _SequenceEmpty( + _SequenceEmpty.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + ), + _SequenceEmpty.Inputs(), + ) + .get_output_vars() + .output + ) def sequence_erase( @@ -13866,16 +14406,20 @@ def sequence_erase( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - I: `tensor(int32)`, `tensor(int64)` """ - return _SequenceErase( - _SequenceErase.Attributes(), - _SequenceErase.Inputs( - input_sequence=unwrap_vars(input_sequence), - position=unwrap_vars(position), - ), - ).get_output_vars( - input_sequence=get_value(input_sequence), - position=get_value(position), - )["output_sequence"] + return ( + _SequenceErase( + _SequenceErase.Attributes(), + _SequenceErase.Inputs( + input_sequence=unwrap_vars(input_sequence), + position=unwrap_vars(position), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + position=get_value(position), + ) + .output_sequence + ) def sequence_insert( @@ -13923,18 +14467,22 @@ def sequence_insert( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - I: `tensor(int32)`, `tensor(int64)` """ - return _SequenceInsert( - _SequenceInsert.Attributes(), - _SequenceInsert.Inputs( - input_sequence=unwrap_vars(input_sequence), - tensor=unwrap_vars(tensor), - position=unwrap_vars(position), - ), - ).get_output_vars( - input_sequence=get_value(input_sequence), - tensor=get_value(tensor), - position=get_value(position), - )["output_sequence"] + return ( + _SequenceInsert( + _SequenceInsert.Attributes(), + _SequenceInsert.Inputs( + input_sequence=unwrap_vars(input_sequence), + tensor=unwrap_vars(tensor), + position=unwrap_vars(position), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + tensor=get_value(tensor), + position=get_value(position), + ) + .output_sequence + ) def sequence_length( @@ -13964,14 +14512,18 @@ def sequence_length( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - I: `tensor(int64)` """ - return _SequenceLength( - _SequenceLength.Attributes(), - _SequenceLength.Inputs( - input_sequence=unwrap_vars(input_sequence), - ), - ).get_output_vars( - input_sequence=get_value(input_sequence), - )["length"] + return ( + _SequenceLength( + _SequenceLength.Attributes(), + _SequenceLength.Inputs( + input_sequence=unwrap_vars(input_sequence), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + ) + .length + ) def sequence_map( @@ -14034,19 +14586,23 @@ def sequence_map( ], body, ) - return _SequenceMap( - _SequenceMap.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), - _SequenceMap.Inputs( - input_sequence=unwrap_vars(input_sequence), - additional_inputs=unwrap_vars(additional_inputs), - ), - out_variadic=len(_body_subgraph.requested_results), - ).get_output_vars( - input_sequence=get_value(input_sequence), - additional_inputs=get_value(additional_inputs), - )["out_sequence"] + return ( + _SequenceMap( + _SequenceMap.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), + _SequenceMap.Inputs( + input_sequence=unwrap_vars(input_sequence), + additional_inputs=unwrap_vars(additional_inputs), + ), + out_variadic=len(_body_subgraph.requested_results), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + additional_inputs=get_value(additional_inputs), + ) + .out_sequence + ) def shape( @@ -14125,17 +14681,21 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - return _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), - _Shape.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["shape"] + return ( + _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), + _Shape.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .shape + ) def shrink( @@ -14175,17 +14735,21 @@ def shrink( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Shrink( - _Shrink.Attributes( - bias=AttrFloat32(bias, name="bias"), - lambd=AttrFloat32(lambd, name="lambd"), - ), - _Shrink.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Shrink( + _Shrink.Attributes( + bias=AttrFloat32(bias, name="bias"), + lambd=AttrFloat32(lambd, name="lambd"), + ), + _Shrink.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def sigmoid( @@ -14215,14 +14779,18 @@ def sigmoid( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Sigmoid( - _Sigmoid.Attributes(), - _Sigmoid.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Sigmoid( + _Sigmoid.Attributes(), + _Sigmoid.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def sign( @@ -14252,14 +14820,18 @@ def sign( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Sign( - _Sign.Attributes(), - _Sign.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Sign( + _Sign.Attributes(), + _Sign.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def sin( @@ -14287,14 +14859,18 @@ def sin( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Sin( - _Sin.Attributes(), - _Sin.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Sin( + _Sin.Attributes(), + _Sin.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def sinh( @@ -14322,14 +14898,18 @@ def sinh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Sinh( - _Sinh.Attributes(), - _Sinh.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Sinh( + _Sinh.Attributes(), + _Sinh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def size( @@ -14359,14 +14939,18 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - return _Size( - _Size.Attributes(), - _Size.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["size"] + return ( + _Size( + _Size.Attributes(), + _Size.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .size + ) def slice( @@ -14482,22 +15066,26 @@ def slice( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _Slice( - _Slice.Attributes(), - _Slice.Inputs( - data=unwrap_vars(data), - starts=unwrap_vars(starts), - ends=unwrap_vars(ends), - axes=unwrap_vars(axes), - steps=unwrap_vars(steps), - ), - ).get_output_vars( - data=get_value(data), - starts=get_value(starts), - ends=get_value(ends), - axes=get_value(axes), - steps=get_value(steps), - )["output"] + return ( + _Slice( + _Slice.Attributes(), + _Slice.Inputs( + data=unwrap_vars(data), + starts=unwrap_vars(starts), + ends=unwrap_vars(ends), + axes=unwrap_vars(axes), + steps=unwrap_vars(steps), + ), + ) + .get_output_vars( + data=get_value(data), + starts=get_value(starts), + ends=get_value(ends), + axes=get_value(axes), + steps=get_value(steps), + ) + .output + ) def softmax( @@ -14540,16 +15128,20 @@ def softmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Softmax( - _Softmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Softmax.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Softmax( + _Softmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Softmax.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def softmax_cross_entropy_loss( @@ -14678,7 +15270,7 @@ def softmax_cross_entropy_loss( labels=get_value(labels), weights=get_value(weights), ) - .values() + ._unpack_to_any() ) @@ -14709,14 +15301,18 @@ def softplus( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Softplus( - _Softplus.Attributes(), - _Softplus.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Softplus( + _Softplus.Attributes(), + _Softplus.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def softsign( @@ -14746,14 +15342,18 @@ def softsign( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Softsign( - _Softsign.Attributes(), - _Softsign.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Softsign( + _Softsign.Attributes(), + _Softsign.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def space_to_depth( @@ -14790,16 +15390,20 @@ def space_to_depth( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _SpaceToDepth( - _SpaceToDepth.Attributes( - blocksize=AttrInt64(blocksize, name="blocksize"), - ), - _SpaceToDepth.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _SpaceToDepth( + _SpaceToDepth.Attributes( + blocksize=AttrInt64(blocksize, name="blocksize"), + ), + _SpaceToDepth.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def split( @@ -14844,19 +15448,23 @@ def split( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Split( - _Split.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Split.Inputs( - input=unwrap_vars(input), - split=unwrap_vars(split), - ), - out_variadic=outputs_count, - ).get_output_vars( - input=get_value(input), - split=get_value(split), - )["outputs"] + return ( + _Split( + _Split.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Split.Inputs( + input=unwrap_vars(input), + split=unwrap_vars(split), + ), + out_variadic=outputs_count, + ) + .get_output_vars( + input=get_value(input), + split=get_value(split), + ) + .outputs + ) def split_to_sequence( @@ -14914,19 +15522,23 @@ def split_to_sequence( - I: `tensor(int32)`, `tensor(int64)` - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - return _SplitToSequence( - _SplitToSequence.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _SplitToSequence.Inputs( - input=unwrap_vars(input), - split=unwrap_vars(split), - ), - ).get_output_vars( - input=get_value(input), - split=get_value(split), - )["output_sequence"] + return ( + _SplitToSequence( + _SplitToSequence.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _SplitToSequence.Inputs( + input=unwrap_vars(input), + split=unwrap_vars(split), + ), + ) + .get_output_vars( + input=get_value(input), + split=get_value(split), + ) + .output_sequence + ) def sqrt( @@ -14956,14 +15568,18 @@ def sqrt( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Sqrt( - _Sqrt.Attributes(), - _Sqrt.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Sqrt( + _Sqrt.Attributes(), + _Sqrt.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def squeeze( @@ -15001,16 +15617,20 @@ def squeeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Squeeze( - _Squeeze.Attributes(), - _Squeeze.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["squeezed"] + return ( + _Squeeze( + _Squeeze.Attributes(), + _Squeeze.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .squeezed + ) def string_normalizer( @@ -15065,21 +15685,27 @@ def string_normalizer( Signature: ``ai.onnx@10::StringNormalizer``. """ - return _StringNormalizer( - _StringNormalizer.Attributes( - case_change_action=AttrString( - case_change_action, name="case_change_action" - ), - is_case_sensitive=AttrInt64(is_case_sensitive, name="is_case_sensitive"), - locale=AttrString.maybe(locale, name="locale"), - stopwords=AttrStrings.maybe(stopwords, name="stopwords"), - ), - _StringNormalizer.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _StringNormalizer( + _StringNormalizer.Attributes( + case_change_action=AttrString( + case_change_action, name="case_change_action" + ), + is_case_sensitive=AttrInt64( + is_case_sensitive, name="is_case_sensitive" + ), + locale=AttrString.maybe(locale, name="locale"), + stopwords=AttrStrings.maybe(stopwords, name="stopwords"), + ), + _StringNormalizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def sub( @@ -15119,16 +15745,20 @@ def sub( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Sub( - _Sub.Attributes(), - _Sub.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Sub( + _Sub.Attributes(), + _Sub.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def sum( @@ -15160,14 +15790,18 @@ def sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Sum( - _Sum.Attributes(), - _Sum.Inputs( - data_0=unwrap_vars(data_0), - ), - ).get_output_vars( - data_0=get_value(data_0), - )["sum"] + return ( + _Sum( + _Sum.Attributes(), + _Sum.Inputs( + data_0=unwrap_vars(data_0), + ), + ) + .get_output_vars( + data_0=get_value(data_0), + ) + .sum + ) def tan( @@ -15195,14 +15829,18 @@ def tan( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Tan( - _Tan.Attributes(), - _Tan.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Tan( + _Tan.Attributes(), + _Tan.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def tanh( @@ -15231,14 +15869,18 @@ def tanh( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Tanh( - _Tanh.Attributes(), - _Tanh.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Tanh( + _Tanh.Attributes(), + _Tanh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def tf_idf_vectorizer( @@ -15370,24 +16012,28 @@ def tf_idf_vectorizer( - T: `tensor(int32)`, `tensor(int64)`, `tensor(string)` - T1: `tensor(float)` """ - return _TfIdfVectorizer( - _TfIdfVectorizer.Attributes( - max_gram_length=AttrInt64(max_gram_length, name="max_gram_length"), - max_skip_count=AttrInt64(max_skip_count, name="max_skip_count"), - min_gram_length=AttrInt64(min_gram_length, name="min_gram_length"), - mode=AttrString(mode, name="mode"), - ngram_counts=AttrInt64s(ngram_counts, name="ngram_counts"), - ngram_indexes=AttrInt64s(ngram_indexes, name="ngram_indexes"), - pool_int64s=AttrInt64s.maybe(pool_int64s, name="pool_int64s"), - pool_strings=AttrStrings.maybe(pool_strings, name="pool_strings"), - weights=AttrFloat32s.maybe(weights, name="weights"), - ), - _TfIdfVectorizer.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _TfIdfVectorizer( + _TfIdfVectorizer.Attributes( + max_gram_length=AttrInt64(max_gram_length, name="max_gram_length"), + max_skip_count=AttrInt64(max_skip_count, name="max_skip_count"), + min_gram_length=AttrInt64(min_gram_length, name="min_gram_length"), + mode=AttrString(mode, name="mode"), + ngram_counts=AttrInt64s(ngram_counts, name="ngram_counts"), + ngram_indexes=AttrInt64s(ngram_indexes, name="ngram_indexes"), + pool_int64s=AttrInt64s.maybe(pool_int64s, name="pool_int64s"), + pool_strings=AttrStrings.maybe(pool_strings, name="pool_strings"), + weights=AttrFloat32s.maybe(weights, name="weights"), + ), + _TfIdfVectorizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def thresholded_relu( @@ -15422,16 +16068,20 @@ def thresholded_relu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _ThresholdedRelu( - _ThresholdedRelu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), - _ThresholdedRelu.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _ThresholdedRelu( + _ThresholdedRelu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), + _ThresholdedRelu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def tile( @@ -15468,16 +16118,20 @@ def tile( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - return _Tile( - _Tile.Attributes(), - _Tile.Inputs( - input=unwrap_vars(input), - repeats=unwrap_vars(repeats), - ), - ).get_output_vars( - input=get_value(input), - repeats=get_value(repeats), - )["output"] + return ( + _Tile( + _Tile.Attributes(), + _Tile.Inputs( + input=unwrap_vars(input), + repeats=unwrap_vars(repeats), + ), + ) + .get_output_vars( + input=get_value(input), + repeats=get_value(repeats), + ) + .output + ) def top_k( @@ -15571,7 +16225,7 @@ def top_k( X=get_value(X), K=get_value(K), ) - .values() + ._unpack_to_any() ) @@ -15608,16 +16262,20 @@ def transpose( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Transpose( - _Transpose.Attributes( - perm=AttrInt64s.maybe(perm, name="perm"), - ), - _Transpose.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["transposed"] + return ( + _Transpose( + _Transpose.Attributes( + perm=AttrInt64s.maybe(perm, name="perm"), + ), + _Transpose.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .transposed + ) def trilu( @@ -15673,18 +16331,22 @@ def trilu( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Trilu( - _Trilu.Attributes( - upper=AttrInt64(upper, name="upper"), - ), - _Trilu.Inputs( - input=unwrap_vars(input), - k=unwrap_vars(k), - ), - ).get_output_vars( - input=get_value(input), - k=get_value(k), - )["output"] + return ( + _Trilu( + _Trilu.Attributes( + upper=AttrInt64(upper, name="upper"), + ), + _Trilu.Inputs( + input=unwrap_vars(input), + k=unwrap_vars(k), + ), + ) + .get_output_vars( + input=get_value(input), + k=get_value(k), + ) + .output + ) def unique( @@ -15869,7 +16531,7 @@ def unique( .get_output_vars( X=get_value(X), ) - .values() + ._unpack_to_any() ) @@ -15918,16 +16580,20 @@ def unsqueeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Unsqueeze( - _Unsqueeze.Attributes(), - _Unsqueeze.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["expanded"] + return ( + _Unsqueeze( + _Unsqueeze.Attributes(), + _Unsqueeze.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .expanded + ) def where( @@ -15971,18 +16637,22 @@ def where( - B: `tensor(bool)` - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Where( - _Where.Attributes(), - _Where.Inputs( - condition=unwrap_vars(condition), - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ).get_output_vars( - condition=get_value(condition), - X=get_value(X), - Y=get_value(Y), - )["output"] + return ( + _Where( + _Where.Attributes(), + _Where.Inputs( + condition=unwrap_vars(condition), + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + condition=get_value(condition), + X=get_value(X), + Y=get_value(Y), + ) + .output + ) def xor( @@ -16021,16 +16691,20 @@ def xor( - T: `tensor(bool)` - T1: `tensor(bool)` """ - return _Xor( - _Xor.Attributes(), - _Xor.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Xor( + _Xor.Attributes(), + _Xor.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index 1f191da5..f8de6f33 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -934,16 +934,20 @@ def bitwise_and( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitwiseAnd( - _BitwiseAnd.Attributes(), - _BitwiseAnd.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _BitwiseAnd( + _BitwiseAnd.Attributes(), + _BitwiseAnd.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def bitwise_not( @@ -971,14 +975,18 @@ def bitwise_not( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitwiseNot( - _BitwiseNot.Attributes(), - _BitwiseNot.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _BitwiseNot( + _BitwiseNot.Attributes(), + _BitwiseNot.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def bitwise_or( @@ -1016,16 +1024,20 @@ def bitwise_or( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitwiseOr( - _BitwiseOr.Attributes(), - _BitwiseOr.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _BitwiseOr( + _BitwiseOr.Attributes(), + _BitwiseOr.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def bitwise_xor( @@ -1063,16 +1075,20 @@ def bitwise_xor( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitwiseXor( - _BitwiseXor.Attributes(), - _BitwiseXor.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _BitwiseXor( + _BitwiseXor.Attributes(), + _BitwiseXor.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def center_crop_pad( @@ -1122,18 +1138,22 @@ def center_crop_pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _CenterCropPad( - _CenterCropPad.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - ), - _CenterCropPad.Inputs( - input_data=unwrap_vars(input_data), - shape=unwrap_vars(shape), - ), - ).get_output_vars( - input_data=get_value(input_data), - shape=get_value(shape), - )["output_data"] + return ( + _CenterCropPad( + _CenterCropPad.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + ), + _CenterCropPad.Inputs( + input_data=unwrap_vars(input_data), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + input_data=get_value(input_data), + shape=get_value(shape), + ) + .output_data + ) def col2_im( @@ -1216,22 +1236,26 @@ def col2_im( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Col2Im( - _Col2Im.Attributes( - dilations=AttrInt64s.maybe(dilations, name="dilations"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _Col2Im.Inputs( - input=unwrap_vars(input), - image_shape=unwrap_vars(image_shape), - block_shape=unwrap_vars(block_shape), - ), - ).get_output_vars( - input=get_value(input), - image_shape=get_value(image_shape), - block_shape=get_value(block_shape), - )["output"] + return ( + _Col2Im( + _Col2Im.Attributes( + dilations=AttrInt64s.maybe(dilations, name="dilations"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _Col2Im.Inputs( + input=unwrap_vars(input), + image_shape=unwrap_vars(image_shape), + block_shape=unwrap_vars(block_shape), + ), + ) + .get_output_vars( + input=get_value(input), + image_shape=get_value(image_shape), + block_shape=get_value(block_shape), + ) + .output + ) def group_normalization( @@ -1299,21 +1323,25 @@ def group_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GroupNormalization( - _GroupNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - num_groups=AttrInt64(num_groups, name="num_groups"), - ), - _GroupNormalization.Inputs( - X=unwrap_vars(X), - scale=unwrap_vars(scale), - bias=unwrap_vars(bias), - ), - ).get_output_vars( - X=get_value(X), - scale=get_value(scale), - bias=get_value(bias), - )["Y"] + return ( + _GroupNormalization( + _GroupNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + num_groups=AttrInt64(num_groups, name="num_groups"), + ), + _GroupNormalization.Inputs( + X=unwrap_vars(X), + scale=unwrap_vars(scale), + bias=unwrap_vars(bias), + ), + ) + .get_output_vars( + X=get_value(X), + scale=get_value(scale), + bias=get_value(bias), + ) + .Y + ) def lp_pool( @@ -1424,22 +1452,26 @@ def lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _LpPool( - _LpPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - p=AttrInt64(p, name="p"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _LpPool.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _LpPool( + _LpPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + p=AttrInt64(p, name="p"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _LpPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def mish( @@ -1474,14 +1506,18 @@ def mish( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Mish( - _Mish.Attributes(), - _Mish.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Mish( + _Mish.Attributes(), + _Mish.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def optional_get_element( @@ -1513,14 +1549,18 @@ def optional_get_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _OptionalGetElement( - _OptionalGetElement.Attributes(), - _OptionalGetElement.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _OptionalGetElement( + _OptionalGetElement.Attributes(), + _OptionalGetElement.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def optional_has_element( @@ -1552,14 +1592,18 @@ def optional_has_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - B: `tensor(bool)` """ - return _OptionalHasElement( - _OptionalHasElement.Attributes(), - _OptionalHasElement.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _OptionalHasElement( + _OptionalHasElement.Attributes(), + _OptionalHasElement.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def pad( @@ -1696,22 +1740,26 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), - _Pad.Inputs( - data=unwrap_vars(data), - pads=unwrap_vars(pads), - constant_value=unwrap_vars(constant_value), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), - )["output"] + return ( + _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), + _Pad.Inputs( + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), + ) + .output + ) def reduce_l1( @@ -1767,21 +1815,25 @@ def reduce_l1( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceL1( - _ReduceL1.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceL1( + _ReduceL1.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), ), - ), - _ReduceL1.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + _ReduceL1.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_l2( @@ -1837,21 +1889,25 @@ def reduce_l2( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceL2( - _ReduceL2.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceL2( + _ReduceL2.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceL2.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), - ), - _ReduceL2.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_log_sum( @@ -1908,21 +1964,25 @@ def reduce_log_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceLogSum( - _ReduceLogSum.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceLogSum( + _ReduceLogSum.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), ), - ), - _ReduceLogSum.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + _ReduceLogSum.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_log_sum_exp( @@ -1979,21 +2039,25 @@ def reduce_log_sum_exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceLogSumExp( - _ReduceLogSumExp.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceLogSumExp( + _ReduceLogSumExp.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceLogSumExp.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), - ), - _ReduceLogSumExp.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_max( @@ -2051,21 +2115,25 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReduceMax( - _ReduceMax.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceMax( + _ReduceMax.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), ), - ), - _ReduceMax.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + _ReduceMax.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_mean( @@ -2121,21 +2189,25 @@ def reduce_mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceMean( - _ReduceMean.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceMean( + _ReduceMean.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceMean.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), - ), - _ReduceMean.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_min( @@ -2192,21 +2264,25 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReduceMin( - _ReduceMin.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceMin( + _ReduceMin.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), ), - ), - _ReduceMin.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + _ReduceMin.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_prod( @@ -2262,21 +2338,25 @@ def reduce_prod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceProd( - _ReduceProd.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceProd( + _ReduceProd.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceProd.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), - ), - _ReduceProd.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_sum_square( @@ -2332,21 +2412,25 @@ def reduce_sum_square( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceSumSquare( - _ReduceSumSquare.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceSumSquare( + _ReduceSumSquare.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), ), - ), - _ReduceSumSquare.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + _ReduceSumSquare.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def resize( @@ -2519,36 +2603,41 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Resize( - _Resize.Attributes( - antialias=AttrInt64(antialias, name="antialias"), - axes=AttrInt64s.maybe(axes, name="axes"), - coordinate_transformation_mode=AttrString( - coordinate_transformation_mode, name="coordinate_transformation_mode" - ), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32( - extrapolation_value, name="extrapolation_value" + return ( + _Resize( + _Resize.Attributes( + antialias=AttrInt64(antialias, name="antialias"), + axes=AttrInt64s.maybe(axes, name="axes"), + coordinate_transformation_mode=AttrString( + coordinate_transformation_mode, + name="coordinate_transformation_mode", + ), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32( + extrapolation_value, name="extrapolation_value" + ), + keep_aspect_ratio_policy=AttrString( + keep_aspect_ratio_policy, name="keep_aspect_ratio_policy" + ), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), ), - keep_aspect_ratio_policy=AttrString( - keep_aspect_ratio_policy, name="keep_aspect_ratio_policy" + _Resize.Inputs( + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), ), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), - _Resize.Inputs( - X=unwrap_vars(X), - roi=unwrap_vars(roi), - scales=unwrap_vars(scales), - sizes=unwrap_vars(sizes), - ), - ).get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), - )["Y"] + ) + .get_output_vars( + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), + ) + .Y + ) def scatter_elements( @@ -2674,21 +2763,25 @@ def scatter_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _ScatterElements( - _ScatterElements.Attributes( - axis=AttrInt64(axis, name="axis"), - reduction=AttrString(reduction, name="reduction"), - ), - _ScatterElements.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - updates=unwrap_vars(updates), - ), - ).get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), - )["output"] + return ( + _ScatterElements( + _ScatterElements.Attributes( + axis=AttrInt64(axis, name="axis"), + reduction=AttrString(reduction, name="reduction"), + ), + _ScatterElements.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), + ) + .output + ) def scatter_nd( @@ -2816,20 +2909,24 @@ def scatter_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ScatterND( - _ScatterND.Attributes( - reduction=AttrString(reduction, name="reduction"), - ), - _ScatterND.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - updates=unwrap_vars(updates), - ), - ).get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), - )["output"] + return ( + _ScatterND( + _ScatterND.Attributes( + reduction=AttrString(reduction, name="reduction"), + ), + _ScatterND.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), + ) + .output + ) def split( @@ -2879,20 +2976,24 @@ def split( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Split( - _Split.Attributes( - axis=AttrInt64(axis, name="axis"), - num_outputs=AttrInt64.maybe(num_outputs, name="num_outputs"), - ), - _Split.Inputs( - input=unwrap_vars(input), - split=unwrap_vars(split), - ), - out_variadic=num_outputs, - ).get_output_vars( - input=get_value(input), - split=get_value(split), - )["outputs"] + return ( + _Split( + _Split.Attributes( + axis=AttrInt64(axis, name="axis"), + num_outputs=AttrInt64.maybe(num_outputs, name="num_outputs"), + ), + _Split.Inputs( + input=unwrap_vars(input), + split=unwrap_vars(split), + ), + out_variadic=num_outputs, + ) + .get_output_vars( + input=get_value(input), + split=get_value(split), + ) + .outputs + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 8cf8cce4..8fc23f65 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -916,22 +916,28 @@ def average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _AveragePool( - _AveragePool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - count_include_pad=AttrInt64(count_include_pad, name="count_include_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _AveragePool.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _AveragePool( + _AveragePool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + count_include_pad=AttrInt64( + count_include_pad, name="count_include_pad" + ), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _AveragePool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def cast( @@ -1055,17 +1061,21 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Cast( - _Cast.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - to=AttrDtype(to, name="to"), - ), - _Cast.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Cast( + _Cast.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + to=AttrDtype(to, name="to"), + ), + _Cast.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def cast_like( @@ -1111,18 +1121,22 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _CastLike( - _CastLike.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - ), - _CastLike.Inputs( - input=unwrap_vars(input), - target_type=unwrap_vars(target_type), - ), - ).get_output_vars( - input=get_value(input), - target_type=get_value(target_type), - )["output"] + return ( + _CastLike( + _CastLike.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + ), + _CastLike.Inputs( + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), + ), + ) + .get_output_vars( + input=get_value(input), + target_type=get_value(target_type), + ) + .output + ) def constant( @@ -1180,18 +1194,22 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), - _Constant.Inputs(), - ).get_output_vars()["output"] + return ( + _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), + _Constant.Inputs(), + ) + .get_output_vars() + .output + ) def deform_conv( @@ -1290,29 +1308,33 @@ def deform_conv( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _DeformConv( - _DeformConv.Attributes( - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - offset_group=AttrInt64(offset_group, name="offset_group"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _DeformConv.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - offset=unwrap_vars(offset), - B=unwrap_vars(B), - mask=unwrap_vars(mask), - ), - ).get_output_vars( - X=get_value(X), - W=get_value(W), - offset=get_value(offset), - B=get_value(B), - mask=get_value(mask), - )["Y"] + return ( + _DeformConv( + _DeformConv.Attributes( + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + offset_group=AttrInt64(offset_group, name="offset_group"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _DeformConv.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + offset=unwrap_vars(offset), + B=unwrap_vars(B), + mask=unwrap_vars(mask), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + offset=get_value(offset), + B=get_value(B), + mask=get_value(mask), + ) + .Y + ) def dequantize_linear( @@ -1370,20 +1392,24 @@ def dequantize_linear( - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - return _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _DequantizeLinear.Inputs( - x=unwrap_vars(x), - x_scale=unwrap_vars(x_scale), - x_zero_point=unwrap_vars(x_zero_point), - ), - ).get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - )["y"] + return ( + _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _DequantizeLinear.Inputs( + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + ) + .y + ) def equal( @@ -1422,16 +1448,20 @@ def equal( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - return _Equal( - _Equal.Attributes(), - _Equal.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ).get_output_vars( - A=get_value(A), - B=get_value(B), - )["C"] + return ( + _Equal( + _Equal.Attributes(), + _Equal.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def identity( @@ -1459,14 +1489,18 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Identity( - _Identity.Attributes(), - _Identity.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Identity( + _Identity.Attributes(), + _Identity.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def if_( @@ -1523,18 +1557,22 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - return _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), - _If.Inputs( - cond=unwrap_vars(cond), - ), - out_variadic=len(_else_branch_subgraph.requested_results), - ).get_output_vars( - cond=get_value(cond), - )["outputs"] + return ( + _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), + _If.Inputs( + cond=unwrap_vars(cond), + ), + out_variadic=len(_else_branch_subgraph.requested_results), + ) + .get_output_vars( + cond=get_value(cond), + ) + .outputs + ) def loop( @@ -1718,21 +1756,25 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - return _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), - _Loop.Inputs( - M=unwrap_vars(M), - cond=unwrap_vars(cond), - v_initial=unwrap_vars(v_initial), - ), - out_variadic=len(_body_subgraph.requested_results) - 1, - ).get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), - )["v_final_and_scan_outputs"] + return ( + _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), + _Loop.Inputs( + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), + ), + out_variadic=len(_body_subgraph.requested_results) - 1, + ) + .get_output_vars( + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), + ) + .v_final_and_scan_outputs + ) def pad( @@ -1895,22 +1937,26 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), - _Pad.Inputs( - data=unwrap_vars(data), - pads=unwrap_vars(pads), - constant_value=unwrap_vars(constant_value), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), - )["output"] + return ( + _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), + _Pad.Inputs( + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), + ) + .output + ) def quantize_linear( @@ -1979,21 +2025,25 @@ def quantize_linear( - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - return _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - saturate=AttrInt64(saturate, name="saturate"), - ), - _QuantizeLinear.Inputs( - x=unwrap_vars(x), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ).get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - )["y"] + return ( + _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + saturate=AttrInt64(saturate, name="saturate"), + ), + _QuantizeLinear.Inputs( + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) def reshape( @@ -2047,18 +2097,22 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), - _Reshape.Inputs( - data=unwrap_vars(data), - shape=unwrap_vars(shape), - ), - ).get_output_vars( - data=get_value(data), - shape=get_value(shape), - )["reshaped"] + return ( + _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), + _Reshape.Inputs( + data=unwrap_vars(data), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + data=get_value(data), + shape=get_value(shape), + ) + .reshaped + ) def resize( @@ -2269,36 +2323,41 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Resize( - _Resize.Attributes( - antialias=AttrInt64(antialias, name="antialias"), - axes=AttrInt64s.maybe(axes, name="axes"), - coordinate_transformation_mode=AttrString( - coordinate_transformation_mode, name="coordinate_transformation_mode" - ), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32( - extrapolation_value, name="extrapolation_value" + return ( + _Resize( + _Resize.Attributes( + antialias=AttrInt64(antialias, name="antialias"), + axes=AttrInt64s.maybe(axes, name="axes"), + coordinate_transformation_mode=AttrString( + coordinate_transformation_mode, + name="coordinate_transformation_mode", + ), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32( + extrapolation_value, name="extrapolation_value" + ), + keep_aspect_ratio_policy=AttrString( + keep_aspect_ratio_policy, name="keep_aspect_ratio_policy" + ), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), ), - keep_aspect_ratio_policy=AttrString( - keep_aspect_ratio_policy, name="keep_aspect_ratio_policy" + _Resize.Inputs( + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), ), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), - _Resize.Inputs( - X=unwrap_vars(X), - roi=unwrap_vars(roi), - scales=unwrap_vars(scales), - sizes=unwrap_vars(sizes), - ), - ).get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), - )["Y"] + ) + .get_output_vars( + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), + ) + .Y + ) def scan( @@ -2522,28 +2581,36 @@ def scan( ], body, ) - return _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), - scan_input_directions=AttrInt64s.maybe( - scan_input_directions, name="scan_input_directions" - ), - scan_output_axes=AttrInt64s.maybe( - scan_output_axes, name="scan_output_axes" + return ( + _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe( + scan_input_axes, name="scan_input_axes" + ), + scan_input_directions=AttrInt64s.maybe( + scan_input_directions, name="scan_input_directions" + ), + scan_output_axes=AttrInt64s.maybe( + scan_output_axes, name="scan_output_axes" + ), + scan_output_directions=AttrInt64s.maybe( + scan_output_directions, name="scan_output_directions" + ), ), - scan_output_directions=AttrInt64s.maybe( - scan_output_directions, name="scan_output_directions" + _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars( + initial_state_and_scan_inputs + ), ), - ), - _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), - ), - out_variadic=len(_body_subgraph.requested_results), - ).get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), - )["final_state_and_scan_outputs"] + out_variadic=len(_body_subgraph.requested_results), + ) + .get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + ) + .final_state_and_scan_outputs + ) def shape( @@ -2622,17 +2689,21 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - return _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), - _Shape.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["shape"] + return ( + _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), + _Shape.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .shape + ) def size( @@ -2662,14 +2733,18 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - return _Size( - _Size.Attributes(), - _Size.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["size"] + return ( + _Size( + _Size.Attributes(), + _Size.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .size + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index e9bdebf9..0e1d406a 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -733,18 +733,22 @@ def affine_grid( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - return _AffineGrid( - _AffineGrid.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - ), - _AffineGrid.Inputs( - theta=unwrap_vars(theta), - size=unwrap_vars(size), - ), - ).get_output_vars( - theta=get_value(theta), - size=get_value(size), - )["grid"] + return ( + _AffineGrid( + _AffineGrid.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + ), + _AffineGrid.Inputs( + theta=unwrap_vars(theta), + size=unwrap_vars(size), + ), + ) + .get_output_vars( + theta=get_value(theta), + size=get_value(size), + ) + .grid + ) def constant_of_shape( @@ -784,16 +788,20 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), - _ConstantOfShape.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), + _ConstantOfShape.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def dft( @@ -886,21 +894,25 @@ def dft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - return _DFT( - _DFT.Attributes( - inverse=AttrInt64(inverse, name="inverse"), - onesided=AttrInt64(onesided, name="onesided"), - ), - _DFT.Inputs( - input=unwrap_vars(input), - dft_length=unwrap_vars(dft_length), - axis=unwrap_vars(axis), - ), - ).get_output_vars( - input=get_value(input), - dft_length=get_value(dft_length), - axis=get_value(axis), - )["output"] + return ( + _DFT( + _DFT.Attributes( + inverse=AttrInt64(inverse, name="inverse"), + onesided=AttrInt64(onesided, name="onesided"), + ), + _DFT.Inputs( + input=unwrap_vars(input), + dft_length=unwrap_vars(dft_length), + axis=unwrap_vars(axis), + ), + ) + .get_output_vars( + input=get_value(input), + dft_length=get_value(dft_length), + axis=get_value(axis), + ) + .output + ) def gelu( @@ -941,16 +953,20 @@ def gelu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Gelu( - _Gelu.Attributes( - approximate=AttrString(approximate, name="approximate"), - ), - _Gelu.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _Gelu( + _Gelu.Attributes( + approximate=AttrString(approximate, name="approximate"), + ), + _Gelu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def grid_sample( @@ -1055,20 +1071,24 @@ def grid_sample( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GridSample( - _GridSample.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - mode=AttrString(mode, name="mode"), - padding_mode=AttrString(padding_mode, name="padding_mode"), - ), - _GridSample.Inputs( - X=unwrap_vars(X), - grid=unwrap_vars(grid), - ), - ).get_output_vars( - X=get_value(X), - grid=get_value(grid), - )["Y"] + return ( + _GridSample( + _GridSample.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + mode=AttrString(mode, name="mode"), + padding_mode=AttrString(padding_mode, name="padding_mode"), + ), + _GridSample.Inputs( + X=unwrap_vars(X), + grid=unwrap_vars(grid), + ), + ) + .get_output_vars( + X=get_value(X), + grid=get_value(grid), + ) + .Y + ) def image_decoder( @@ -1129,16 +1149,20 @@ def image_decoder( - T1: `tensor(uint8)` - T2: `tensor(uint8)` """ - return _ImageDecoder( - _ImageDecoder.Attributes( - pixel_format=AttrString(pixel_format, name="pixel_format"), - ), - _ImageDecoder.Inputs( - encoded_stream=unwrap_vars(encoded_stream), - ), - ).get_output_vars( - encoded_stream=get_value(encoded_stream), - )["image"] + return ( + _ImageDecoder( + _ImageDecoder.Attributes( + pixel_format=AttrString(pixel_format, name="pixel_format"), + ), + _ImageDecoder.Inputs( + encoded_stream=unwrap_vars(encoded_stream), + ), + ) + .get_output_vars( + encoded_stream=get_value(encoded_stream), + ) + .image + ) def isinf( @@ -1180,17 +1204,21 @@ def isinf( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - T2: `tensor(bool)` """ - return _IsInf( - _IsInf.Attributes( - detect_negative=AttrInt64(detect_negative, name="detect_negative"), - detect_positive=AttrInt64(detect_positive, name="detect_positive"), - ), - _IsInf.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _IsInf( + _IsInf.Attributes( + detect_negative=AttrInt64(detect_negative, name="detect_negative"), + detect_positive=AttrInt64(detect_positive, name="detect_positive"), + ), + _IsInf.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def isnan( @@ -1219,14 +1247,18 @@ def isnan( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - T2: `tensor(bool)` """ - return _IsNaN( - _IsNaN.Attributes(), - _IsNaN.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _IsNaN( + _IsNaN.Attributes(), + _IsNaN.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def reduce_max( @@ -1287,21 +1319,25 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReduceMax( - _ReduceMax.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceMax( + _ReduceMax.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), ), - ), - _ReduceMax.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + _ReduceMax.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def reduce_min( @@ -1361,21 +1397,25 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReduceMin( - _ReduceMin.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" + return ( + _ReduceMin( + _ReduceMin.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceMin.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), ), - ), - _ReduceMin.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["reduced"] + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) def regex_full_match( @@ -1414,16 +1454,20 @@ def regex_full_match( - T1: `tensor(string)` - T2: `tensor(bool)` """ - return _RegexFullMatch( - _RegexFullMatch.Attributes( - pattern=AttrString.maybe(pattern, name="pattern"), - ), - _RegexFullMatch.Inputs( - X=unwrap_vars(X), - ), - ).get_output_vars( - X=get_value(X), - )["Y"] + return ( + _RegexFullMatch( + _RegexFullMatch.Attributes( + pattern=AttrString.maybe(pattern, name="pattern"), + ), + _RegexFullMatch.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) def string_concat( @@ -1456,16 +1500,20 @@ def string_concat( Type constraints: - T: `tensor(string)` """ - return _StringConcat( - _StringConcat.Attributes(), - _StringConcat.Inputs( - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ).get_output_vars( - X=get_value(X), - Y=get_value(Y), - )["Z"] + return ( + _StringConcat( + _StringConcat.Attributes(), + _StringConcat.Inputs( + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + X=get_value(X), + Y=get_value(Y), + ) + .Z + ) def string_split( @@ -1550,7 +1598,7 @@ def string_split( .get_output_vars( X=get_value(X), ) - .values() + ._unpack_to_any() ) diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 1f7110aa..52e3027a 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -964,17 +964,21 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Cast( - _Cast.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - to=AttrDtype(to, name="to"), - ), - _Cast.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Cast( + _Cast.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + to=AttrDtype(to, name="to"), + ), + _Cast.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def cast_like( @@ -1020,18 +1024,22 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _CastLike( - _CastLike.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - ), - _CastLike.Inputs( - input=unwrap_vars(input), - target_type=unwrap_vars(target_type), - ), - ).get_output_vars( - input=get_value(input), - target_type=get_value(target_type), - )["output"] + return ( + _CastLike( + _CastLike.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + ), + _CastLike.Inputs( + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), + ), + ) + .get_output_vars( + input=get_value(input), + target_type=get_value(target_type), + ) + .output + ) def constant( @@ -1089,18 +1097,22 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), - _Constant.Inputs(), - ).get_output_vars()["output"] + return ( + _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), + _Constant.Inputs(), + ) + .get_output_vars() + .output + ) def constant_of_shape( @@ -1140,16 +1152,20 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), - _ConstantOfShape.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), + _ConstantOfShape.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def dequantize_linear( @@ -1220,21 +1236,25 @@ def dequantize_linear( - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - return _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - block_size=AttrInt64(block_size, name="block_size"), - ), - _DequantizeLinear.Inputs( - x=unwrap_vars(x), - x_scale=unwrap_vars(x_scale), - x_zero_point=unwrap_vars(x_zero_point), - ), - ).get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - )["y"] + return ( + _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + block_size=AttrInt64(block_size, name="block_size"), + ), + _DequantizeLinear.Inputs( + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + ) + .y + ) def flatten( @@ -1276,16 +1296,20 @@ def flatten( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Flatten( - _Flatten.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Flatten.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Flatten( + _Flatten.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Flatten.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def group_normalization( @@ -1367,22 +1391,26 @@ def group_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GroupNormalization( - _GroupNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - num_groups=AttrInt64(num_groups, name="num_groups"), - stash_type=AttrInt64(stash_type, name="stash_type"), - ), - _GroupNormalization.Inputs( - X=unwrap_vars(X), - scale=unwrap_vars(scale), - bias=unwrap_vars(bias), - ), - ).get_output_vars( - X=get_value(X), - scale=get_value(scale), - bias=get_value(bias), - )["Y"] + return ( + _GroupNormalization( + _GroupNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + num_groups=AttrInt64(num_groups, name="num_groups"), + stash_type=AttrInt64(stash_type, name="stash_type"), + ), + _GroupNormalization.Inputs( + X=unwrap_vars(X), + scale=unwrap_vars(scale), + bias=unwrap_vars(bias), + ), + ) + .get_output_vars( + X=get_value(X), + scale=get_value(scale), + bias=get_value(bias), + ) + .Y + ) def identity( @@ -1410,14 +1438,18 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Identity( - _Identity.Attributes(), - _Identity.Inputs( - input=unwrap_vars(input), - ), - ).get_output_vars( - input=get_value(input), - )["output"] + return ( + _Identity( + _Identity.Attributes(), + _Identity.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) def if_( @@ -1474,18 +1506,22 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - return _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), - _If.Inputs( - cond=unwrap_vars(cond), - ), - out_variadic=len(_else_branch_subgraph.requested_results), - ).get_output_vars( - cond=get_value(cond), - )["outputs"] + return ( + _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), + _If.Inputs( + cond=unwrap_vars(cond), + ), + out_variadic=len(_else_branch_subgraph.requested_results), + ) + .get_output_vars( + cond=get_value(cond), + ) + .outputs + ) def loop( @@ -1669,21 +1705,25 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - return _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), - _Loop.Inputs( - M=unwrap_vars(M), - cond=unwrap_vars(cond), - v_initial=unwrap_vars(v_initial), - ), - out_variadic=len(_body_subgraph.requested_results) - 1, - ).get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), - )["v_final_and_scan_outputs"] + return ( + _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), + _Loop.Inputs( + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), + ), + out_variadic=len(_body_subgraph.requested_results) - 1, + ) + .get_output_vars( + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), + ) + .v_final_and_scan_outputs + ) def pad( @@ -1846,22 +1886,26 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - return _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), - _Pad.Inputs( - data=unwrap_vars(data), - pads=unwrap_vars(pads), - constant_value=unwrap_vars(constant_value), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), - )["output"] + return ( + _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), + _Pad.Inputs( + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), + ) + .output + ) def qlinear_matmul( @@ -1937,28 +1981,32 @@ def qlinear_matmul( - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` - T3: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - return _QLinearMatMul( - _QLinearMatMul.Attributes(), - _QLinearMatMul.Inputs( - a=unwrap_vars(a), - a_scale=unwrap_vars(a_scale), - a_zero_point=unwrap_vars(a_zero_point), - b=unwrap_vars(b), - b_scale=unwrap_vars(b_scale), - b_zero_point=unwrap_vars(b_zero_point), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ).get_output_vars( - a=get_value(a), - a_scale=get_value(a_scale), - a_zero_point=get_value(a_zero_point), - b=get_value(b), - b_scale=get_value(b_scale), - b_zero_point=get_value(b_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - )["y"] + return ( + _QLinearMatMul( + _QLinearMatMul.Attributes(), + _QLinearMatMul.Inputs( + a=unwrap_vars(a), + a_scale=unwrap_vars(a_scale), + a_zero_point=unwrap_vars(a_zero_point), + b=unwrap_vars(b), + b_scale=unwrap_vars(b_scale), + b_zero_point=unwrap_vars(b_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + a=get_value(a), + a_scale=get_value(a_scale), + a_zero_point=get_value(a_zero_point), + b=get_value(b), + b_scale=get_value(b_scale), + b_zero_point=get_value(b_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) def quantize_linear( @@ -2066,23 +2114,27 @@ def quantize_linear( - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` """ - return _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - block_size=AttrInt64(block_size, name="block_size"), - output_dtype=AttrInt64(output_dtype, name="output_dtype"), - saturate=AttrInt64(saturate, name="saturate"), - ), - _QuantizeLinear.Inputs( - x=unwrap_vars(x), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ).get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - )["y"] + return ( + _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + block_size=AttrInt64(block_size, name="block_size"), + output_dtype=AttrInt64(output_dtype, name="output_dtype"), + saturate=AttrInt64(saturate, name="saturate"), + ), + _QuantizeLinear.Inputs( + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) def reshape( @@ -2136,18 +2188,22 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), - _Reshape.Inputs( - data=unwrap_vars(data), - shape=unwrap_vars(shape), - ), - ).get_output_vars( - data=get_value(data), - shape=get_value(shape), - )["reshaped"] + return ( + _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), + _Reshape.Inputs( + data=unwrap_vars(data), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + data=get_value(data), + shape=get_value(shape), + ) + .reshaped + ) def scan( @@ -2371,28 +2427,36 @@ def scan( ], body, ) - return _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), - scan_input_directions=AttrInt64s.maybe( - scan_input_directions, name="scan_input_directions" - ), - scan_output_axes=AttrInt64s.maybe( - scan_output_axes, name="scan_output_axes" + return ( + _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe( + scan_input_axes, name="scan_input_axes" + ), + scan_input_directions=AttrInt64s.maybe( + scan_input_directions, name="scan_input_directions" + ), + scan_output_axes=AttrInt64s.maybe( + scan_output_axes, name="scan_output_axes" + ), + scan_output_directions=AttrInt64s.maybe( + scan_output_directions, name="scan_output_directions" + ), ), - scan_output_directions=AttrInt64s.maybe( - scan_output_directions, name="scan_output_directions" + _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars( + initial_state_and_scan_inputs + ), ), - ), - _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), - ), - out_variadic=len(_body_subgraph.requested_results), - ).get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), - )["final_state_and_scan_outputs"] + out_variadic=len(_body_subgraph.requested_results), + ) + .get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + ) + .final_state_and_scan_outputs + ) def shape( @@ -2471,17 +2535,21 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - return _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), - _Shape.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["shape"] + return ( + _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), + _Shape.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .shape + ) def size( @@ -2511,14 +2579,18 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - return _Size( - _Size.Attributes(), - _Size.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["size"] + return ( + _Size( + _Size.Attributes(), + _Size.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .size + ) def squeeze( @@ -2556,16 +2628,20 @@ def squeeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Squeeze( - _Squeeze.Attributes(), - _Squeeze.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["squeezed"] + return ( + _Squeeze( + _Squeeze.Attributes(), + _Squeeze.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .squeezed + ) def transpose( @@ -2602,16 +2678,20 @@ def transpose( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Transpose( - _Transpose.Attributes( - perm=AttrInt64s.maybe(perm, name="perm"), - ), - _Transpose.Inputs( - data=unwrap_vars(data), - ), - ).get_output_vars( - data=get_value(data), - )["transposed"] + return ( + _Transpose( + _Transpose.Attributes( + perm=AttrInt64s.maybe(perm, name="perm"), + ), + _Transpose.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .transposed + ) def unsqueeze( @@ -2659,16 +2739,20 @@ def unsqueeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Unsqueeze( - _Unsqueeze.Attributes(), - _Unsqueeze.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ).get_output_vars( - data=get_value(data), - axes=get_value(axes), - )["expanded"] + return ( + _Unsqueeze( + _Unsqueeze.Attributes(), + _Unsqueeze.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .expanded + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: diff --git a/tests/test_adapt.py b/tests/test_adapt.py index d3b01a06..25c47646 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -97,10 +97,14 @@ class Outputs(BaseOutputs): def squeeze11(_data: Var, _axes: Iterable[int]): - return Squeeze11( - Squeeze11.Attributes(AttrInt64s(_axes, "axes")), - Squeeze11.Inputs(_data._var_info), - ).get_output_vars()["squeezed"] + return ( + Squeeze11( + Squeeze11.Attributes(AttrInt64s(_axes, "axes")), + Squeeze11.Inputs(_data._var_info), + ) + .get_output_vars() + .squeezed + ) @pytest.fixture diff --git a/tests/test_custom_operator.py b/tests/test_custom_operator.py index 752a17f3..fc102a8e 100644 --- a/tests/test_custom_operator.py +++ b/tests/test_custom_operator.py @@ -67,9 +67,11 @@ def propagate_values(self, initializers) -> dict[str, np.ndarray]: # Define the operator constructor which is actually used def inverse(matrix: Var) -> Var: - return Inverse( - Inverse.Attributes(), Inverse.Inputs(matrix._var_info) - ).get_output_vars(X=matrix._value)["Y"] + return ( + Inverse(Inverse.Attributes(), Inverse.Inputs(matrix._var_info)) + .get_output_vars(X=matrix._value) + .Y + ) # Test the correct runtime behaviour with ORT diff --git a/tests/test_function.py b/tests/test_function.py index 7e78ef2e..ce6ec4ca 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -62,13 +62,17 @@ def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: def linear_inner( x: Var, a: Union[float, _Ref[float]], b: Union[float, _Ref[float]] ) -> Var: - return LinearFunction( - LinearFunction.Attributes( - slope_outer=AttrFloat32(a, "slope_outer"), - shift_outer=AttrFloat32(b, "shift_outer"), - ), - LinearFunction.Inputs(x._var_info), - ).get_output_vars(X=x._value)["Y"] + return ( + LinearFunction( + LinearFunction.Attributes( + slope_outer=AttrFloat32(a, "slope_outer"), + shift_outer=AttrFloat32(b, "shift_outer"), + ), + LinearFunction.Inputs(x._var_info), + ) + .get_output_vars(X=x._value) + .Y + ) return linear_inner @@ -107,12 +111,17 @@ def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: def linear_inner( x: Var, a: Union[float, _Ref[float]], b: Union[float, _Ref[float]] ) -> Var: - return LinearFunction2( - LinearFunction2.Attributes( - slope1=AttrFloat32(a, name="slope1"), shift1=AttrFloat32(b, "shift1") - ), - LinearFunction2.Inputs(x._var_info), - ).get_output_vars(X=x._value)["Y"] + return ( + LinearFunction2( + LinearFunction2.Attributes( + slope1=AttrFloat32(a, name="slope1"), + shift1=AttrFloat32(b, "shift1"), + ), + LinearFunction2.Inputs(x._var_info), + ) + .get_output_vars(X=x._value) + .Y + ) return linear_inner @@ -168,15 +177,19 @@ def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: return self.Outputs(y._var_info) def cubic_inner(x: Var, a3: float, a2: float, a1: float, a0: float) -> Var: - return CubicFunction( - CubicFunction.Attributes( - a3=AttrFloat32(a3, name="a3"), - a2=AttrFloat32(a2, name="a2"), - a1=AttrFloat32(a1, name="a1"), - a0=AttrFloat32(a0, name="a0"), - ), - CubicFunction.Inputs(X=x._var_info), - ).get_output_vars()["Y"] + return ( + CubicFunction( + CubicFunction.Attributes( + a3=AttrFloat32(a3, name="a3"), + a2=AttrFloat32(a2, name="a2"), + a1=AttrFloat32(a1, name="a1"), + a0=AttrFloat32(a0, name="a0"), + ), + CubicFunction.Inputs(X=x._var_info), + ) + .get_output_vars() + .Y + ) return cubic_inner diff --git a/tests/test_value_propagation.py b/tests/test_value_propagation.py index 30cc678a..06a19550 100644 --- a/tests/test_value_propagation.py +++ b/tests/test_value_propagation.py @@ -12,8 +12,8 @@ from spox import Var, _type_system from spox._graph import arguments, results from spox._shape import Shape -from spox._var import VarInfo from spox._value_prop import ORTValue, PropValue +from spox._var import VarInfo @pytest.fixture( diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index f0225a51..e57f6c54 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -42,6 +42,6 @@ endif %}).get_output_vars( endfor %} ){% if schema.outputs | length <= 1 - %}["{{ schema.outputs[0].name }}"]{% -else %}.values(){% + %}.{{ schema.outputs[0].name }}{% +else %}._unpack_to_any(){% endif %} From f5af5d95c7a5ed7771b505dcd35d8eccafae2937 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Tue, 5 Nov 2024 17:04:54 +0200 Subject: [PATCH 09/29] More initializers --- src/spox/_fields.py | 2 +- src/spox/_function.py | 11 +- src/spox/_inline.py | 2 +- src/spox/_internal_op.py | 6 +- src/spox/_node.py | 10 +- src/spox/_standard.py | 21 +- src/spox/opset/ai/onnx/ml/v3.py | 2654 ++-- src/spox/opset/ai/onnx/ml/v4.py | 306 +- src/spox/opset/ai/onnx/ml/v5.py | 372 +- src/spox/opset/ai/onnx/v17.py | 23063 +++++++++++++----------------- src/spox/opset/ai/onnx/v18.py | 4196 +++--- src/spox/opset/ai/onnx/v19.py | 3973 +++-- src/spox/opset/ai/onnx/v20.py | 2236 ++- src/spox/opset/ai/onnx/v21.py | 3887 +++-- tests/test_custom_operator.py | 2 +- tests/test_function.py | 2 +- tools/templates/class.jinja2 | 2 +- 17 files changed, 17799 insertions(+), 22946 deletions(-) diff --git a/src/spox/_fields.py b/src/spox/_fields.py index 1286b55e..03ae7419 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -7,6 +7,7 @@ from collections.abc import Iterable, Iterator, Sequence from dataclasses import dataclass from typing import Any, Optional, Union +from typing_extensions import Self from ._attributes import Attr from ._exceptions import InferenceWarning @@ -190,7 +191,6 @@ def vars(self, prop_values) -> Vars: return self.Vars(**vars_structure) - @dataclass class BaseOutputs(BaseVarInfos, metaclass=BaseVarsMeta): @dataclass diff --git a/src/spox/_function.py b/src/spox/_function.py index 16a106b8..98654111 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -61,7 +61,7 @@ def constructor(self, attrs, inputs): f"Function {type(self).__name__} does not implement a constructor." ) - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: from . import _graph func_args_var = _graph.arguments_dict( @@ -147,7 +147,7 @@ class Attributes(BaseAttributes): op_type = OpType(name, domain, version) def constructor(self, attrs, inputs): - return self.Outputs(*fun(*inputs.get_fields().values())) + return self.Outputs(*unwrap_vars(fun(*wrap_vars(inputs.get_fields().values())))) return _Func @@ -192,11 +192,12 @@ def init(*args: Var): def alt_fun(*args: Var) -> Iterable[Var]: cls = init(*args) - return wrap_vars( - cls(cls.Attributes(), cls.Inputs(*unwrap_vars(args))) + return [ + Var(var_info) + for var_info in cls(cls.Attributes(), cls.Inputs(*unwrap_vars(args))) .outputs.get_fields() .values() - ) + ] return alt_fun # type: ignore diff --git a/src/spox/_inline.py b/src/spox/_inline.py index b8bf407d..6c0356f3 100644 --- a/src/spox/_inline.py +++ b/src/spox/_inline.py @@ -111,7 +111,7 @@ def opset_req(self) -> set[tuple[str, int]]: ("", INTERNAL_MIN_OPSET) } - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: # First, type check that we match the ModelProto type requirements for i, var in zip(self.graph.input, self.inputs.inputs): if var.type is not None and not ( diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index 835c451b..7ed71b01 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -88,7 +88,7 @@ def post_init(self, **kwargs): if self.attrs.name is not None: self.outputs.arg._rename(self.attrs.name.value) - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: # Output type is based on the value of the type attribute return {"arg": self.attrs.type.value} @@ -121,7 +121,7 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: # Output type is based on the value of the type attribute arr = self.attrs.value.value return {"arg": Tensor(arr.dtype, arr.shape)} @@ -161,7 +161,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: return { f"outputs_{i}": arr.type for i, arr in enumerate(self.inputs.inputs) diff --git a/src/spox/_node.py b/src/spox/_node.py index 85d0ba31..de40b7d7 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -95,7 +95,7 @@ def __init__( out_variadic: Optional[int] = None, infer_types: bool = True, validate: bool = True, - initializers=[], + initializers={}, **kwargs, ): """ @@ -127,7 +127,7 @@ def __init__( # As inference functions may access which output vars we initialized (e.g. variadics) # we inject uninitialized vars first self.outputs = self._init_output_vars() - self.inference(infer_types) + self.inference(infer_types, initializers) else: self.outputs = outputs @@ -215,7 +215,7 @@ def propagate_values(self, initializers) -> dict[str, PropValueType]: """ return {} - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers) -> dict[str, Type]: """ Inference routine for output types. Often overriden by inheriting Node types. @@ -223,10 +223,10 @@ def infer_output_types(self) -> dict[str, Type]: """ return {} - def inference(self, infer_types: bool = True): + def inference(self, infer_types: bool = True, initializers={}): # Type inference routine - call infer_output_types if required # and check if it provides the expected outputs. - out_types = self.infer_output_types() if infer_types else {} + out_types = self.infer_output_types(initializers=initializers) if infer_types else {} for key, var in self.outputs.get_vars().items(): if var.type is None: # If no existing type from init_output_vars diff --git a/src/spox/_standard.py b/src/spox/_standard.py index 531d7afe..9767fb4a 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -6,9 +6,11 @@ from typing import TYPE_CHECKING, Callable import onnx +from onnx.numpy_helper import from_array import onnx.reference import onnx.shape_inference from onnx.defs import OpSchema +import numpy as np from . import _value_prop from ._exceptions import InferenceError @@ -18,6 +20,7 @@ from ._shape import SimpleShape from ._type_system import Optional, Sequence, Tensor, Type from ._value_prop import PropValueType +from ._utils import from_array if TYPE_CHECKING: from ._graph import Graph @@ -48,7 +51,7 @@ def min_output(self) -> int: return self.schema.min_output def to_singleton_onnx_model( - self, *, dummy_outputs: bool = True, with_dummy_subgraphs: bool = True + self, *, dummy_outputs: bool = True, with_dummy_subgraphs: bool = True, prop_values={} ) -> tuple[onnx.ModelProto, Scope]: """ Build a singleton model consisting of just this StandardNode. Used for type inference. @@ -97,7 +100,11 @@ def out_value_info(curr_key, curr_var): ] # Initializers, passed in to allow partial data propagation # - used so that operators like Reshape are aware of constant shapes - initializers = [] + initializers = [ + from_array(prop.value, name) # type: ignore + for name, prop in prop_values.items() + if prop is not None and isinstance(prop.value, np.ndarray) + ] # Graph and model graph = onnx.helper.make_graph( [node_proto], @@ -117,13 +124,13 @@ def out_value_info(curr_key, curr_var): ) return model, scope - def infer_output_types_onnx(self) -> dict[str, Type]: + def infer_output_types_onnx(self, initializers={}) -> dict[str, Type]: """Execute type & shape inference with ``onnx.shape_inference.infer_node_outputs``.""" # Check that all (specified) inputs have known types, as otherwise we fail if any(var.type is None for var in self.inputs.get_vars().values()): return {} - model, _ = self.to_singleton_onnx_model() + model, _ = self.to_singleton_onnx_model(prop_values=initializers) # Attempt to do shape inference - if an error is caught, we extend the traceback a bit try: @@ -161,7 +168,7 @@ def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: if next(iter(self.subgraphs), None) is not None: # Cannot do propagation with subgraphs implicitly for performance - should be reimplemented return {} - model, scope = self.to_singleton_onnx_model(with_dummy_subgraphs=False) + model, scope = self.to_singleton_onnx_model(with_dummy_subgraphs=False, prop_values=initializers) wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() input_feed = { scope.var[var_info]: wrap_feed(initializers[name]) @@ -179,8 +186,8 @@ def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: } return {k: v for k, v in results.items() if k is not None} - def infer_output_types(self) -> dict[str, Type]: - return self.infer_output_types_onnx() + def infer_output_types(self, initializers={}) -> dict[str, Type]: + return self.infer_output_types_onnx(initializers) def propagate_values(self, initializers) -> dict[str, PropValueType]: if _value_prop._VALUE_PROP_BACKEND != _value_prop.ValuePropBackend.NONE: diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index c80ce52d..22fac5aa 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -1,29 +1,39 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: BSD-3-Clause - # ruff: noqa: E741 -- Allow ambiguous variable name -from collections.abc import Iterable, Sequence +import typing +import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( + Any, + Callable, Optional, + Union, ) +from typing import cast as typing_cast import numpy as np +import numpy.typing as npt +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( + AttrDtype, AttrFloat32, AttrFloat32s, + AttrGraph, AttrInt64, AttrInt64s, AttrString, AttrStrings, AttrTensor, + AttrType, ) -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs +from spox._graph import Graph, subgraph +from spox._internal_op import intro from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._value_prop import PropValueType class _ArrayFeatureExtractor(StandardNode): @@ -40,7 +50,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Z: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} xt, yt = self.inputs.X.unwrap_tensor(), self.inputs.Y.unwrap_tensor() @@ -54,14 +64,12 @@ def infer_output_types(self) -> dict[str, Type]: return {"Z": Tensor(xt.dtype, (1, yt.shape[-1]))} shape = tuple(list(xt.shape[:-1]) + [yt.shape[-1]]) # type: ignore return {"Z": Tensor(xt.dtype, shape)} - op_type = OpType("ArrayFeatureExtractor", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs - class _Binarizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -75,16 +83,14 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {} - op_type = OpType("Binarizer", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs - class _CastMap(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -106,7 +112,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _CategoryMapper(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -123,7 +128,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} cats1, cats2 = self.attrs.cats_int64s, self.attrs.cats_strings @@ -134,14 +139,12 @@ def infer_output_types(self) -> dict[str, Type]: t = self.inputs.X.unwrap_tensor() (elem_type,) = {np.int64, np.str_} - {t.dtype.type} # type: ignore return {"Y": Tensor(elem_type, t.shape)} - op_type = OpType("CategoryMapper", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs - class _DictVectorizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -162,7 +165,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _FeatureVectorizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -182,7 +184,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Imputer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -199,26 +200,18 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} t = self.inputs.X.unwrap_tensor() # We verify if the attributes are set correctly and matching the input elem type cases = { - np.int64: ( - self.attrs.imputed_value_int64s, - self.attrs.replaced_value_int64, - ), - np.float32: ( - self.attrs.imputed_value_floats, - self.attrs.replaced_value_float, - ), + np.int64: (self.attrs.imputed_value_int64s, self.attrs.replaced_value_int64), + np.float32: (self.attrs.imputed_value_floats, self.attrs.replaced_value_float) } for key, (imp, rep) in cases.items(): if t.dtype.type is key: - if not all( - imp1 is None for key1, (imp1, rep1) in cases.items() if key != key1 - ): + if not all(imp1 is None for key1, (imp1, rep1) in cases.items() if key != key1): raise InferenceError("Only one input imputed type may be set.") break else: @@ -229,18 +222,14 @@ def infer_output_types(self) -> dict[str, Type]: sim = t.shape last = sim[-1] if sim else 1 if isinstance(last, int) and len(imp.value) not in {1, last}: - raise InferenceError( - f"Mismatched expected ({len(imp.value)}) and actual ({last}) feature count." - ) + raise InferenceError(f"Mismatched expected ({len(imp.value)}) and actual ({last}) feature count.") return {"Y": t} - op_type = OpType("Imputer", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs - class _LabelEncoder(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -268,7 +257,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LinearClassifier(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -294,7 +282,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LinearRegressor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -311,7 +298,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} sim = self.inputs.X.unwrap_tensor().shape @@ -324,14 +311,12 @@ def infer_output_types(self) -> dict[str, Type]: return {"Y": Tensor(np.float32, (1, 1))} else: raise InferenceError("Input shape must be at most a matrix.") - op_type = OpType("LinearRegressor", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs - class _Normalizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -345,20 +330,16 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: if self.attrs.norm.value not in ("MAX", "L1", "L2"): - raise InferenceError( - f"Unknown normalisation method `{self.attrs.norm.value}`" - ) + raise InferenceError(f"Unknown normalisation method `{self.attrs.norm.value}`") return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {} - op_type = OpType("Normalizer", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs - class _OneHotEncoder(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -374,7 +355,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} if self.attrs.cats_int64s: @@ -386,15 +367,15 @@ def infer_output_types(self) -> dict[str, Type]: "Either `cats_int64s` or `cats_strings` attributes must be set." ) shape = (*self.inputs.X.unwrap_tensor().shape, n_encodings) # type: ignore - return {"Y": Tensor(dtype=np.float32, shape=shape)} - + return { + "Y": Tensor(dtype=np.float32, shape=shape) + } op_type = OpType("OneHotEncoder", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs - class _SVMClassifier(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -425,7 +406,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SVMRegressor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -452,7 +432,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Scaler(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -467,7 +446,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: if self.inputs.X.type is None: return {} sc, off = self.attrs.scale, self.attrs.offset @@ -477,22 +456,16 @@ def infer_output_types(self) -> dict[str, Type]: # If the number of features is known (last row, we can check this here) last = t.shape[-1] if t.shape else 1 if isinstance(last, int) and len(sc.value) not in {1, last}: - raise InferenceError( - f"Mismatched expected ({len(sc.value)}) and actual ({last}) feature count for scale." - ) + raise InferenceError(f"Mismatched expected ({len(sc.value)}) and actual ({last}) feature count for scale.") if isinstance(last, int) and len(off.value) not in {1, last}: - raise InferenceError( - f"Mismatched expected ({len(off.value)}) and actual ({last}) feature count for offset." - ) + raise InferenceError(f"Mismatched expected ({len(off.value)}) and actual ({last}) feature count for offset.") return {"Y": Tensor(np.float32, t.shape)} - op_type = OpType("Scaler", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs - class _TreeEnsembleClassifier(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -527,7 +500,7 @@ class Outputs(BaseOutputs): Y: VarInfo Z: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: e = ( len(self.attrs.class_ids.value) if self.attrs.class_ids is not None @@ -543,21 +516,19 @@ def infer_output_types(self) -> dict[str, Type]: ) if self.inputs.fully_typed: shape = self.inputs.X.unwrap_tensor().shape - assert shape is not None # already checked with fully_typed + assert shape is not None # already checked with fully_typed if len(shape) != 2: raise InferenceError("Expected input to be a matrix.") n = shape[0] else: n = None return {"Y": Tensor(y_type, (n,)), "Z": Tensor(np.float32, (n, e))} - op_type = OpType("TreeEnsembleClassifier", "ai.onnx.ml", 3) attrs: Attributes inputs: Inputs outputs: Outputs - class _TreeEnsembleRegressor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -591,7 +562,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: if self.inputs.fully_typed: shape = self.inputs.X.unwrap_tensor().shape assert shape is not None # already checked with fully_typed @@ -603,14 +574,12 @@ def infer_output_types(self) -> dict[str, Type]: n = None e = self.attrs.n_targets.value if self.attrs.n_targets is not None else None return {"Y": Tensor(np.float32, (n, e))} - op_type = OpType("TreeEnsembleRegressor", "ai.onnx.ml", 3) attrs: Attributes inputs: Inputs outputs: Outputs - class _ZipMap(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -631,1518 +600,1137 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs +def array_feature_extractor(X: Var, Y: Var, ) -> Var: + r""" +Select elements of the input tensor based on the indices passed. The +indices are applied to the last axes of the tensor. + +Parameters +========== +X + Type T. + Data to be selected +Y + Type tensor(int64). + The indices, based on 0 as the first index of any dimension. + +Returns +======= +Z : Var + Type T. + Selected output data as an array + +Notes +===== +Signature: ``ai.onnx.ml@1::ArrayFeatureExtractor``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` + """ + return _ArrayFeatureExtractor( + _ArrayFeatureExtractor.Attributes( + ), _ArrayFeatureExtractor.Inputs( + X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( + X=get_value(X), Y=get_value(Y), ).Z + -def array_feature_extractor( - X: Var, - Y: Var, -) -> Var: +def binarizer(X: Var, *, threshold: float = 0.0, ) -> Var: r""" - Select elements of the input tensor based on the indices passed. The - indices are applied to the last axes of the tensor. - - Parameters - ========== - X - Type T. - Data to be selected - Y - Type tensor(int64). - The indices, based on 0 as the first index of any dimension. - - Returns - ======= - Z : Var - Type T. - Selected output data as an array - - Notes - ===== - Signature: ``ai.onnx.ml@1::ArrayFeatureExtractor``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` +Maps the values of the input tensor to either 0 or 1, element-wise, +based on the outcome of a comparison against a threshold value. + +Parameters +========== +X + Type T. + Data to be binarized +threshold + Attribute. + Values greater than this are mapped to 1, others to 0. + +Returns +======= +Y : Var + Type T. + Binarized output data + +Notes +===== +Signature: ``ai.onnx.ml@1::Binarizer``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return ( - _ArrayFeatureExtractor( - _ArrayFeatureExtractor.Attributes(), - _ArrayFeatureExtractor.Inputs( - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ) - .get_output_vars( - X=get_value(X), - Y=get_value(Y), - ) - .Z - ) + return _Binarizer( + _Binarizer.Attributes( + threshold=AttrFloat32(threshold, name="threshold"), + ), _Binarizer.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def binarizer( - X: Var, - *, - threshold: float = 0.0, -) -> Var: +def cast_map(X: Var, *, cast_to: str = "TO_FLOAT", map_form: str = "DENSE", max_map: int = 1, ) -> Var: r""" - Maps the values of the input tensor to either 0 or 1, element-wise, - based on the outcome of a comparison against a threshold value. - - Parameters - ========== - X - Type T. - Data to be binarized - threshold - Attribute. - Values greater than this are mapped to 1, others to 0. - - Returns - ======= - Y : Var - Type T. - Binarized output data - - Notes - ===== - Signature: ``ai.onnx.ml@1::Binarizer``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` +Converts a map to a tensor.The map key must be an int64 and the values +will be ordered in ascending order based on this key.The operator +supports dense packing or sparse packing. If using sparse packing, the +key cannot exceed the max_map-1 value. + +Parameters +========== +X + Type T1. + The input map that is to be cast to a tensor +cast_to + Attribute. + A string indicating the desired element type of the output tensor, one + of 'TO_FLOAT', 'TO_STRING', 'TO_INT64'. +map_form + Attribute. + Indicates whether to only output as many values as are in the input + (dense), or position the input based on using the key of the map as the + index of the output (sparse).One of 'DENSE', 'SPARSE'. +max_map + Attribute. + If the value of map_form is 'SPARSE,' this attribute indicates the total + length of the output tensor. + +Returns +======= +Y : Var + Type T2. + A tensor representing the same data as the input map, ordered by their + keys + +Notes +===== +Signature: ``ai.onnx.ml@1::CastMap``. + +Type constraints: + - T1: `map(int64,tensor(float))`, `map(int64,tensor(string))` + - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return ( - _Binarizer( - _Binarizer.Attributes( - threshold=AttrFloat32(threshold, name="threshold"), - ), - _Binarizer.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _CastMap( + _CastMap.Attributes( + cast_to=AttrString(cast_to, name="cast_to"), + map_form=AttrString(map_form, name="map_form"), + max_map=AttrInt64(max_map, name="max_map"), + ), _CastMap.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def cast_map( - X: Var, - *, - cast_to: str = "TO_FLOAT", - map_form: str = "DENSE", - max_map: int = 1, -) -> Var: +def category_mapper(X: Var, *, cats_int64s: Optional[Iterable[int]] = None, cats_strings: Optional[Iterable[str]] = None, default_int64: int = -1, default_string: str = "_Unused", ) -> Var: r""" - Converts a map to a tensor.The map key must be an int64 and the values - will be ordered in ascending order based on this key.The operator - supports dense packing or sparse packing. If using sparse packing, the - key cannot exceed the max_map-1 value. - - Parameters - ========== - X - Type T1. - The input map that is to be cast to a tensor - cast_to - Attribute. - A string indicating the desired element type of the output tensor, one - of 'TO_FLOAT', 'TO_STRING', 'TO_INT64'. - map_form - Attribute. - Indicates whether to only output as many values as are in the input - (dense), or position the input based on using the key of the map as the - index of the output (sparse).One of 'DENSE', 'SPARSE'. - max_map - Attribute. - If the value of map_form is 'SPARSE,' this attribute indicates the total - length of the output tensor. - - Returns - ======= - Y : Var - Type T2. - A tensor representing the same data as the input map, ordered by their - keys - - Notes - ===== - Signature: ``ai.onnx.ml@1::CastMap``. - - Type constraints: - - T1: `map(int64,tensor(float))`, `map(int64,tensor(string))` - - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` +Converts strings to integers and vice versa. Two sequences of equal +length are used to map between integers and strings, with strings and +integers at the same index detailing the mapping. Each operator converts +either integers to strings or strings to integers, depending on which +default value attribute is provided. Only one default value attribute +should be defined. If the string default value is set, it will convert +integers to strings. If the int default value is set, it will convert +strings to integers. + +Parameters +========== +X + Type T1. + Input data +cats_int64s + Attribute. + The integers of the map. This sequence must be the same length as the + 'cats_strings' sequence. +cats_strings + Attribute. + The strings of the map. This sequence must be the same length as the + 'cats_int64s' sequence +default_int64 + Attribute. + An integer to use when an input string value is not found in the map.One + and only one of the 'default\_\*' attributes must be defined. +default_string + Attribute. + A string to use when an input integer value is not found in the map.One + and only one of the 'default\_\*' attributes must be defined. + +Returns +======= +Y : Var + Type T2. + Output data. If strings are input, the output values are integers, and + vice versa. + +Notes +===== +Signature: ``ai.onnx.ml@1::CategoryMapper``. + +Type constraints: + - T1: `tensor(int64)`, `tensor(string)` + - T2: `tensor(int64)`, `tensor(string)` """ - return ( - _CastMap( - _CastMap.Attributes( - cast_to=AttrString(cast_to, name="cast_to"), - map_form=AttrString(map_form, name="map_form"), - max_map=AttrInt64(max_map, name="max_map"), - ), - _CastMap.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def category_mapper( - X: Var, - *, - cats_int64s: Optional[Iterable[int]] = None, - cats_strings: Optional[Iterable[str]] = None, - default_int64: int = -1, - default_string: str = "_Unused", -) -> Var: + return _CategoryMapper( + _CategoryMapper.Attributes( + cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), + cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + ), _CategoryMapper.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def dict_vectorizer(X: Var, *, int64_vocabulary: Optional[Iterable[int]] = None, string_vocabulary: Optional[Iterable[str]] = None, ) -> Var: r""" - Converts strings to integers and vice versa. Two sequences of equal - length are used to map between integers and strings, with strings and - integers at the same index detailing the mapping. Each operator converts - either integers to strings or strings to integers, depending on which - default value attribute is provided. Only one default value attribute - should be defined. If the string default value is set, it will convert - integers to strings. If the int default value is set, it will convert - strings to integers. - - Parameters - ========== - X - Type T1. - Input data - cats_int64s - Attribute. - The integers of the map. This sequence must be the same length as the - 'cats_strings' sequence. - cats_strings - Attribute. - The strings of the map. This sequence must be the same length as the - 'cats_int64s' sequence - default_int64 - Attribute. - An integer to use when an input string value is not found in the map.One - and only one of the 'default\_\*' attributes must be defined. - default_string - Attribute. - A string to use when an input integer value is not found in the map.One - and only one of the 'default\_\*' attributes must be defined. - - Returns - ======= - Y : Var - Type T2. - Output data. If strings are input, the output values are integers, and - vice versa. - - Notes - ===== - Signature: ``ai.onnx.ml@1::CategoryMapper``. - - Type constraints: - - T1: `tensor(int64)`, `tensor(string)` - - T2: `tensor(int64)`, `tensor(string)` +Uses an index mapping to convert a dictionary to an array. Given a +dictionary, each key is looked up in the vocabulary attribute +corresponding to the key type. The index into the vocabulary array at +which the key is found is then used to index the output 1-D tensor 'Y' +and insert into it the value found in the dictionary 'X'. The key type +of the input map must correspond to the element type of the defined +vocabulary attribute. Therefore, the output array will be equal in +length to the index mapping vector parameter. All keys in the input +dictionary must be present in the index mapping vector. For each item in +the input dictionary, insert its value in the output array. Any keys not +present in the input dictionary, will be zero in the output array. For +example: if the ``string_vocabulary`` parameter is set to +``["a", "c", "b", "z"]``, then an input of ``{"a": 4, "c": 8}`` will +produce an output of ``[4, 8, 0, 0]``. + +Parameters +========== +X + Type T1. + A dictionary. +int64_vocabulary + Attribute. + An integer vocabulary array.One and only one of the vocabularies must be + defined. +string_vocabulary + Attribute. + A string vocabulary array.One and only one of the vocabularies must be + defined. + +Returns +======= +Y : Var + Type T2. + A 1-D tensor holding values from the input dictionary. + +Notes +===== +Signature: ``ai.onnx.ml@1::DictVectorizer``. + +Type constraints: + - T1: `map(int64,tensor(double))`, `map(int64,tensor(float))`, `map(int64,tensor(string))`, `map(string,tensor(double))`, `map(string,tensor(float))`, `map(string,tensor(int64))` + - T2: `tensor(double)`, `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return ( - _CategoryMapper( - _CategoryMapper.Attributes( - cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), - cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - ), - _CategoryMapper.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _DictVectorizer( + _DictVectorizer.Attributes( + int64_vocabulary=AttrInt64s.maybe(int64_vocabulary, name="int64_vocabulary"), + string_vocabulary=AttrStrings.maybe(string_vocabulary, name="string_vocabulary"), + ), _DictVectorizer.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def dict_vectorizer( - X: Var, - *, - int64_vocabulary: Optional[Iterable[int]] = None, - string_vocabulary: Optional[Iterable[str]] = None, -) -> Var: +def feature_vectorizer(X: Sequence[Var], *, inputdimensions: Optional[Iterable[int]] = None, ) -> Var: r""" - Uses an index mapping to convert a dictionary to an array. Given a - dictionary, each key is looked up in the vocabulary attribute - corresponding to the key type. The index into the vocabulary array at - which the key is found is then used to index the output 1-D tensor 'Y' - and insert into it the value found in the dictionary 'X'. The key type - of the input map must correspond to the element type of the defined - vocabulary attribute. Therefore, the output array will be equal in - length to the index mapping vector parameter. All keys in the input - dictionary must be present in the index mapping vector. For each item in - the input dictionary, insert its value in the output array. Any keys not - present in the input dictionary, will be zero in the output array. For - example: if the ``string_vocabulary`` parameter is set to - ``["a", "c", "b", "z"]``, then an input of ``{"a": 4, "c": 8}`` will - produce an output of ``[4, 8, 0, 0]``. - - Parameters - ========== - X - Type T1. - A dictionary. - int64_vocabulary - Attribute. - An integer vocabulary array.One and only one of the vocabularies must be - defined. - string_vocabulary - Attribute. - A string vocabulary array.One and only one of the vocabularies must be - defined. - - Returns - ======= - Y : Var - Type T2. - A 1-D tensor holding values from the input dictionary. - - Notes - ===== - Signature: ``ai.onnx.ml@1::DictVectorizer``. - - Type constraints: - - T1: `map(int64,tensor(double))`, `map(int64,tensor(float))`, `map(int64,tensor(string))`, `map(string,tensor(double))`, `map(string,tensor(float))`, `map(string,tensor(int64))` - - T2: `tensor(double)`, `tensor(float)`, `tensor(int64)`, `tensor(string)` +Concatenates input tensors into one continuous output. All input shapes +are 2-D and are concatenated along the second dimension. 1-D tensors are +treated as [1,C]. Inputs are copied to the output maintaining the order +of the input arguments. All inputs must be integers or floats, while the +output will be all floating point values. + +Parameters +========== +X + Type T1. + An ordered collection of tensors, all with the same element type. +inputdimensions + Attribute. + The size of each input in the input list + +Returns +======= +Y : Var + Type tensor(float). + The output array, elements ordered as the inputs. + +Notes +===== +Signature: ``ai.onnx.ml@1::FeatureVectorizer``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return ( - _DictVectorizer( - _DictVectorizer.Attributes( - int64_vocabulary=AttrInt64s.maybe( - int64_vocabulary, name="int64_vocabulary" - ), - string_vocabulary=AttrStrings.maybe( - string_vocabulary, name="string_vocabulary" - ), - ), - _DictVectorizer.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _FeatureVectorizer( + _FeatureVectorizer.Attributes( + inputdimensions=AttrInt64s.maybe(inputdimensions, name="inputdimensions"), + ), _FeatureVectorizer.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def feature_vectorizer( - X: Sequence[Var], - *, - inputdimensions: Optional[Iterable[int]] = None, -) -> Var: +def imputer(X: Var, *, imputed_value_floats: Optional[Iterable[float]] = None, imputed_value_int64s: Optional[Iterable[int]] = None, replaced_value_float: float = 0.0, replaced_value_int64: int = 0, ) -> Var: r""" - Concatenates input tensors into one continuous output. All input shapes - are 2-D and are concatenated along the second dimension. 1-D tensors are - treated as [1,C]. Inputs are copied to the output maintaining the order - of the input arguments. All inputs must be integers or floats, while the - output will be all floating point values. - - Parameters - ========== - X - Type T1. - An ordered collection of tensors, all with the same element type. - inputdimensions - Attribute. - The size of each input in the input list - - Returns - ======= - Y : Var - Type tensor(float). - The output array, elements ordered as the inputs. - - Notes - ===== - Signature: ``ai.onnx.ml@1::FeatureVectorizer``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` +Replaces inputs that equal one value with another, leaving all other +elements alone. This operator is typically used to replace missing +values in situations where they have a canonical representation, such as +-1, 0, NaN, or some extreme value. One and only one of +imputed_value_floats or imputed_value_int64s should be defined -- floats +if the input tensor holds floats, integers if the input tensor holds +integers. The imputed values must all fit within the width of the tensor +element type. One and only one of the replaced_value_float or +replaced_value_int64 should be defined, which one depends on whether +floats or integers are being processed. The imputed_value attribute +length can be 1 element, or it can have one element per input feature.In +other words, if the input tensor has the shape [\*,F], then the length +of the attribute array may be 1 or F. If it is 1, then it is broadcast +along the last dimension and applied to each feature. + +Parameters +========== +X + Type T. + Data to be processed. +imputed_value_floats + Attribute. + Value(s) to change to +imputed_value_int64s + Attribute. + Value(s) to change to. +replaced_value_float + Attribute. + A value that needs replacing. +replaced_value_int64 + Attribute. + A value that needs replacing. + +Returns +======= +Y : Var + Type T. + Imputed output data + +Notes +===== +Signature: ``ai.onnx.ml@1::Imputer``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return ( - _FeatureVectorizer( - _FeatureVectorizer.Attributes( - inputdimensions=AttrInt64s.maybe( - inputdimensions, name="inputdimensions" - ), - ), - _FeatureVectorizer.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def imputer( - X: Var, - *, - imputed_value_floats: Optional[Iterable[float]] = None, - imputed_value_int64s: Optional[Iterable[int]] = None, - replaced_value_float: float = 0.0, - replaced_value_int64: int = 0, -) -> Var: + return _Imputer( + _Imputer.Attributes( + imputed_value_floats=AttrFloat32s.maybe(imputed_value_floats, name="imputed_value_floats"), + imputed_value_int64s=AttrInt64s.maybe(imputed_value_int64s, name="imputed_value_int64s"), + replaced_value_float=AttrFloat32(replaced_value_float, name="replaced_value_float"), + replaced_value_int64=AttrInt64(replaced_value_int64, name="replaced_value_int64"), + ), _Imputer.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def label_encoder(X: Var, *, default_float: float = -0.0, default_int64: int = -1, default_string: str = "_Unused", keys_floats: Optional[Iterable[float]] = None, keys_int64s: Optional[Iterable[int]] = None, keys_strings: Optional[Iterable[str]] = None, values_floats: Optional[Iterable[float]] = None, values_int64s: Optional[Iterable[int]] = None, values_strings: Optional[Iterable[str]] = None, ) -> Var: r""" - Replaces inputs that equal one value with another, leaving all other - elements alone. This operator is typically used to replace missing - values in situations where they have a canonical representation, such as - -1, 0, NaN, or some extreme value. One and only one of - imputed_value_floats or imputed_value_int64s should be defined -- floats - if the input tensor holds floats, integers if the input tensor holds - integers. The imputed values must all fit within the width of the tensor - element type. One and only one of the replaced_value_float or - replaced_value_int64 should be defined, which one depends on whether - floats or integers are being processed. The imputed_value attribute - length can be 1 element, or it can have one element per input feature.In - other words, if the input tensor has the shape [\*,F], then the length - of the attribute array may be 1 or F. If it is 1, then it is broadcast - along the last dimension and applied to each feature. - - Parameters - ========== - X - Type T. - Data to be processed. - imputed_value_floats - Attribute. - Value(s) to change to - imputed_value_int64s - Attribute. - Value(s) to change to. - replaced_value_float - Attribute. - A value that needs replacing. - replaced_value_int64 - Attribute. - A value that needs replacing. - - Returns - ======= - Y : Var - Type T. - Imputed output data - - Notes - ===== - Signature: ``ai.onnx.ml@1::Imputer``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` +Maps each element in the input tensor to another value. The mapping is +determined by the two parallel attributes, 'keys\_\ *' and 'values\_*' +attribute. The i-th value in the specified 'keys\_\ *' attribute would +be mapped to the i-th value in the specified 'values\_*' attribute. It +implies that input's element type and the element type of the specified +'keys\_\ *' should be identical while the output type is identical to +the specified 'values\_*' attribute. If an input element can not be +found in the specified 'keys\_\ *' attribute, the 'default\_*' that +matches the specified 'values\_\ *' attribute may be used as its output +value. Let's consider an example which maps a string tensor to an +integer tensor. Assume and 'keys_strings' is ["Amy", "Sally"], +'values_int64s' is [5, 6], and 'default_int64' is '-1'. The input +["Dori", "Amy", "Amy", "Sally", "Sally"] would be mapped to [-1, 5, 5, +6, 6]. Since this operator is an one-to-one mapping, its input and +output shapes are the same. Notice that only one of +'keys\_*'/'values\_\ *' can be set. For key look-up, bit-wise comparison +is used so even a float NaN can be mapped to a value in 'values\_*' +attribute. + +Parameters +========== +X + Type T1. + Input data. It can be either tensor or scalar. +default_float + Attribute. + A float. +default_int64 + Attribute. + An integer. +default_string + Attribute. + A string. +keys_floats + Attribute. + A list of floats. +keys_int64s + Attribute. + A list of ints. +keys_strings + Attribute. + A list of strings. One and only one of 'keys\_\*'s should be set. +values_floats + Attribute. + A list of floats. +values_int64s + Attribute. + A list of ints. +values_strings + Attribute. + A list of strings. One and only one of 'value\_\*'s should be set. + +Returns +======= +Y : Var + Type T2. + Output data. + +Notes +===== +Signature: ``ai.onnx.ml@2::LabelEncoder``. + +Type constraints: + - T1: `tensor(float)`, `tensor(int64)`, `tensor(string)` + - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return ( - _Imputer( - _Imputer.Attributes( - imputed_value_floats=AttrFloat32s.maybe( - imputed_value_floats, name="imputed_value_floats" - ), - imputed_value_int64s=AttrInt64s.maybe( - imputed_value_int64s, name="imputed_value_int64s" - ), - replaced_value_float=AttrFloat32( - replaced_value_float, name="replaced_value_float" - ), - replaced_value_int64=AttrInt64( - replaced_value_int64, name="replaced_value_int64" - ), - ), - _Imputer.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def label_encoder( - X: Var, - *, - default_float: float = -0.0, - default_int64: int = -1, - default_string: str = "_Unused", - keys_floats: Optional[Iterable[float]] = None, - keys_int64s: Optional[Iterable[int]] = None, - keys_strings: Optional[Iterable[str]] = None, - values_floats: Optional[Iterable[float]] = None, - values_int64s: Optional[Iterable[int]] = None, - values_strings: Optional[Iterable[str]] = None, -) -> Var: + return _LabelEncoder( + _LabelEncoder.Attributes( + default_float=AttrFloat32(default_float, name="default_float"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), + keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), + keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), + values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), + values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), + values_strings=AttrStrings.maybe(values_strings, name="values_strings"), + ), _LabelEncoder.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def linear_classifier(X: Var, *, classlabels_ints: Optional[Iterable[int]] = None, classlabels_strings: Optional[Iterable[str]] = None, coefficients: Iterable[float], intercepts: Optional[Iterable[float]] = None, multi_class: int = 0, post_transform: str = "NONE", ) -> tuple[Var, Var]: r""" - Maps each element in the input tensor to another value. The mapping is - determined by the two parallel attributes, 'keys\_\ *' and 'values\_*' - attribute. The i-th value in the specified 'keys\_\ *' attribute would - be mapped to the i-th value in the specified 'values\_*' attribute. It - implies that input's element type and the element type of the specified - 'keys\_\ *' should be identical while the output type is identical to - the specified 'values\_*' attribute. If an input element can not be - found in the specified 'keys\_\ *' attribute, the 'default\_*' that - matches the specified 'values\_\ *' attribute may be used as its output - value. Let's consider an example which maps a string tensor to an - integer tensor. Assume and 'keys_strings' is ["Amy", "Sally"], - 'values_int64s' is [5, 6], and 'default_int64' is '-1'. The input - ["Dori", "Amy", "Amy", "Sally", "Sally"] would be mapped to [-1, 5, 5, - 6, 6]. Since this operator is an one-to-one mapping, its input and - output shapes are the same. Notice that only one of - 'keys\_*'/'values\_\ *' can be set. For key look-up, bit-wise comparison - is used so even a float NaN can be mapped to a value in 'values\_*' - attribute. - - Parameters - ========== - X - Type T1. - Input data. It can be either tensor or scalar. - default_float - Attribute. - A float. - default_int64 - Attribute. - An integer. - default_string - Attribute. - A string. - keys_floats - Attribute. - A list of floats. - keys_int64s - Attribute. - A list of ints. - keys_strings - Attribute. - A list of strings. One and only one of 'keys\_\*'s should be set. - values_floats - Attribute. - A list of floats. - values_int64s - Attribute. - A list of ints. - values_strings - Attribute. - A list of strings. One and only one of 'value\_\*'s should be set. - - Returns - ======= - Y : Var - Type T2. - Output data. - - Notes - ===== - Signature: ``ai.onnx.ml@2::LabelEncoder``. - - Type constraints: - - T1: `tensor(float)`, `tensor(int64)`, `tensor(string)` - - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` +Linear classifier + +Parameters +========== +X + Type T1. + Data to be classified. +classlabels_ints + Attribute. + Class labels when using integer labels. One and only one 'classlabels' + attribute must be defined. +classlabels_strings + Attribute. + Class labels when using string labels. One and only one 'classlabels' + attribute must be defined. +coefficients + Attribute. + A collection of weights of the model(s). +intercepts + Attribute. + A collection of intercepts. +multi_class + Attribute. + Indicates whether to do OvR or multinomial (0=OvR is the default). +post_transform + Attribute. + Indicates the transform to apply to the scores vector.One of 'NONE,' + 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' + +Returns +======= +Y : Var + Type T2. + Classification outputs (one class per example). +Z : Var + Type tensor(float). + Classification scores ([N,E] - one score for each class and example + +Notes +===== +Signature: ``ai.onnx.ml@1::LinearClassifier``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + - T2: `tensor(int64)`, `tensor(string)` """ - return ( - _LabelEncoder( - _LabelEncoder.Attributes( - default_float=AttrFloat32(default_float, name="default_float"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), - keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), - keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), - values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), - values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), - values_strings=AttrStrings.maybe(values_strings, name="values_strings"), - ), - _LabelEncoder.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def linear_classifier( - X: Var, - *, - classlabels_ints: Optional[Iterable[int]] = None, - classlabels_strings: Optional[Iterable[str]] = None, - coefficients: Iterable[float], - intercepts: Optional[Iterable[float]] = None, - multi_class: int = 0, - post_transform: str = "NONE", -) -> tuple[Var, Var]: + return _LinearClassifier( + _LinearClassifier.Attributes( + classlabels_ints=AttrInt64s.maybe(classlabels_ints, name="classlabels_ints"), + classlabels_strings=AttrStrings.maybe(classlabels_strings, name="classlabels_strings"), + coefficients=AttrFloat32s(coefficients, name="coefficients"), + intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), + multi_class=AttrInt64(multi_class, name="multi_class"), + post_transform=AttrString(post_transform, name="post_transform"), + ), _LinearClassifier.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), )._unpack_to_any() + + +def linear_regressor(X: Var, *, coefficients: Optional[Iterable[float]] = None, intercepts: Optional[Iterable[float]] = None, post_transform: str = "NONE", targets: int = 1, ) -> Var: r""" - Linear classifier - - Parameters - ========== - X - Type T1. - Data to be classified. - classlabels_ints - Attribute. - Class labels when using integer labels. One and only one 'classlabels' - attribute must be defined. - classlabels_strings - Attribute. - Class labels when using string labels. One and only one 'classlabels' - attribute must be defined. - coefficients - Attribute. - A collection of weights of the model(s). - intercepts - Attribute. - A collection of intercepts. - multi_class - Attribute. - Indicates whether to do OvR or multinomial (0=OvR is the default). - post_transform - Attribute. - Indicates the transform to apply to the scores vector.One of 'NONE,' - 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' - - Returns - ======= - Y : Var - Type T2. - Classification outputs (one class per example). - Z : Var - Type tensor(float). - Classification scores ([N,E] - one score for each class and example - - Notes - ===== - Signature: ``ai.onnx.ml@1::LinearClassifier``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - - T2: `tensor(int64)`, `tensor(string)` +Generalized linear regression evaluation. If targets is set to 1 +(default) then univariate regression is performed. If targets is set to +M then M sets of coefficients must be passed in as a sequence and M +results will be output for each input n in N. The coefficients array is +of length n, and the coefficients for each target are contiguous. +Intercepts are optional but if provided must match the number of +targets. + +Parameters +========== +X + Type T. + Data to be regressed. +coefficients + Attribute. + Weights of the model(s). +intercepts + Attribute. + Weights of the intercepts, if used. +post_transform + Attribute. + Indicates the transform to apply to the regression output vector.One of + 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' +targets + Attribute. + The total number of regression targets, 1 if not defined. + +Returns +======= +Y : Var + Type tensor(float). + Regression outputs (one per target, per example). + +Notes +===== +Signature: ``ai.onnx.ml@1::LinearRegressor``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return ( - _LinearClassifier( - _LinearClassifier.Attributes( - classlabels_ints=AttrInt64s.maybe( - classlabels_ints, name="classlabels_ints" - ), - classlabels_strings=AttrStrings.maybe( - classlabels_strings, name="classlabels_strings" - ), - coefficients=AttrFloat32s(coefficients, name="coefficients"), - intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), - multi_class=AttrInt64(multi_class, name="multi_class"), - post_transform=AttrString(post_transform, name="post_transform"), - ), - _LinearClassifier.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - ._unpack_to_any() - ) - - -def linear_regressor( - X: Var, - *, - coefficients: Optional[Iterable[float]] = None, - intercepts: Optional[Iterable[float]] = None, - post_transform: str = "NONE", - targets: int = 1, -) -> Var: + return _LinearRegressor( + _LinearRegressor.Attributes( + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), + post_transform=AttrString(post_transform, name="post_transform"), + targets=AttrInt64(targets, name="targets"), + ), _LinearRegressor.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def normalizer(X: Var, *, norm: str = "MAX", ) -> Var: r""" - Generalized linear regression evaluation. If targets is set to 1 - (default) then univariate regression is performed. If targets is set to - M then M sets of coefficients must be passed in as a sequence and M - results will be output for each input n in N. The coefficients array is - of length n, and the coefficients for each target are contiguous. - Intercepts are optional but if provided must match the number of - targets. - - Parameters - ========== - X - Type T. - Data to be regressed. - coefficients - Attribute. - Weights of the model(s). - intercepts - Attribute. - Weights of the intercepts, if used. - post_transform - Attribute. - Indicates the transform to apply to the regression output vector.One of - 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' - targets - Attribute. - The total number of regression targets, 1 if not defined. - - Returns - ======= - Y : Var - Type tensor(float). - Regression outputs (one per target, per example). - - Notes - ===== - Signature: ``ai.onnx.ml@1::LinearRegressor``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` +Normalize the input. There are three normalization modes, which have the +corresponding formulas, defined using element-wise infix operators '/' +and '^' and tensor-wide functions 'max' and 'sum': Max: Y = X / max(X) +L1: Y = X / sum(X) L2: Y = sqrt(X^2 / sum(X^2)} In all modes, if the +divisor is zero, Y == X. For batches, that is, [N,C] tensors, +normalization is done along the C axis. In other words, each row of the +batch is normalized independently. + +Parameters +========== +X + Type T. + Data to be encoded, a tensor of shape [N,C] or [C] +norm + Attribute. + One of 'MAX,' 'L1,' 'L2' + +Returns +======= +Y : Var + Type tensor(float). + Encoded output data + +Notes +===== +Signature: ``ai.onnx.ml@1::Normalizer``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return ( - _LinearRegressor( - _LinearRegressor.Attributes( - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), - post_transform=AttrString(post_transform, name="post_transform"), - targets=AttrInt64(targets, name="targets"), - ), - _LinearRegressor.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _Normalizer( + _Normalizer.Attributes( + norm=AttrString(norm, name="norm"), + ), _Normalizer.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def normalizer( - X: Var, - *, - norm: str = "MAX", -) -> Var: +def one_hot_encoder(X: Var, *, cats_int64s: Optional[Iterable[int]] = None, cats_strings: Optional[Iterable[str]] = None, zeros: int = 1, ) -> Var: r""" - Normalize the input. There are three normalization modes, which have the - corresponding formulas, defined using element-wise infix operators '/' - and '^' and tensor-wide functions 'max' and 'sum': Max: Y = X / max(X) - L1: Y = X / sum(X) L2: Y = sqrt(X^2 / sum(X^2)} In all modes, if the - divisor is zero, Y == X. For batches, that is, [N,C] tensors, - normalization is done along the C axis. In other words, each row of the - batch is normalized independently. - - Parameters - ========== - X - Type T. - Data to be encoded, a tensor of shape [N,C] or [C] - norm - Attribute. - One of 'MAX,' 'L1,' 'L2' - - Returns - ======= - Y : Var - Type tensor(float). - Encoded output data - - Notes - ===== - Signature: ``ai.onnx.ml@1::Normalizer``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` +Replace each input element with an array of ones and zeros, where a +single one is placed at the index of the category that was passed in. +The total category count will determine the size of the extra dimension +of the output array Y. For example, if we pass a tensor with a single +value of 4, and a category count of 8, the output will be a tensor with +``[0,0,0,0,1,0,0,0]``. This operator assumes every input feature is from +the same set of categories. If the input is a tensor of float, int32, or +double, the data will be cast to integers and the cats_int64s category +list will be used for the lookups. + +Parameters +========== +X + Type T. + Data to be encoded. +cats_int64s + Attribute. + List of categories, ints.One and only one of the 'cats\_\*' attributes + must be defined. +cats_strings + Attribute. + List of categories, strings.One and only one of the 'cats\_\*' + attributes must be defined. +zeros + Attribute. + If true and category is not present, will return all zeros; if false and + a category if not found, the operator will fail. + +Returns +======= +Y : Var + Type tensor(float). + Encoded output data, having one more dimension than X. + +Notes +===== +Signature: ``ai.onnx.ml@1::OneHotEncoder``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - return ( - _Normalizer( - _Normalizer.Attributes( - norm=AttrString(norm, name="norm"), - ), - _Normalizer.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _OneHotEncoder( + _OneHotEncoder.Attributes( + cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), + cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), + zeros=AttrInt64(zeros, name="zeros"), + ), _OneHotEncoder.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def one_hot_encoder( - X: Var, - *, - cats_int64s: Optional[Iterable[int]] = None, - cats_strings: Optional[Iterable[str]] = None, - zeros: int = 1, -) -> Var: +def svmclassifier(X: Var, *, classlabels_ints: Optional[Iterable[int]] = None, classlabels_strings: Optional[Iterable[str]] = None, coefficients: Optional[Iterable[float]] = None, kernel_params: Optional[Iterable[float]] = None, kernel_type: str = "LINEAR", post_transform: str = "NONE", prob_a: Optional[Iterable[float]] = None, prob_b: Optional[Iterable[float]] = None, rho: Optional[Iterable[float]] = None, support_vectors: Optional[Iterable[float]] = None, vectors_per_class: Optional[Iterable[int]] = None, ) -> tuple[Var, Var]: r""" - Replace each input element with an array of ones and zeros, where a - single one is placed at the index of the category that was passed in. - The total category count will determine the size of the extra dimension - of the output array Y. For example, if we pass a tensor with a single - value of 4, and a category count of 8, the output will be a tensor with - ``[0,0,0,0,1,0,0,0]``. This operator assumes every input feature is from - the same set of categories. If the input is a tensor of float, int32, or - double, the data will be cast to integers and the cats_int64s category - list will be used for the lookups. - - Parameters - ========== - X - Type T. - Data to be encoded. - cats_int64s - Attribute. - List of categories, ints.One and only one of the 'cats\_\*' attributes - must be defined. - cats_strings - Attribute. - List of categories, strings.One and only one of the 'cats\_\*' - attributes must be defined. - zeros - Attribute. - If true and category is not present, will return all zeros; if false and - a category if not found, the operator will fail. - - Returns - ======= - Y : Var - Type tensor(float). - Encoded output data, having one more dimension than X. - - Notes - ===== - Signature: ``ai.onnx.ml@1::OneHotEncoder``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` +Support Vector Machine classifier + +Parameters +========== +X + Type T1. + Data to be classified. +classlabels_ints + Attribute. + Class labels if using integer labels.One and only one of the + 'classlabels\_\*' attributes must be defined. +classlabels_strings + Attribute. + Class labels if using string labels.One and only one of the + 'classlabels\_\*' attributes must be defined. +coefficients + Attribute. + +kernel_params + Attribute. + List of 3 elements containing gamma, coef0, and degree, in that order. + Zero if unused for the kernel. +kernel_type + Attribute. + The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'. +post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' + 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' +prob_a + Attribute. + First set of probability coefficients. +prob_b + Attribute. + Second set of probability coefficients. This array must be same size as + prob_a.If these are provided then output Z are probability estimates, + otherwise they are raw scores. +rho + Attribute. + +support_vectors + Attribute. + +vectors_per_class + Attribute. + + +Returns +======= +Y : Var + Type T2. + Classification outputs (one class per example). +Z : Var + Type tensor(float). + Class scores (one per class per example), if prob_a and prob_b are + provided they are probabilities for each class, otherwise they are raw + scores. + +Notes +===== +Signature: ``ai.onnx.ml@1::SVMClassifier``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + - T2: `tensor(int64)`, `tensor(string)` """ - return ( - _OneHotEncoder( - _OneHotEncoder.Attributes( - cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), - cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), - zeros=AttrInt64(zeros, name="zeros"), - ), - _OneHotEncoder.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def svmclassifier( - X: Var, - *, - classlabels_ints: Optional[Iterable[int]] = None, - classlabels_strings: Optional[Iterable[str]] = None, - coefficients: Optional[Iterable[float]] = None, - kernel_params: Optional[Iterable[float]] = None, - kernel_type: str = "LINEAR", - post_transform: str = "NONE", - prob_a: Optional[Iterable[float]] = None, - prob_b: Optional[Iterable[float]] = None, - rho: Optional[Iterable[float]] = None, - support_vectors: Optional[Iterable[float]] = None, - vectors_per_class: Optional[Iterable[int]] = None, -) -> tuple[Var, Var]: + return _SVMClassifier( + _SVMClassifier.Attributes( + classlabels_ints=AttrInt64s.maybe(classlabels_ints, name="classlabels_ints"), + classlabels_strings=AttrStrings.maybe(classlabels_strings, name="classlabels_strings"), + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), + kernel_type=AttrString(kernel_type, name="kernel_type"), + post_transform=AttrString(post_transform, name="post_transform"), + prob_a=AttrFloat32s.maybe(prob_a, name="prob_a"), + prob_b=AttrFloat32s.maybe(prob_b, name="prob_b"), + rho=AttrFloat32s.maybe(rho, name="rho"), + support_vectors=AttrFloat32s.maybe(support_vectors, name="support_vectors"), + vectors_per_class=AttrInt64s.maybe(vectors_per_class, name="vectors_per_class"), + ), _SVMClassifier.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), )._unpack_to_any() + + +def svmregressor(X: Var, *, coefficients: Optional[Iterable[float]] = None, kernel_params: Optional[Iterable[float]] = None, kernel_type: str = "LINEAR", n_supports: int = 0, one_class: int = 0, post_transform: str = "NONE", rho: Optional[Iterable[float]] = None, support_vectors: Optional[Iterable[float]] = None, ) -> Var: r""" - Support Vector Machine classifier - - Parameters - ========== - X - Type T1. - Data to be classified. - classlabels_ints - Attribute. - Class labels if using integer labels.One and only one of the - 'classlabels\_\*' attributes must be defined. - classlabels_strings - Attribute. - Class labels if using string labels.One and only one of the - 'classlabels\_\*' attributes must be defined. - coefficients - Attribute. - - kernel_params - Attribute. - List of 3 elements containing gamma, coef0, and degree, in that order. - Zero if unused for the kernel. - kernel_type - Attribute. - The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'. - post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' - 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' - prob_a - Attribute. - First set of probability coefficients. - prob_b - Attribute. - Second set of probability coefficients. This array must be same size as - prob_a.If these are provided then output Z are probability estimates, - otherwise they are raw scores. - rho - Attribute. - - support_vectors - Attribute. - - vectors_per_class - Attribute. - - - Returns - ======= - Y : Var - Type T2. - Classification outputs (one class per example). - Z : Var - Type tensor(float). - Class scores (one per class per example), if prob_a and prob_b are - provided they are probabilities for each class, otherwise they are raw - scores. - - Notes - ===== - Signature: ``ai.onnx.ml@1::SVMClassifier``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - - T2: `tensor(int64)`, `tensor(string)` +Support Vector Machine regression prediction and one-class SVM anomaly +detection. + +Parameters +========== +X + Type T. + Data to be regressed. +coefficients + Attribute. + Support vector coefficients. +kernel_params + Attribute. + List of 3 elements containing gamma, coef0, and degree, in that order. + Zero if unused for the kernel. +kernel_type + Attribute. + The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'. +n_supports + Attribute. + The number of support vectors. +one_class + Attribute. + Flag indicating whether the regression is a one-class SVM or not. +post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' + 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.' +rho + Attribute. + +support_vectors + Attribute. + Chosen support vectors + +Returns +======= +Y : Var + Type tensor(float). + Regression outputs (one score per target per example). + +Notes +===== +Signature: ``ai.onnx.ml@1::SVMRegressor``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return ( - _SVMClassifier( - _SVMClassifier.Attributes( - classlabels_ints=AttrInt64s.maybe( - classlabels_ints, name="classlabels_ints" - ), - classlabels_strings=AttrStrings.maybe( - classlabels_strings, name="classlabels_strings" - ), - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), - kernel_type=AttrString(kernel_type, name="kernel_type"), - post_transform=AttrString(post_transform, name="post_transform"), - prob_a=AttrFloat32s.maybe(prob_a, name="prob_a"), - prob_b=AttrFloat32s.maybe(prob_b, name="prob_b"), - rho=AttrFloat32s.maybe(rho, name="rho"), - support_vectors=AttrFloat32s.maybe( - support_vectors, name="support_vectors" - ), - vectors_per_class=AttrInt64s.maybe( - vectors_per_class, name="vectors_per_class" - ), - ), - _SVMClassifier.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - ._unpack_to_any() - ) - - -def svmregressor( - X: Var, - *, - coefficients: Optional[Iterable[float]] = None, - kernel_params: Optional[Iterable[float]] = None, - kernel_type: str = "LINEAR", - n_supports: int = 0, - one_class: int = 0, - post_transform: str = "NONE", - rho: Optional[Iterable[float]] = None, - support_vectors: Optional[Iterable[float]] = None, -) -> Var: + return _SVMRegressor( + _SVMRegressor.Attributes( + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), + kernel_type=AttrString(kernel_type, name="kernel_type"), + n_supports=AttrInt64(n_supports, name="n_supports"), + one_class=AttrInt64(one_class, name="one_class"), + post_transform=AttrString(post_transform, name="post_transform"), + rho=AttrFloat32s.maybe(rho, name="rho"), + support_vectors=AttrFloat32s.maybe(support_vectors, name="support_vectors"), + ), _SVMRegressor.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def scaler(X: Var, *, offset: Optional[Iterable[float]] = None, scale: Optional[Iterable[float]] = None, ) -> Var: r""" - Support Vector Machine regression prediction and one-class SVM anomaly - detection. - - Parameters - ========== - X - Type T. - Data to be regressed. - coefficients - Attribute. - Support vector coefficients. - kernel_params - Attribute. - List of 3 elements containing gamma, coef0, and degree, in that order. - Zero if unused for the kernel. - kernel_type - Attribute. - The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'. - n_supports - Attribute. - The number of support vectors. - one_class - Attribute. - Flag indicating whether the regression is a one-class SVM or not. - post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' - 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.' - rho - Attribute. - - support_vectors - Attribute. - Chosen support vectors - - Returns - ======= - Y : Var - Type tensor(float). - Regression outputs (one score per target per example). - - Notes - ===== - Signature: ``ai.onnx.ml@1::SVMRegressor``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` +Rescale input data, for example to standardize features by removing the +mean and scaling to unit variance. + +Parameters +========== +X + Type T. + Data to be scaled. +offset + Attribute. + First, offset by this.Can be length of features in an [N,F] tensor or + length 1, in which case it applies to all features, regardless of + dimension count. +scale + Attribute. + Second, multiply by this.Can be length of features in an [N,F] tensor or + length 1, in which case it applies to all features, regardless of + dimension count.Must be same length as 'offset' + +Returns +======= +Y : Var + Type tensor(float). + Scaled output data. + +Notes +===== +Signature: ``ai.onnx.ml@1::Scaler``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return ( - _SVMRegressor( - _SVMRegressor.Attributes( - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), - kernel_type=AttrString(kernel_type, name="kernel_type"), - n_supports=AttrInt64(n_supports, name="n_supports"), - one_class=AttrInt64(one_class, name="one_class"), - post_transform=AttrString(post_transform, name="post_transform"), - rho=AttrFloat32s.maybe(rho, name="rho"), - support_vectors=AttrFloat32s.maybe( - support_vectors, name="support_vectors" - ), - ), - _SVMRegressor.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _Scaler( + _Scaler.Attributes( + offset=AttrFloat32s.maybe(offset, name="offset"), + scale=AttrFloat32s.maybe(scale, name="scale"), + ), _Scaler.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def scaler( - X: Var, - *, - offset: Optional[Iterable[float]] = None, - scale: Optional[Iterable[float]] = None, -) -> Var: +def tree_ensemble_classifier(X: Var, *, base_values: Optional[Iterable[float]] = None, base_values_as_tensor: Optional[np.ndarray] = None, class_ids: Optional[Iterable[int]] = None, class_nodeids: Optional[Iterable[int]] = None, class_treeids: Optional[Iterable[int]] = None, class_weights: Optional[Iterable[float]] = None, class_weights_as_tensor: Optional[np.ndarray] = None, classlabels_int64s: Optional[Iterable[int]] = None, classlabels_strings: Optional[Iterable[str]] = None, nodes_falsenodeids: Optional[Iterable[int]] = None, nodes_featureids: Optional[Iterable[int]] = None, nodes_hitrates: Optional[Iterable[float]] = None, nodes_hitrates_as_tensor: Optional[np.ndarray] = None, nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, nodes_modes: Optional[Iterable[str]] = None, nodes_nodeids: Optional[Iterable[int]] = None, nodes_treeids: Optional[Iterable[int]] = None, nodes_truenodeids: Optional[Iterable[int]] = None, nodes_values: Optional[Iterable[float]] = None, nodes_values_as_tensor: Optional[np.ndarray] = None, post_transform: str = "NONE", ) -> tuple[Var, Var]: r""" - Rescale input data, for example to standardize features by removing the - mean and scaling to unit variance. - - Parameters - ========== - X - Type T. - Data to be scaled. - offset - Attribute. - First, offset by this.Can be length of features in an [N,F] tensor or - length 1, in which case it applies to all features, regardless of - dimension count. - scale - Attribute. - Second, multiply by this.Can be length of features in an [N,F] tensor or - length 1, in which case it applies to all features, regardless of - dimension count.Must be same length as 'offset' - - Returns - ======= - Y : Var - Type tensor(float). - Scaled output data. - - Notes - ===== - Signature: ``ai.onnx.ml@1::Scaler``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` +Tree Ensemble classifier. Returns the top class for each of N inputs. +The attributes named 'nodes_X' form a sequence of tuples, associated by +index into the sequences, which must all be of equal length. These +tuples define the nodes. Similarly, all fields prefixed with 'class\_' +are tuples of votes at the leaves. A leaf may have multiple votes, where +each vote is weighted by the associated class_weights index. One and +only one of classlabels_strings or classlabels_int64s will be defined. +The class_ids are indices into this list. All fields ending with +\_as_tensor can be used instead of the same parameter without the suffix +if the element type is double and not float. + +Parameters +========== +X + Type T1. + Input of shape [N,F] +base_values + Attribute. + Base values for classification, added to final class score; the size + must be the same as the classes or can be left unassigned (assumed 0) +base_values_as_tensor + Attribute. + Base values for classification, added to final class score; the size + must be the same as the classes or can be left unassigned (assumed 0) +class_ids + Attribute. + The index of the class list that each weight is for. +class_nodeids + Attribute. + node id that this weight is for. +class_treeids + Attribute. + The id of the tree that this node is in. +class_weights + Attribute. + The weight for the class in class_id. +class_weights_as_tensor + Attribute. + The weight for the class in class_id. +classlabels_int64s + Attribute. + Class labels if using integer labels.One and only one of the + 'classlabels\_\*' attributes must be defined. +classlabels_strings + Attribute. + Class labels if using string labels.One and only one of the + 'classlabels\_\*' attributes must be defined. +nodes_falsenodeids + Attribute. + Child node if expression is false. +nodes_featureids + Attribute. + Feature id for each node. +nodes_hitrates + Attribute. + Popularity of each node, used for performance and may be omitted. +nodes_hitrates_as_tensor + Attribute. + Popularity of each node, used for performance and may be omitted. +nodes_missing_value_tracks_true + Attribute. + For each node, define what to do in the presence of a missing value: if + a value is missing (NaN), use the 'true' or 'false' branch based on the + value in this array.This attribute may be left undefined, and the + default value is false (0) for all nodes. +nodes_modes + Attribute. + The node kind, that is, the comparison to make at the node. There is no + comparison to make at a leaf node.One of 'BRANCH_LEQ', 'BRANCH_LT', + 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF' +nodes_nodeids + Attribute. + Node id for each node. Ids may restart at zero for each tree, but it not + required to. +nodes_treeids + Attribute. + Tree id for each node. +nodes_truenodeids + Attribute. + Child node if expression is true. +nodes_values + Attribute. + Thresholds to do the splitting on for each node. +nodes_values_as_tensor + Attribute. + Thresholds to do the splitting on for each node. +post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' + 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.' + +Returns +======= +Y : Var + Type T2. + N, Top class for each point +Z : Var + Type tensor(float). + The class score for each class, for each point, a tensor of shape [N,E]. + +Notes +===== +Signature: ``ai.onnx.ml@3::TreeEnsembleClassifier``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + - T2: `tensor(int64)`, `tensor(string)` """ - return ( - _Scaler( - _Scaler.Attributes( - offset=AttrFloat32s.maybe(offset, name="offset"), - scale=AttrFloat32s.maybe(scale, name="scale"), - ), - _Scaler.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def tree_ensemble_classifier( - X: Var, - *, - base_values: Optional[Iterable[float]] = None, - base_values_as_tensor: Optional[np.ndarray] = None, - class_ids: Optional[Iterable[int]] = None, - class_nodeids: Optional[Iterable[int]] = None, - class_treeids: Optional[Iterable[int]] = None, - class_weights: Optional[Iterable[float]] = None, - class_weights_as_tensor: Optional[np.ndarray] = None, - classlabels_int64s: Optional[Iterable[int]] = None, - classlabels_strings: Optional[Iterable[str]] = None, - nodes_falsenodeids: Optional[Iterable[int]] = None, - nodes_featureids: Optional[Iterable[int]] = None, - nodes_hitrates: Optional[Iterable[float]] = None, - nodes_hitrates_as_tensor: Optional[np.ndarray] = None, - nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, - nodes_modes: Optional[Iterable[str]] = None, - nodes_nodeids: Optional[Iterable[int]] = None, - nodes_treeids: Optional[Iterable[int]] = None, - nodes_truenodeids: Optional[Iterable[int]] = None, - nodes_values: Optional[Iterable[float]] = None, - nodes_values_as_tensor: Optional[np.ndarray] = None, - post_transform: str = "NONE", -) -> tuple[Var, Var]: + return _TreeEnsembleClassifier( + _TreeEnsembleClassifier.Attributes( + base_values=AttrFloat32s.maybe(base_values, name="base_values"), + base_values_as_tensor=AttrTensor.maybe(base_values_as_tensor, name="base_values_as_tensor"), + class_ids=AttrInt64s.maybe(class_ids, name="class_ids"), + class_nodeids=AttrInt64s.maybe(class_nodeids, name="class_nodeids"), + class_treeids=AttrInt64s.maybe(class_treeids, name="class_treeids"), + class_weights=AttrFloat32s.maybe(class_weights, name="class_weights"), + class_weights_as_tensor=AttrTensor.maybe(class_weights_as_tensor, name="class_weights_as_tensor"), + classlabels_int64s=AttrInt64s.maybe(classlabels_int64s, name="classlabels_int64s"), + classlabels_strings=AttrStrings.maybe(classlabels_strings, name="classlabels_strings"), + nodes_falsenodeids=AttrInt64s.maybe(nodes_falsenodeids, name="nodes_falsenodeids"), + nodes_featureids=AttrInt64s.maybe(nodes_featureids, name="nodes_featureids"), + nodes_hitrates=AttrFloat32s.maybe(nodes_hitrates, name="nodes_hitrates"), + nodes_hitrates_as_tensor=AttrTensor.maybe(nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor"), + nodes_missing_value_tracks_true=AttrInt64s.maybe(nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true"), + nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), + nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), + nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), + nodes_truenodeids=AttrInt64s.maybe(nodes_truenodeids, name="nodes_truenodeids"), + nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), + nodes_values_as_tensor=AttrTensor.maybe(nodes_values_as_tensor, name="nodes_values_as_tensor"), + post_transform=AttrString(post_transform, name="post_transform"), + ), _TreeEnsembleClassifier.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), )._unpack_to_any() + + +def tree_ensemble_regressor(X: Var, *, aggregate_function: str = "SUM", base_values: Optional[Iterable[float]] = None, base_values_as_tensor: Optional[np.ndarray] = None, n_targets: Optional[int] = None, nodes_falsenodeids: Optional[Iterable[int]] = None, nodes_featureids: Optional[Iterable[int]] = None, nodes_hitrates: Optional[Iterable[float]] = None, nodes_hitrates_as_tensor: Optional[np.ndarray] = None, nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, nodes_modes: Optional[Iterable[str]] = None, nodes_nodeids: Optional[Iterable[int]] = None, nodes_treeids: Optional[Iterable[int]] = None, nodes_truenodeids: Optional[Iterable[int]] = None, nodes_values: Optional[Iterable[float]] = None, nodes_values_as_tensor: Optional[np.ndarray] = None, post_transform: str = "NONE", target_ids: Optional[Iterable[int]] = None, target_nodeids: Optional[Iterable[int]] = None, target_treeids: Optional[Iterable[int]] = None, target_weights: Optional[Iterable[float]] = None, target_weights_as_tensor: Optional[np.ndarray] = None, ) -> Var: r""" - Tree Ensemble classifier. Returns the top class for each of N inputs. - The attributes named 'nodes_X' form a sequence of tuples, associated by - index into the sequences, which must all be of equal length. These - tuples define the nodes. Similarly, all fields prefixed with 'class\_' - are tuples of votes at the leaves. A leaf may have multiple votes, where - each vote is weighted by the associated class_weights index. One and - only one of classlabels_strings or classlabels_int64s will be defined. - The class_ids are indices into this list. All fields ending with - \_as_tensor can be used instead of the same parameter without the suffix - if the element type is double and not float. - - Parameters - ========== - X - Type T1. - Input of shape [N,F] - base_values - Attribute. - Base values for classification, added to final class score; the size - must be the same as the classes or can be left unassigned (assumed 0) - base_values_as_tensor - Attribute. - Base values for classification, added to final class score; the size - must be the same as the classes or can be left unassigned (assumed 0) - class_ids - Attribute. - The index of the class list that each weight is for. - class_nodeids - Attribute. - node id that this weight is for. - class_treeids - Attribute. - The id of the tree that this node is in. - class_weights - Attribute. - The weight for the class in class_id. - class_weights_as_tensor - Attribute. - The weight for the class in class_id. - classlabels_int64s - Attribute. - Class labels if using integer labels.One and only one of the - 'classlabels\_\*' attributes must be defined. - classlabels_strings - Attribute. - Class labels if using string labels.One and only one of the - 'classlabels\_\*' attributes must be defined. - nodes_falsenodeids - Attribute. - Child node if expression is false. - nodes_featureids - Attribute. - Feature id for each node. - nodes_hitrates - Attribute. - Popularity of each node, used for performance and may be omitted. - nodes_hitrates_as_tensor - Attribute. - Popularity of each node, used for performance and may be omitted. - nodes_missing_value_tracks_true - Attribute. - For each node, define what to do in the presence of a missing value: if - a value is missing (NaN), use the 'true' or 'false' branch based on the - value in this array.This attribute may be left undefined, and the - default value is false (0) for all nodes. - nodes_modes - Attribute. - The node kind, that is, the comparison to make at the node. There is no - comparison to make at a leaf node.One of 'BRANCH_LEQ', 'BRANCH_LT', - 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF' - nodes_nodeids - Attribute. - Node id for each node. Ids may restart at zero for each tree, but it not - required to. - nodes_treeids - Attribute. - Tree id for each node. - nodes_truenodeids - Attribute. - Child node if expression is true. - nodes_values - Attribute. - Thresholds to do the splitting on for each node. - nodes_values_as_tensor - Attribute. - Thresholds to do the splitting on for each node. - post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' - 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.' - - Returns - ======= - Y : Var - Type T2. - N, Top class for each point - Z : Var - Type tensor(float). - The class score for each class, for each point, a tensor of shape [N,E]. - - Notes - ===== - Signature: ``ai.onnx.ml@3::TreeEnsembleClassifier``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - - T2: `tensor(int64)`, `tensor(string)` +Tree Ensemble regressor. Returns the regressed values for each input in +N. All args with nodes\_ are fields of a tuple of tree nodes, and it is +assumed they are the same length, and an index i will decode the tuple +across these inputs. Each node id can appear only once for each tree id. +All fields prefixed with target\_ are tuples of votes at the leaves. A +leaf may have multiple votes, where each vote is weighted by the +associated target_weights index. All fields ending with \_as_tensor can +be used instead of the same parameter without the suffix if the element +type is double and not float. All trees must have their node ids start +at 0 and increment by 1. Mode enum is BRANCH_LEQ, BRANCH_LT, BRANCH_GTE, +BRANCH_GT, BRANCH_EQ, BRANCH_NEQ, LEAF + +Parameters +========== +X + Type T. + Input of shape [N,F] +aggregate_function + Attribute. + Defines how to aggregate leaf values within a target. One of 'AVERAGE,' + 'SUM,' 'MIN,' 'MAX.' +base_values + Attribute. + Base values for regression, added to final prediction after applying + aggregate_function; the size must be the same as the classes or can be + left unassigned (assumed 0) +base_values_as_tensor + Attribute. + Base values for regression, added to final prediction after applying + aggregate_function; the size must be the same as the classes or can be + left unassigned (assumed 0) +n_targets + Attribute. + The total number of targets. +nodes_falsenodeids + Attribute. + Child node if expression is false +nodes_featureids + Attribute. + Feature id for each node. +nodes_hitrates + Attribute. + Popularity of each node, used for performance and may be omitted. +nodes_hitrates_as_tensor + Attribute. + Popularity of each node, used for performance and may be omitted. +nodes_missing_value_tracks_true + Attribute. + For each node, define what to do in the presence of a NaN: use the + 'true' (if the attribute value is 1) or 'false' (if the attribute value + is 0) branch based on the value in this array.This attribute may be left + undefined and the default value is false (0) for all nodes. +nodes_modes + Attribute. + The node kind, that is, the comparison to make at the node. There is no + comparison to make at a leaf node.One of 'BRANCH_LEQ', 'BRANCH_LT', + 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF' +nodes_nodeids + Attribute. + Node id for each node. Node ids must restart at zero for each tree and + increase sequentially. +nodes_treeids + Attribute. + Tree id for each node. +nodes_truenodeids + Attribute. + Child node if expression is true +nodes_values + Attribute. + Thresholds to do the splitting on for each node. +nodes_values_as_tensor + Attribute. + Thresholds to do the splitting on for each node. +post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' + 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' +target_ids + Attribute. + The index of the target that each weight is for +target_nodeids + Attribute. + The node id of each weight +target_treeids + Attribute. + The id of the tree that each node is in. +target_weights + Attribute. + The weight for each target +target_weights_as_tensor + Attribute. + The weight for each target + +Returns +======= +Y : Var + Type tensor(float). + N classes + +Notes +===== +Signature: ``ai.onnx.ml@3::TreeEnsembleRegressor``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return ( - _TreeEnsembleClassifier( - _TreeEnsembleClassifier.Attributes( - base_values=AttrFloat32s.maybe(base_values, name="base_values"), - base_values_as_tensor=AttrTensor.maybe( - base_values_as_tensor, name="base_values_as_tensor" - ), - class_ids=AttrInt64s.maybe(class_ids, name="class_ids"), - class_nodeids=AttrInt64s.maybe(class_nodeids, name="class_nodeids"), - class_treeids=AttrInt64s.maybe(class_treeids, name="class_treeids"), - class_weights=AttrFloat32s.maybe(class_weights, name="class_weights"), - class_weights_as_tensor=AttrTensor.maybe( - class_weights_as_tensor, name="class_weights_as_tensor" - ), - classlabels_int64s=AttrInt64s.maybe( - classlabels_int64s, name="classlabels_int64s" - ), - classlabels_strings=AttrStrings.maybe( - classlabels_strings, name="classlabels_strings" - ), - nodes_falsenodeids=AttrInt64s.maybe( - nodes_falsenodeids, name="nodes_falsenodeids" - ), - nodes_featureids=AttrInt64s.maybe( - nodes_featureids, name="nodes_featureids" - ), - nodes_hitrates=AttrFloat32s.maybe( - nodes_hitrates, name="nodes_hitrates" - ), - nodes_hitrates_as_tensor=AttrTensor.maybe( - nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor" - ), - nodes_missing_value_tracks_true=AttrInt64s.maybe( - nodes_missing_value_tracks_true, - name="nodes_missing_value_tracks_true", - ), - nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), - nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), - nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), - nodes_truenodeids=AttrInt64s.maybe( - nodes_truenodeids, name="nodes_truenodeids" - ), - nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), - nodes_values_as_tensor=AttrTensor.maybe( - nodes_values_as_tensor, name="nodes_values_as_tensor" - ), - post_transform=AttrString(post_transform, name="post_transform"), - ), - _TreeEnsembleClassifier.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - ._unpack_to_any() - ) - - -def tree_ensemble_regressor( - X: Var, - *, - aggregate_function: str = "SUM", - base_values: Optional[Iterable[float]] = None, - base_values_as_tensor: Optional[np.ndarray] = None, - n_targets: Optional[int] = None, - nodes_falsenodeids: Optional[Iterable[int]] = None, - nodes_featureids: Optional[Iterable[int]] = None, - nodes_hitrates: Optional[Iterable[float]] = None, - nodes_hitrates_as_tensor: Optional[np.ndarray] = None, - nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, - nodes_modes: Optional[Iterable[str]] = None, - nodes_nodeids: Optional[Iterable[int]] = None, - nodes_treeids: Optional[Iterable[int]] = None, - nodes_truenodeids: Optional[Iterable[int]] = None, - nodes_values: Optional[Iterable[float]] = None, - nodes_values_as_tensor: Optional[np.ndarray] = None, - post_transform: str = "NONE", - target_ids: Optional[Iterable[int]] = None, - target_nodeids: Optional[Iterable[int]] = None, - target_treeids: Optional[Iterable[int]] = None, - target_weights: Optional[Iterable[float]] = None, - target_weights_as_tensor: Optional[np.ndarray] = None, -) -> Var: - r""" - Tree Ensemble regressor. Returns the regressed values for each input in - N. All args with nodes\_ are fields of a tuple of tree nodes, and it is - assumed they are the same length, and an index i will decode the tuple - across these inputs. Each node id can appear only once for each tree id. - All fields prefixed with target\_ are tuples of votes at the leaves. A - leaf may have multiple votes, where each vote is weighted by the - associated target_weights index. All fields ending with \_as_tensor can - be used instead of the same parameter without the suffix if the element - type is double and not float. All trees must have their node ids start - at 0 and increment by 1. Mode enum is BRANCH_LEQ, BRANCH_LT, BRANCH_GTE, - BRANCH_GT, BRANCH_EQ, BRANCH_NEQ, LEAF - - Parameters - ========== - X - Type T. - Input of shape [N,F] - aggregate_function - Attribute. - Defines how to aggregate leaf values within a target. One of 'AVERAGE,' - 'SUM,' 'MIN,' 'MAX.' - base_values - Attribute. - Base values for regression, added to final prediction after applying - aggregate_function; the size must be the same as the classes or can be - left unassigned (assumed 0) - base_values_as_tensor - Attribute. - Base values for regression, added to final prediction after applying - aggregate_function; the size must be the same as the classes or can be - left unassigned (assumed 0) - n_targets - Attribute. - The total number of targets. - nodes_falsenodeids - Attribute. - Child node if expression is false - nodes_featureids - Attribute. - Feature id for each node. - nodes_hitrates - Attribute. - Popularity of each node, used for performance and may be omitted. - nodes_hitrates_as_tensor - Attribute. - Popularity of each node, used for performance and may be omitted. - nodes_missing_value_tracks_true - Attribute. - For each node, define what to do in the presence of a NaN: use the - 'true' (if the attribute value is 1) or 'false' (if the attribute value - is 0) branch based on the value in this array.This attribute may be left - undefined and the default value is false (0) for all nodes. - nodes_modes - Attribute. - The node kind, that is, the comparison to make at the node. There is no - comparison to make at a leaf node.One of 'BRANCH_LEQ', 'BRANCH_LT', - 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF' - nodes_nodeids - Attribute. - Node id for each node. Node ids must restart at zero for each tree and - increase sequentially. - nodes_treeids - Attribute. - Tree id for each node. - nodes_truenodeids - Attribute. - Child node if expression is true - nodes_values - Attribute. - Thresholds to do the splitting on for each node. - nodes_values_as_tensor - Attribute. - Thresholds to do the splitting on for each node. - post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' - 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' - target_ids - Attribute. - The index of the target that each weight is for - target_nodeids - Attribute. - The node id of each weight - target_treeids - Attribute. - The id of the tree that each node is in. - target_weights - Attribute. - The weight for each target - target_weights_as_tensor - Attribute. - The weight for each target - - Returns - ======= - Y : Var - Type tensor(float). - N classes - - Notes - ===== - Signature: ``ai.onnx.ml@3::TreeEnsembleRegressor``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - """ - return ( - _TreeEnsembleRegressor( - _TreeEnsembleRegressor.Attributes( - aggregate_function=AttrString( - aggregate_function, name="aggregate_function" - ), - base_values=AttrFloat32s.maybe(base_values, name="base_values"), - base_values_as_tensor=AttrTensor.maybe( - base_values_as_tensor, name="base_values_as_tensor" - ), - n_targets=AttrInt64.maybe(n_targets, name="n_targets"), - nodes_falsenodeids=AttrInt64s.maybe( - nodes_falsenodeids, name="nodes_falsenodeids" - ), - nodes_featureids=AttrInt64s.maybe( - nodes_featureids, name="nodes_featureids" - ), - nodes_hitrates=AttrFloat32s.maybe( - nodes_hitrates, name="nodes_hitrates" - ), - nodes_hitrates_as_tensor=AttrTensor.maybe( - nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor" - ), - nodes_missing_value_tracks_true=AttrInt64s.maybe( - nodes_missing_value_tracks_true, - name="nodes_missing_value_tracks_true", - ), - nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), - nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), - nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), - nodes_truenodeids=AttrInt64s.maybe( - nodes_truenodeids, name="nodes_truenodeids" - ), - nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), - nodes_values_as_tensor=AttrTensor.maybe( - nodes_values_as_tensor, name="nodes_values_as_tensor" - ), - post_transform=AttrString(post_transform, name="post_transform"), - target_ids=AttrInt64s.maybe(target_ids, name="target_ids"), - target_nodeids=AttrInt64s.maybe(target_nodeids, name="target_nodeids"), - target_treeids=AttrInt64s.maybe(target_treeids, name="target_treeids"), - target_weights=AttrFloat32s.maybe( - target_weights, name="target_weights" - ), - target_weights_as_tensor=AttrTensor.maybe( - target_weights_as_tensor, name="target_weights_as_tensor" - ), - ), - _TreeEnsembleRegressor.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def zip_map( - X: Var, - *, - classlabels_int64s: Optional[Iterable[int]] = None, - classlabels_strings: Optional[Iterable[str]] = None, -) -> Var: + return _TreeEnsembleRegressor( + _TreeEnsembleRegressor.Attributes( + aggregate_function=AttrString(aggregate_function, name="aggregate_function"), + base_values=AttrFloat32s.maybe(base_values, name="base_values"), + base_values_as_tensor=AttrTensor.maybe(base_values_as_tensor, name="base_values_as_tensor"), + n_targets=AttrInt64.maybe(n_targets, name="n_targets"), + nodes_falsenodeids=AttrInt64s.maybe(nodes_falsenodeids, name="nodes_falsenodeids"), + nodes_featureids=AttrInt64s.maybe(nodes_featureids, name="nodes_featureids"), + nodes_hitrates=AttrFloat32s.maybe(nodes_hitrates, name="nodes_hitrates"), + nodes_hitrates_as_tensor=AttrTensor.maybe(nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor"), + nodes_missing_value_tracks_true=AttrInt64s.maybe(nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true"), + nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), + nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), + nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), + nodes_truenodeids=AttrInt64s.maybe(nodes_truenodeids, name="nodes_truenodeids"), + nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), + nodes_values_as_tensor=AttrTensor.maybe(nodes_values_as_tensor, name="nodes_values_as_tensor"), + post_transform=AttrString(post_transform, name="post_transform"), + target_ids=AttrInt64s.maybe(target_ids, name="target_ids"), + target_nodeids=AttrInt64s.maybe(target_nodeids, name="target_nodeids"), + target_treeids=AttrInt64s.maybe(target_treeids, name="target_treeids"), + target_weights=AttrFloat32s.maybe(target_weights, name="target_weights"), + target_weights_as_tensor=AttrTensor.maybe(target_weights_as_tensor, name="target_weights_as_tensor"), + ), _TreeEnsembleRegressor.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def zip_map(X: Var, *, classlabels_int64s: Optional[Iterable[int]] = None, classlabels_strings: Optional[Iterable[str]] = None, ) -> Var: r""" - Creates a map from the input and the attributes. The values are provided - by the input tensor, while the keys are specified by the attributes. - Must provide keys in either classlabels_strings or classlabels_int64s - (but not both). The columns of the tensor correspond one-by-one to the - keys specified by the attributes. There must be as many columns as keys. - - Parameters - ========== - X - Type tensor(float). - The input values - classlabels_int64s - Attribute. - The keys when using int keys.One and only one of the 'classlabels\_\*' - attributes must be defined. - classlabels_strings - Attribute. - The keys when using string keys.One and only one of the - 'classlabels\_\*' attributes must be defined. - - Returns - ======= - Z : Var - Type T. - The output map - - Notes - ===== - Signature: ``ai.onnx.ml@1::ZipMap``. - - Type constraints: - - T: `seq(map(int64,tensor(float)))`, `seq(map(string,tensor(float)))` +Creates a map from the input and the attributes. The values are provided +by the input tensor, while the keys are specified by the attributes. +Must provide keys in either classlabels_strings or classlabels_int64s +(but not both). The columns of the tensor correspond one-by-one to the +keys specified by the attributes. There must be as many columns as keys. + +Parameters +========== +X + Type tensor(float). + The input values +classlabels_int64s + Attribute. + The keys when using int keys.One and only one of the 'classlabels\_\*' + attributes must be defined. +classlabels_strings + Attribute. + The keys when using string keys.One and only one of the + 'classlabels\_\*' attributes must be defined. + +Returns +======= +Z : Var + Type T. + The output map + +Notes +===== +Signature: ``ai.onnx.ml@1::ZipMap``. + +Type constraints: + - T: `seq(map(int64,tensor(float)))`, `seq(map(string,tensor(float)))` """ - return ( - _ZipMap( - _ZipMap.Attributes( - classlabels_int64s=AttrInt64s.maybe( - classlabels_int64s, name="classlabels_int64s" - ), - classlabels_strings=AttrStrings.maybe( - classlabels_strings, name="classlabels_strings" - ), - ), - _ZipMap.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Z - ) + return _ZipMap( + _ZipMap.Attributes( + classlabels_int64s=AttrInt64s.maybe(classlabels_int64s, name="classlabels_int64s"), + classlabels_strings=AttrStrings.maybe(classlabels_strings, name="classlabels_strings"), + ), _ZipMap.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Z _OPERATORS = { @@ -2187,4 +1775,4 @@ def zip_map( "ZipMap": zip_map, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index 2e4871c8..998b6afc 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -1,66 +1,58 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: BSD-3-Clause - # ruff: noqa: E741 -- Allow ambiguous variable name -from collections.abc import Iterable +import typing +import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( + Any, + Callable, Optional, + Union, ) +from typing import cast as typing_cast import numpy as np +import numpy.typing as npt +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( + AttrDtype, AttrFloat32, AttrFloat32s, + AttrGraph, AttrInt64, AttrInt64s, AttrString, AttrStrings, AttrTensor, + AttrType, ) -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs +from spox._graph import Graph, subgraph +from spox._internal_op import intro from spox._node import OpType -from spox._standard import StandardNode -from spox._var import Var, VarInfo, get_value, unwrap_vars -from spox.opset.ai.onnx.ml.v3 import ( - _ArrayFeatureExtractor, - _Binarizer, - _CastMap, - _CategoryMapper, - _DictVectorizer, - _FeatureVectorizer, - _Imputer, - _LinearClassifier, - _LinearRegressor, - _Normalizer, - _OneHotEncoder, - _Scaler, - _SVMClassifier, - _SVMRegressor, - _TreeEnsembleClassifier, - _TreeEnsembleRegressor, - _ZipMap, - array_feature_extractor, - binarizer, - cast_map, - category_mapper, - dict_vectorizer, - feature_vectorizer, - imputer, - linear_classifier, - linear_regressor, - normalizer, - one_hot_encoder, - scaler, - svmclassifier, - svmregressor, - tree_ensemble_classifier, - tree_ensemble_regressor, - zip_map, -) - - +from spox._standard import InferenceError, StandardNode +from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._value_prop import PropValueType + + +from spox.opset.ai.onnx.ml.v3 import _ArrayFeatureExtractor, array_feature_extractor +from spox.opset.ai.onnx.ml.v3 import _Binarizer, binarizer +from spox.opset.ai.onnx.ml.v3 import _CastMap, cast_map +from spox.opset.ai.onnx.ml.v3 import _CategoryMapper, category_mapper +from spox.opset.ai.onnx.ml.v3 import _DictVectorizer, dict_vectorizer +from spox.opset.ai.onnx.ml.v3 import _FeatureVectorizer, feature_vectorizer +from spox.opset.ai.onnx.ml.v3 import _Imputer, imputer +from spox.opset.ai.onnx.ml.v3 import _LinearClassifier, linear_classifier +from spox.opset.ai.onnx.ml.v3 import _LinearRegressor, linear_regressor +from spox.opset.ai.onnx.ml.v3 import _Normalizer, normalizer +from spox.opset.ai.onnx.ml.v3 import _OneHotEncoder, one_hot_encoder +from spox.opset.ai.onnx.ml.v3 import _SVMClassifier, svmclassifier +from spox.opset.ai.onnx.ml.v3 import _SVMRegressor, svmregressor +from spox.opset.ai.onnx.ml.v3 import _Scaler, scaler +from spox.opset.ai.onnx.ml.v3 import _TreeEnsembleClassifier, tree_ensemble_classifier +from spox.opset.ai.onnx.ml.v3 import _TreeEnsembleRegressor, tree_ensemble_regressor +from spox.opset.ai.onnx.ml.v3 import _ZipMap, zip_map class _LabelEncoder(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -91,131 +83,107 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - -def label_encoder( - X: Var, - *, - default_float: float = -0.0, - default_int64: int = -1, - default_string: str = "_Unused", - default_tensor: Optional[np.ndarray] = None, - keys_floats: Optional[Iterable[float]] = None, - keys_int64s: Optional[Iterable[int]] = None, - keys_strings: Optional[Iterable[str]] = None, - keys_tensor: Optional[np.ndarray] = None, - values_floats: Optional[Iterable[float]] = None, - values_int64s: Optional[Iterable[int]] = None, - values_strings: Optional[Iterable[str]] = None, - values_tensor: Optional[np.ndarray] = None, -) -> Var: +def label_encoder(X: Var, *, default_float: float = -0.0, default_int64: int = -1, default_string: str = "_Unused", default_tensor: Optional[np.ndarray] = None, keys_floats: Optional[Iterable[float]] = None, keys_int64s: Optional[Iterable[int]] = None, keys_strings: Optional[Iterable[str]] = None, keys_tensor: Optional[np.ndarray] = None, values_floats: Optional[Iterable[float]] = None, values_int64s: Optional[Iterable[int]] = None, values_strings: Optional[Iterable[str]] = None, values_tensor: Optional[np.ndarray] = None, ) -> Var: r""" - Maps each element in the input tensor to another value. The mapping is - determined by the two parallel attributes, 'keys\_\ *' and 'values\_*' - attribute. The i-th value in the specified 'keys\_\ *' attribute would - be mapped to the i-th value in the specified 'values\_*' attribute. It - implies that input's element type and the element type of the specified - 'keys\_\ *' should be identical while the output type is identical to - the specified 'values\_*' attribute. Note that the 'keys\_\ *' and - 'values\_*' attributes must have the same length. If an input element - can not be found in the specified 'keys\_\ *' attribute, the - 'default\_*' that matches the specified 'values\_\ *' attribute may be - used as its output value. The type of the 'default\_*' attribute must - match the 'values\_\ *' attribute chosen. Let's consider an example - which maps a string tensor to an integer tensor. Assume and - 'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6], and - 'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally", - "Sally"] would be mapped to [-1, 5, 5, 6, 6]. Since this operator is an - one-to-one mapping, its input and output shapes are the same. Notice - that only one of 'keys\_*'/'values\_\*' can be set. Float keys with - value 'NaN' match any input 'NaN' value regardless of bit value. If a - key is repeated, the last key takes precedence. - - Parameters - ========== - X - Type T1. - Input data. It must have the same element type as the keys\_\* attribute - set. - default_float - Attribute. - A float. - default_int64 - Attribute. - An integer. - default_string - Attribute. - A string. - default_tensor - Attribute. - A default tensor. {"*Unused"} if values*\ \* has string type, {-1} if - values\_\* has integral type, and {-0.f} if values\_\* has float type. - keys_floats - Attribute. - A list of floats. - keys_int64s - Attribute. - A list of ints. - keys_strings - Attribute. - A list of strings. - keys_tensor - Attribute. - Keys encoded as a 1D tensor. One and only one of 'keys\_\*'s should be - set. - values_floats - Attribute. - A list of floats. - values_int64s - Attribute. - A list of ints. - values_strings - Attribute. - A list of strings. - values_tensor - Attribute. - Values encoded as a 1D tensor. One and only one of 'values\_\*'s should - be set. - - Returns - ======= - Y : Var - Type T2. - Output data. This tensor's element type is based on the values\_\* - attribute set. - - Notes - ===== - Signature: ``ai.onnx.ml@4::LabelEncoder``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` +Maps each element in the input tensor to another value. The mapping is +determined by the two parallel attributes, 'keys\_\ *' and 'values\_*' +attribute. The i-th value in the specified 'keys\_\ *' attribute would +be mapped to the i-th value in the specified 'values\_*' attribute. It +implies that input's element type and the element type of the specified +'keys\_\ *' should be identical while the output type is identical to +the specified 'values\_*' attribute. Note that the 'keys\_\ *' and +'values\_*' attributes must have the same length. If an input element +can not be found in the specified 'keys\_\ *' attribute, the +'default\_*' that matches the specified 'values\_\ *' attribute may be +used as its output value. The type of the 'default\_*' attribute must +match the 'values\_\ *' attribute chosen. Let's consider an example +which maps a string tensor to an integer tensor. Assume and +'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6], and +'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally", +"Sally"] would be mapped to [-1, 5, 5, 6, 6]. Since this operator is an +one-to-one mapping, its input and output shapes are the same. Notice +that only one of 'keys\_*'/'values\_\*' can be set. Float keys with +value 'NaN' match any input 'NaN' value regardless of bit value. If a +key is repeated, the last key takes precedence. + +Parameters +========== +X + Type T1. + Input data. It must have the same element type as the keys\_\* attribute + set. +default_float + Attribute. + A float. +default_int64 + Attribute. + An integer. +default_string + Attribute. + A string. +default_tensor + Attribute. + A default tensor. {"*Unused"} if values*\ \* has string type, {-1} if + values\_\* has integral type, and {-0.f} if values\_\* has float type. +keys_floats + Attribute. + A list of floats. +keys_int64s + Attribute. + A list of ints. +keys_strings + Attribute. + A list of strings. +keys_tensor + Attribute. + Keys encoded as a 1D tensor. One and only one of 'keys\_\*'s should be + set. +values_floats + Attribute. + A list of floats. +values_int64s + Attribute. + A list of ints. +values_strings + Attribute. + A list of strings. +values_tensor + Attribute. + Values encoded as a 1D tensor. One and only one of 'values\_\*'s should + be set. + +Returns +======= +Y : Var + Type T2. + Output data. This tensor's element type is based on the values\_\* + attribute set. + +Notes +===== +Signature: ``ai.onnx.ml@4::LabelEncoder``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - return ( - _LabelEncoder( - _LabelEncoder.Attributes( - default_float=AttrFloat32(default_float, name="default_float"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - default_tensor=AttrTensor.maybe(default_tensor, name="default_tensor"), - keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), - keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), - keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), - keys_tensor=AttrTensor.maybe(keys_tensor, name="keys_tensor"), - values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), - values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), - values_strings=AttrStrings.maybe(values_strings, name="values_strings"), - values_tensor=AttrTensor.maybe(values_tensor, name="values_tensor"), - ), - _LabelEncoder.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _LabelEncoder( + _LabelEncoder.Attributes( + default_float=AttrFloat32(default_float, name="default_float"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + default_tensor=AttrTensor.maybe(default_tensor, name="default_tensor"), + keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), + keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), + keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), + keys_tensor=AttrTensor.maybe(keys_tensor, name="keys_tensor"), + values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), + values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), + values_strings=AttrStrings.maybe(values_strings, name="values_strings"), + values_tensor=AttrTensor.maybe(values_tensor, name="values_tensor"), + ), _LabelEncoder.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y _OPERATORS = { @@ -260,4 +228,4 @@ def label_encoder( "ZipMap": zip_map, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index c35f6c9a..c1c90c3e 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -1,60 +1,57 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: BSD-3-Clause - # ruff: noqa: E741 -- Allow ambiguous variable name -from collections.abc import Iterable +import typing +import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( + Any, + Callable, Optional, + Union, ) +from typing import cast as typing_cast import numpy as np +import numpy.typing as npt +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( + AttrDtype, + AttrFloat32, + AttrFloat32s, + AttrGraph, AttrInt64, AttrInt64s, + AttrString, + AttrStrings, AttrTensor, + AttrType, ) -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs +from spox._graph import Graph, subgraph +from spox._internal_op import intro from spox._node import OpType -from spox._standard import StandardNode -from spox._var import Var, VarInfo, get_value, unwrap_vars -from spox.opset.ai.onnx.ml.v4 import ( - _ArrayFeatureExtractor, - _Binarizer, - _CastMap, - _CategoryMapper, - _DictVectorizer, - _FeatureVectorizer, - _Imputer, - _LabelEncoder, - _LinearClassifier, - _LinearRegressor, - _Normalizer, - _OneHotEncoder, - _Scaler, - _SVMClassifier, - _SVMRegressor, - _ZipMap, - array_feature_extractor, - binarizer, - cast_map, - category_mapper, - dict_vectorizer, - feature_vectorizer, - imputer, - label_encoder, - linear_classifier, - linear_regressor, - normalizer, - one_hot_encoder, - scaler, - svmclassifier, - svmregressor, - zip_map, -) +from spox._standard import InferenceError, StandardNode +from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._value_prop import PropValueType +from spox.opset.ai.onnx.ml.v4 import _ArrayFeatureExtractor, array_feature_extractor +from spox.opset.ai.onnx.ml.v4 import _Binarizer, binarizer +from spox.opset.ai.onnx.ml.v4 import _CastMap, cast_map +from spox.opset.ai.onnx.ml.v4 import _CategoryMapper, category_mapper +from spox.opset.ai.onnx.ml.v4 import _DictVectorizer, dict_vectorizer +from spox.opset.ai.onnx.ml.v4 import _FeatureVectorizer, feature_vectorizer +from spox.opset.ai.onnx.ml.v4 import _Imputer, imputer +from spox.opset.ai.onnx.ml.v4 import _LabelEncoder, label_encoder +from spox.opset.ai.onnx.ml.v4 import _LinearClassifier, linear_classifier +from spox.opset.ai.onnx.ml.v4 import _LinearRegressor, linear_regressor +from spox.opset.ai.onnx.ml.v4 import _Normalizer, normalizer +from spox.opset.ai.onnx.ml.v4 import _OneHotEncoder, one_hot_encoder +from spox.opset.ai.onnx.ml.v4 import _SVMClassifier, svmclassifier +from spox.opset.ai.onnx.ml.v4 import _SVMRegressor, svmregressor +from spox.opset.ai.onnx.ml.v4 import _Scaler, scaler +from spox.opset.ai.onnx.ml.v4 import _ZipMap, zip_map class _TreeEnsemble(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -89,181 +86,142 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - -def tree_ensemble( - X: Var, - *, - aggregate_function: int = 1, - leaf_targetids: Iterable[int], - leaf_weights: np.ndarray, - membership_values: Optional[np.ndarray] = None, - n_targets: Optional[int] = None, - nodes_falseleafs: Iterable[int], - nodes_falsenodeids: Iterable[int], - nodes_featureids: Iterable[int], - nodes_hitrates: Optional[np.ndarray] = None, - nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, - nodes_modes: np.ndarray, - nodes_splits: np.ndarray, - nodes_trueleafs: Iterable[int], - nodes_truenodeids: Iterable[int], - post_transform: int = 0, - tree_roots: Iterable[int], -) -> Var: +def tree_ensemble(X: Var, *, aggregate_function: int = 1, leaf_targetids: Iterable[int], leaf_weights: np.ndarray, membership_values: Optional[np.ndarray] = None, n_targets: Optional[int] = None, nodes_falseleafs: Iterable[int], nodes_falsenodeids: Iterable[int], nodes_featureids: Iterable[int], nodes_hitrates: Optional[np.ndarray] = None, nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, nodes_modes: np.ndarray, nodes_splits: np.ndarray, nodes_trueleafs: Iterable[int], nodes_truenodeids: Iterable[int], post_transform: int = 0, tree_roots: Iterable[int], ) -> Var: r""" - Tree Ensemble operator. Returns the regressed values for each input in a - batch. Inputs have dimensions ``[N, F]`` where ``N`` is the input batch - size and ``F`` is the number of input features. Outputs have dimensions - ``[N, num_targets]`` where ``N`` is the batch size and ``num_targets`` - is the number of targets, which is a configurable attribute. +Tree Ensemble operator. Returns the regressed values for each input in a +batch. Inputs have dimensions ``[N, F]`` where ``N`` is the input batch +size and ``F`` is the number of input features. Outputs have dimensions +``[N, num_targets]`` where ``N`` is the batch size and ``num_targets`` +is the number of targets, which is a configurable attribute. - :: +:: - The encoding of this attribute is split along interior nodes and the leaves of the trees. Notably, attributes with the prefix `nodes_*` are associated with interior nodes, and attributes with the prefix `leaf_*` are associated with leaves. - The attributes `nodes_*` must all have the same length and encode a sequence of tuples, as defined by taking all the `nodes_*` fields at a given position. + The encoding of this attribute is split along interior nodes and the leaves of the trees. Notably, attributes with the prefix `nodes_*` are associated with interior nodes, and attributes with the prefix `leaf_*` are associated with leaves. + The attributes `nodes_*` must all have the same length and encode a sequence of tuples, as defined by taking all the `nodes_*` fields at a given position. - All fields prefixed with `leaf_*` represent tree leaves, and similarly define tuples of leaves and must have identical length. + All fields prefixed with `leaf_*` represent tree leaves, and similarly define tuples of leaves and must have identical length. - This operator can be used to implement both the previous `TreeEnsembleRegressor` and `TreeEnsembleClassifier` nodes. - The `TreeEnsembleRegressor` node maps directly to this node and requires changing how the nodes are represented. - The `TreeEnsembleClassifier` node can be implemented by adding a `ArgMax` node after this node to determine the top class. - To encode class labels, a `LabelEncoder` or `GatherND` operator may be used. + This operator can be used to implement both the previous `TreeEnsembleRegressor` and `TreeEnsembleClassifier` nodes. + The `TreeEnsembleRegressor` node maps directly to this node and requires changing how the nodes are represented. + The `TreeEnsembleClassifier` node can be implemented by adding a `ArgMax` node after this node to determine the top class. + To encode class labels, a `LabelEncoder` or `GatherND` operator may be used. - Parameters - ========== - X - Type T. - Input of shape [Batch Size, Number of Features] - aggregate_function - Attribute. - Defines how to aggregate leaf values within a target. One of 'AVERAGE' - (0) 'SUM' (1) 'MIN' (2) 'MAX (3) defaults to 'SUM' (1) - leaf_targetids - Attribute. - The index of the target that this leaf contributes to (this must be in - range ``[0, n_targets)``). - leaf_weights - Attribute. - The weight for each leaf. - membership_values - Attribute. - Members to test membership of for each set membership node. List all of - the members to test again in the order that the 'BRANCH_MEMBER' mode - appears in ``node_modes``, delimited by ``NaN``\ s. Will have the same - number of sets of values as nodes with mode 'BRANCH_MEMBER'. This may be - omitted if the node doesn't contain any 'BRANCH_MEMBER' nodes. - n_targets - Attribute. - The total number of targets. - nodes_falseleafs - Attribute. - 1 if false branch is leaf for each node and 0 if an interior node. To - represent a tree that is a leaf (only has one node), one can do so by - having a single ``nodes_*`` entry with true and false branches - referencing the same ``leaf_*`` entry - nodes_falsenodeids - Attribute. - If ``nodes_falseleafs`` is false at an entry, this represents the - position of the false branch node. This position can be used to index - into a ``nodes_*`` entry. If ``nodes_falseleafs`` is false, it is an - index into the leaf\_\* attributes. - nodes_featureids - Attribute. - Feature id for each node. - nodes_hitrates - Attribute. - Popularity of each node, used for performance and may be omitted. - nodes_missing_value_tracks_true - Attribute. - For each node, define whether to follow the true branch (if attribute - value is 1) or false branch (if attribute value is 0) in the presence of - a NaN input feature. This attribute may be left undefined and the - default value is false (0) for all nodes. - nodes_modes - Attribute. - The comparison operation performed by the node. This is encoded as an - enumeration of 0 ('BRANCH_LEQ'), 1 ('BRANCH_LT'), 2 ('BRANCH_GTE'), 3 - ('BRANCH_GT'), 4 ('BRANCH_EQ'), 5 ('BRANCH_NEQ'), and 6 - ('BRANCH_MEMBER'). Note this is a tensor of type uint8. - nodes_splits - Attribute. - Thresholds to do the splitting on for each node with mode that is not - 'BRANCH_MEMBER'. - nodes_trueleafs - Attribute. - 1 if true branch is leaf for each node and 0 an interior node. To - represent a tree that is a leaf (only has one node), one can do so by - having a single ``nodes_*`` entry with true and false branches - referencing the same ``leaf_*`` entry - nodes_truenodeids - Attribute. - If ``nodes_trueleafs`` is false at an entry, this represents the - position of the true branch node. This position can be used to index - into a ``nodes_*`` entry. If ``nodes_trueleafs`` is false, it is an - index into the leaf\_\* attributes. - post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE' (0), - 'SOFTMAX' (1), 'LOGISTIC' (2), 'SOFTMAX_ZERO' (3) or 'PROBIT' (4), - defaults to 'NONE' (0) - tree_roots - Attribute. - Index into ``nodes_*`` for the root of each tree. The tree structure is - derived from the branching of each node. +Parameters +========== +X + Type T. + Input of shape [Batch Size, Number of Features] +aggregate_function + Attribute. + Defines how to aggregate leaf values within a target. One of 'AVERAGE' + (0) 'SUM' (1) 'MIN' (2) 'MAX (3) defaults to 'SUM' (1) +leaf_targetids + Attribute. + The index of the target that this leaf contributes to (this must be in + range ``[0, n_targets)``). +leaf_weights + Attribute. + The weight for each leaf. +membership_values + Attribute. + Members to test membership of for each set membership node. List all of + the members to test again in the order that the 'BRANCH_MEMBER' mode + appears in ``node_modes``, delimited by ``NaN``\ s. Will have the same + number of sets of values as nodes with mode 'BRANCH_MEMBER'. This may be + omitted if the node doesn't contain any 'BRANCH_MEMBER' nodes. +n_targets + Attribute. + The total number of targets. +nodes_falseleafs + Attribute. + 1 if false branch is leaf for each node and 0 if an interior node. To + represent a tree that is a leaf (only has one node), one can do so by + having a single ``nodes_*`` entry with true and false branches + referencing the same ``leaf_*`` entry +nodes_falsenodeids + Attribute. + If ``nodes_falseleafs`` is false at an entry, this represents the + position of the false branch node. This position can be used to index + into a ``nodes_*`` entry. If ``nodes_falseleafs`` is false, it is an + index into the leaf\_\* attributes. +nodes_featureids + Attribute. + Feature id for each node. +nodes_hitrates + Attribute. + Popularity of each node, used for performance and may be omitted. +nodes_missing_value_tracks_true + Attribute. + For each node, define whether to follow the true branch (if attribute + value is 1) or false branch (if attribute value is 0) in the presence of + a NaN input feature. This attribute may be left undefined and the + default value is false (0) for all nodes. +nodes_modes + Attribute. + The comparison operation performed by the node. This is encoded as an + enumeration of 0 ('BRANCH_LEQ'), 1 ('BRANCH_LT'), 2 ('BRANCH_GTE'), 3 + ('BRANCH_GT'), 4 ('BRANCH_EQ'), 5 ('BRANCH_NEQ'), and 6 + ('BRANCH_MEMBER'). Note this is a tensor of type uint8. +nodes_splits + Attribute. + Thresholds to do the splitting on for each node with mode that is not + 'BRANCH_MEMBER'. +nodes_trueleafs + Attribute. + 1 if true branch is leaf for each node and 0 an interior node. To + represent a tree that is a leaf (only has one node), one can do so by + having a single ``nodes_*`` entry with true and false branches + referencing the same ``leaf_*`` entry +nodes_truenodeids + Attribute. + If ``nodes_trueleafs`` is false at an entry, this represents the + position of the true branch node. This position can be used to index + into a ``nodes_*`` entry. If ``nodes_trueleafs`` is false, it is an + index into the leaf\_\* attributes. +post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE' (0), + 'SOFTMAX' (1), 'LOGISTIC' (2), 'SOFTMAX_ZERO' (3) or 'PROBIT' (4), + defaults to 'NONE' (0) +tree_roots + Attribute. + Index into ``nodes_*`` for the root of each tree. The tree structure is + derived from the branching of each node. - Returns - ======= - Y : Var - Type T. - Output of shape [Batch Size, Number of targets] +Returns +======= +Y : Var + Type T. + Output of shape [Batch Size, Number of targets] - Notes - ===== - Signature: ``ai.onnx.ml@5::TreeEnsemble``. +Notes +===== +Signature: ``ai.onnx.ml@5::TreeEnsemble``. - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _TreeEnsemble( - _TreeEnsemble.Attributes( - aggregate_function=AttrInt64( - aggregate_function, name="aggregate_function" - ), - leaf_targetids=AttrInt64s(leaf_targetids, name="leaf_targetids"), - leaf_weights=AttrTensor(leaf_weights, name="leaf_weights"), - membership_values=AttrTensor.maybe( - membership_values, name="membership_values" - ), - n_targets=AttrInt64.maybe(n_targets, name="n_targets"), - nodes_falseleafs=AttrInt64s(nodes_falseleafs, name="nodes_falseleafs"), - nodes_falsenodeids=AttrInt64s( - nodes_falsenodeids, name="nodes_falsenodeids" - ), - nodes_featureids=AttrInt64s(nodes_featureids, name="nodes_featureids"), - nodes_hitrates=AttrTensor.maybe(nodes_hitrates, name="nodes_hitrates"), - nodes_missing_value_tracks_true=AttrInt64s.maybe( - nodes_missing_value_tracks_true, - name="nodes_missing_value_tracks_true", - ), - nodes_modes=AttrTensor(nodes_modes, name="nodes_modes"), - nodes_splits=AttrTensor(nodes_splits, name="nodes_splits"), - nodes_trueleafs=AttrInt64s(nodes_trueleafs, name="nodes_trueleafs"), - nodes_truenodeids=AttrInt64s( - nodes_truenodeids, name="nodes_truenodeids" - ), - post_transform=AttrInt64(post_transform, name="post_transform"), - tree_roots=AttrInt64s(tree_roots, name="tree_roots"), - ), - _TreeEnsemble.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _TreeEnsemble( + _TreeEnsemble.Attributes( + aggregate_function=AttrInt64(aggregate_function, name="aggregate_function"), + leaf_targetids=AttrInt64s(leaf_targetids, name="leaf_targetids"), + leaf_weights=AttrTensor(leaf_weights, name="leaf_weights"), + membership_values=AttrTensor.maybe(membership_values, name="membership_values"), + n_targets=AttrInt64.maybe(n_targets, name="n_targets"), + nodes_falseleafs=AttrInt64s(nodes_falseleafs, name="nodes_falseleafs"), + nodes_falsenodeids=AttrInt64s(nodes_falsenodeids, name="nodes_falsenodeids"), + nodes_featureids=AttrInt64s(nodes_featureids, name="nodes_featureids"), + nodes_hitrates=AttrTensor.maybe(nodes_hitrates, name="nodes_hitrates"), + nodes_missing_value_tracks_true=AttrInt64s.maybe(nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true"), + nodes_modes=AttrTensor(nodes_modes, name="nodes_modes"), + nodes_splits=AttrTensor(nodes_splits, name="nodes_splits"), + nodes_trueleafs=AttrInt64s(nodes_trueleafs, name="nodes_trueleafs"), + nodes_truenodeids=AttrInt64s(nodes_truenodeids, name="nodes_truenodeids"), + post_transform=AttrInt64(post_transform, name="post_transform"), + tree_roots=AttrInt64s(tree_roots, name="tree_roots"), + ), _TreeEnsemble.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y _OPERATORS = { @@ -306,4 +264,4 @@ def tree_ensemble( "ZipMap": zip_map, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index cc4ffc60..023e5da7 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -1,18 +1,21 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: BSD-3-Clause - # ruff: noqa: E741 -- Allow ambiguous variable name -from collections.abc import Iterable, Sequence +import typing +import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( + Any, Callable, Optional, + Union, ) from typing import cast as typing_cast import numpy as np import numpy.typing as npt +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, AttrFloat32, @@ -25,14 +28,12 @@ AttrTensor, AttrType, ) -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._graph import Graph, subgraph +from spox._internal_op import intro from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import Sequence as SpoxSequence -from spox._type_system import Tensor, Type +from spox._type_system import Tensor, Type, Sequence as SpoxSequence from spox._value_prop import PropValueType -from spox._var import Var, VarInfo, get_value, unwrap_vars class _Abs(StandardNode): @@ -54,7 +55,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Acos(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -74,7 +74,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Acosh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -94,7 +93,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Add(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -115,7 +113,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _And(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -136,7 +133,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ArgMax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -158,7 +154,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ArgMin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -180,7 +175,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Asin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -200,7 +194,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Asinh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -220,7 +213,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Atan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -240,7 +232,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Atanh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -260,7 +251,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _AveragePool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -285,7 +275,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _BatchNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -313,7 +302,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Bernoulli(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -334,7 +322,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _BitShift(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -355,7 +342,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _BlackmanWindow(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -376,7 +362,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Cast(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -396,7 +381,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _CastLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -417,7 +401,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Ceil(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -437,7 +420,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Celu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -457,7 +439,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Clip(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -479,7 +460,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Compress(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -494,39 +474,30 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): output: VarInfo - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: self.infer_output_types_onnx() - inp, cond = ( - self.inputs.input.unwrap_tensor(), - self.inputs.condition.unwrap_tensor(), - ) + inp, cond = self.inputs.input.unwrap_tensor(), self.inputs.condition.unwrap_tensor() if not inp.shape: - return {"output": Tensor(inp.dtype, None)} + return {'output': Tensor(inp.dtype, None)} if cond.dtype != np.dtype(bool): raise InferenceError("Compress input 'condition' must be a boolean dtype.") if cond.shape and len(cond.shape) != 1: - raise InferenceError( - "Compress input 'condition' must be a vector (of rank 1)." - ) + raise InferenceError("Compress input 'condition' must be a vector (of rank 1).") if self.attrs.axis is not None: shape = list(inp.shape) axis = self.attrs.axis.value if not (-len(shape) <= axis < len(shape)): - raise InferenceError( - f"Compress attribute 'axis' must in range [-rank, rank-1] (rank={len(shape)})." - ) + raise InferenceError(f"Compress attribute 'axis' must in range [-rank, rank-1] (rank={len(shape)}).") shape[axis] = None else: shape = [None] - return {"output": Tensor(inp.dtype, tuple(shape))} - + return {'output': Tensor(inp.dtype, tuple(shape))} op_type = OpType("Compress", "", 11) attrs: Attributes inputs: Inputs outputs: Outputs - class _Concat(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -546,7 +517,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ConcatFromSequence(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -567,7 +537,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Constant(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -586,9 +555,7 @@ class Outputs(BaseOutputs): output: VarInfo def propagate_values(self, initializers) -> dict[str, PropValueType]: - ((key, raw),) = ( - (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None - ) + ((key, raw),) = ((k, v.value) for k, v in self.attrs.get_fields().items() if v is not None) if key == "value": value = raw elif key == "value_float": @@ -606,18 +573,14 @@ def propagate_values(self, initializers) -> dict[str, PropValueType]: elif key == "sparse_value": return {} else: - raise RuntimeError( - f"Could not extract the set Constant value attribute, got: {key}" - ) + raise RuntimeError(f"Could not extract the set Constant value attribute, got: {key}") return {"output": value} - op_type = OpType("Constant", "", 13) attrs: Attributes inputs: BaseInputs outputs: Outputs - class _ConstantOfShape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -637,7 +600,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Conv(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -664,7 +626,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ConvInteger(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -692,7 +653,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ConvTranspose(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -721,7 +681,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Cos(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -741,7 +700,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Cosh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -761,7 +719,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _CumSum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -783,7 +740,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _DFT(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -806,7 +762,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _DepthToSpace(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -827,7 +782,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _DequantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -849,7 +803,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Det(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -869,7 +822,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Div(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -890,7 +842,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Dropout(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -913,7 +864,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _DynamicQuantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -935,7 +885,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Einsum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -955,7 +904,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Elu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -975,7 +923,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Equal(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -996,7 +943,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Erf(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1016,7 +962,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Exp(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1036,7 +981,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Expand(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1057,7 +1001,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _EyeLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1078,7 +1021,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Flatten(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1098,7 +1040,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Floor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1118,7 +1059,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GRU(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1151,7 +1091,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Gather(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1172,7 +1111,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GatherElements(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1193,7 +1131,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GatherND(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1214,7 +1151,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Gemm(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1239,7 +1175,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GlobalAveragePool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1259,7 +1194,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GlobalLpPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1279,7 +1213,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GlobalMaxPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1299,7 +1232,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Greater(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1320,7 +1252,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GreaterOrEqual(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1341,7 +1272,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GridSample(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1364,7 +1294,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _HammingWindow(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1385,7 +1314,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _HannWindow(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1406,7 +1334,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _HardSigmoid(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1427,7 +1354,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _HardSwish(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1447,7 +1373,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Hardmax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1467,7 +1392,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Identity(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1487,7 +1411,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _If(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1508,7 +1431,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _InstanceNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1530,7 +1452,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _IsInf(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1551,7 +1472,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _IsNaN(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1571,7 +1491,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LRN(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1594,7 +1513,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LSTM(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1630,7 +1548,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LayerNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1656,7 +1573,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LeakyRelu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1676,7 +1592,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Less(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1697,7 +1612,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LessOrEqual(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1718,7 +1632,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Log(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1738,7 +1651,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LogSoftmax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1758,7 +1670,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Loop(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1774,7 +1685,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): v_final_and_scan_outputs: Sequence[VarInfo] - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: output_types = super().infer_output_types() body = self.attrs.body.value @@ -1787,14 +1698,12 @@ def infer_output_types(self) -> dict[str, Type]: output_types[name] = typ return output_types - op_type = OpType("Loop", "", 16) attrs: Attributes inputs: Inputs outputs: Outputs - class _LpNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1815,7 +1724,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LpPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1839,7 +1747,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _MatMul(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1860,7 +1767,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _MatMulInteger(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1883,7 +1789,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Max(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1903,7 +1808,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _MaxPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1930,7 +1834,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _MaxRoiPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1952,7 +1855,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _MaxUnpool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1976,7 +1878,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Mean(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1996,7 +1897,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _MeanVarianceNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2016,7 +1916,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _MelWeightMatrix(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2040,7 +1939,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Min(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2060,7 +1958,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Mod(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2081,7 +1978,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Mul(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2102,7 +1998,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Multinomial(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2124,7 +2019,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Neg(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2144,7 +2038,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _NegativeLogLikelihoodLoss(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2167,7 +2060,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _NonMaxSuppression(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2191,7 +2083,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _NonZero(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2211,7 +2102,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Not(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2231,7 +2121,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _OneHot(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2253,7 +2142,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Optional(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2273,7 +2161,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _OptionalGetElement(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2293,7 +2180,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _OptionalHasElement(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2313,7 +2199,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Or(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2334,7 +2219,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _PRelu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2355,7 +2239,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Pad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2377,7 +2260,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Pow(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2398,7 +2280,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _QLinearConv(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2431,7 +2312,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _QLinearMatMul(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2458,7 +2338,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _QuantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2480,7 +2359,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _RNN(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2512,7 +2390,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _RandomNormal(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2534,7 +2411,6 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs - class _RandomNormalLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2557,7 +2433,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _RandomUniform(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2579,7 +2454,6 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs - class _RandomUniformLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2602,7 +2476,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Range(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2624,7 +2497,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Reciprocal(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2644,7 +2516,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceL1(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2665,7 +2536,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceL2(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2686,7 +2556,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceLogSum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2707,7 +2576,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceLogSumExp(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2728,7 +2596,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceMax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2749,7 +2616,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceMean(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2770,7 +2636,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceMin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2791,7 +2656,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceProd(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2812,7 +2676,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceSum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2834,7 +2697,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceSumSquare(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2855,7 +2717,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Relu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2875,7 +2736,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Reshape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2896,7 +2756,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Resize(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2924,7 +2783,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReverseSequence(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2946,7 +2804,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _RoiAlign(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2973,7 +2830,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Round(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2993,7 +2849,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _STFT(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3016,7 +2871,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Scan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3041,7 +2895,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ScatterElements(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3064,7 +2917,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ScatterND(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3086,7 +2938,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Selu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3107,7 +2958,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SequenceAt(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3128,7 +2978,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SequenceConstruct(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3148,7 +2997,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SequenceEmpty(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3166,7 +3014,6 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs - class _SequenceErase(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3187,7 +3034,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SequenceInsert(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3209,7 +3055,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SequenceLength(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3229,7 +3074,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SequenceMap(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3250,7 +3094,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Shape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3271,7 +3114,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Shrink(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3292,7 +3134,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Sigmoid(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3312,7 +3153,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Sign(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3332,7 +3172,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Sin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3352,7 +3191,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Sinh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3372,7 +3210,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Size(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3392,7 +3229,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Slice(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3416,7 +3252,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Softmax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3436,7 +3271,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SoftmaxCrossEntropyLoss(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3460,7 +3294,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Softplus(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3480,7 +3313,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Softsign(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3500,7 +3332,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SpaceToDepth(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3520,7 +3351,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Split(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3541,7 +3371,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _SplitToSequence(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3563,7 +3392,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Sqrt(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3583,7 +3411,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Squeeze(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3604,7 +3431,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _StringNormalizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3627,7 +3453,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Sub(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3648,7 +3473,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Sum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3668,7 +3492,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Tan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3688,7 +3511,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Tanh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3708,7 +3530,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _TfIdfVectorizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3736,7 +3557,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ThresholdedRelu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3756,7 +3576,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Tile(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3777,7 +3596,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _TopK(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3801,7 +3619,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Transpose(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3821,7 +3638,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Trilu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3842,7 +3658,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Unique(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3866,7 +3681,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Unsqueeze(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3887,7 +3701,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Where(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3909,7 +3722,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Xor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3930,12781 +3742,10266 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - -def abs( - X: Var, -) -> Var: +def abs(X: Var, ) -> Var: r""" - Absolute takes one input data (Tensor) and produces one output data - (Tensor) where absolute value, y = abs(x), is applied to the tensor - elementwise. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::Abs``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Abs( - _Abs.Attributes(), - _Abs.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def acos( - input: Var, -) -> Var: - r""" - Calculates the arccosine (inverse of cosine) of the given input tensor, - element-wise. +Absolute takes one input data (Tensor) and produces one output data +(Tensor) where absolute value, y = abs(x), is applied to the tensor +elementwise. - Parameters - ========== - input - Type T. - Input tensor +Parameters +========== +X + Type T. + Input tensor - Returns - ======= - output : Var - Type T. - The arccosine of the input tensor computed element-wise +Returns +======= +Y : Var + Type T. + Output tensor - Notes - ===== - Signature: ``ai.onnx@7::Acos``. +Notes +===== +Signature: ``ai.onnx@13::Abs``. - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Acos( - _Acos.Attributes(), - _Acos.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Abs( + _Abs.Attributes( + ), _Abs.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def acosh( - input: Var, -) -> Var: +def acos(input: Var, ) -> Var: r""" - Calculates the hyperbolic arccosine of the given input tensor - element-wise. +Calculates the arccosine (inverse of cosine) of the given input tensor, +element-wise. - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The hyperbolic arccosine values of the input tensor computed - element-wise - - Notes - ===== - Signature: ``ai.onnx@9::Acosh``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Acosh( - _Acosh.Attributes(), - _Acosh.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) +Parameters +========== +input + Type T. + Input tensor +Returns +======= +output : Var + Type T. + The arccosine of the input tensor computed element-wise -def add( - A: Var, - B: Var, -) -> Var: - r""" - Performs element-wise binary addition (with Numpy-style broadcasting - support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - (Opset 14 change): Extend supported types to include uint8, int8, - uint16, and int16. - - Parameters - ========== - A - Type T. - First operand. - B - Type T. - Second operand. - - Returns - ======= - C : Var - Type T. - Result, has same element type as two inputs - - Notes - ===== - Signature: ``ai.onnx@14::Add``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Notes +===== +Signature: ``ai.onnx@7::Acos``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _Add( - _Add.Attributes(), - _Add.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) + return _Acos( + _Acos.Attributes( + ), _Acos.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def and_( - A: Var, - B: Var, -) -> Var: +def acosh(input: Var, ) -> Var: r""" - Returns the tensor resulted from performing the ``and`` logical - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@7::And``. - - Type constraints: - - T: `tensor(bool)` - - T1: `tensor(bool)` - """ - return ( - _And( - _And.Attributes(), - _And.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) +Calculates the hyperbolic arccosine of the given input tensor +element-wise. +Parameters +========== +input + Type T. + Input tensor -def arg_max( - data: Var, - *, - axis: int = 0, - keepdims: int = 1, - select_last_index: int = 0, -) -> Var: - r""" - Computes the indices of the max elements of the input tensor's element - along the provided axis. The resulting tensor has the same rank as the - input if keepdims equals 1. If keepdims equals 0, then the resulting - tensor has the reduced dimension pruned. If select_last_index is True - (default False), the index of the last occurrence of the max is selected - if the max appears more than once in the input. Otherwise the index of - the first occurrence is selected. The type of the output tensor is - integer. - - Parameters - ========== - data - Type T. - An input tensor. - axis - Attribute. - The axis in which to compute the arg indices. Accepted range is [-r, - r-1] where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - select_last_index - Attribute. - Whether to select the last index or the first index if the {name} - appears in multiple indices, default is False (first index). - - Returns - ======= - reduced : Var - Type tensor(int64). - Reduced output tensor with integer data type. - - Notes - ===== - Signature: ``ai.onnx@13::ArgMax``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Returns +======= +output : Var + Type T. + The hyperbolic arccosine values of the input tensor computed + element-wise + +Notes +===== +Signature: ``ai.onnx@9::Acosh``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _ArgMax( - _ArgMax.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - select_last_index=AttrInt64( - select_last_index, name="select_last_index" - ), - ), - _ArgMax.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) + return _Acosh( + _Acosh.Attributes( + ), _Acosh.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def arg_min( - data: Var, - *, - axis: int = 0, - keepdims: int = 1, - select_last_index: int = 0, -) -> Var: - r""" - Computes the indices of the min elements of the input tensor's element - along the provided axis. The resulting tensor has the same rank as the - input if keepdims equals 1. If keepdims equals 0, then the resulting - tensor has the reduced dimension pruned. If select_last_index is True - (default False), the index of the last occurrence of the min is selected - if the min appears more than once in the input. Otherwise the index of - the first occurrence is selected. The type of the output tensor is - integer. - - Parameters - ========== - data - Type T. - An input tensor. - axis - Attribute. - The axis in which to compute the arg indices. Accepted range is [-r, - r-1] where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - select_last_index - Attribute. - Whether to select the last index or the first index if the {name} - appears in multiple indices, default is False (first index). - - Returns - ======= - reduced : Var - Type tensor(int64). - Reduced output tensor with integer data type. - - Notes - ===== - Signature: ``ai.onnx@13::ArgMin``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +def add(A: Var, B: Var, ) -> Var: + r""" +Performs element-wise binary addition (with Numpy-style broadcasting +support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +(Opset 14 change): Extend supported types to include uint8, int8, +uint16, and int16. + +Parameters +========== +A + Type T. + First operand. +B + Type T. + Second operand. + +Returns +======= +C : Var + Type T. + Result, has same element type as two inputs + +Notes +===== +Signature: ``ai.onnx@14::Add``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Add( + _Add.Attributes( + ), _Add.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def and_(A: Var, B: Var, ) -> Var: + r""" +Returns the tensor resulted from performing the ``and`` logical +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. + +Returns +======= +C : Var + Type T1. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@7::And``. + +Type constraints: + - T: `tensor(bool)` + - T1: `tensor(bool)` + """ + return _And( + _And.Attributes( + ), _And.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def arg_max(data: Var, *, axis: int = 0, keepdims: int = 1, select_last_index: int = 0, ) -> Var: + r""" +Computes the indices of the max elements of the input tensor's element +along the provided axis. The resulting tensor has the same rank as the +input if keepdims equals 1. If keepdims equals 0, then the resulting +tensor has the reduced dimension pruned. If select_last_index is True +(default False), the index of the last occurrence of the max is selected +if the max appears more than once in the input. Otherwise the index of +the first occurrence is selected. The type of the output tensor is +integer. + +Parameters +========== +data + Type T. + An input tensor. +axis + Attribute. + The axis in which to compute the arg indices. Accepted range is [-r, + r-1] where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +select_last_index + Attribute. + Whether to select the last index or the first index if the {name} + appears in multiple indices, default is False (first index). + +Returns +======= +reduced : Var + Type tensor(int64). + Reduced output tensor with integer data type. + +Notes +===== +Signature: ``ai.onnx@13::ArgMax``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ArgMax( + _ArgMax.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + select_last_index=AttrInt64(select_last_index, name="select_last_index"), + ), _ArgMax.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def arg_min(data: Var, *, axis: int = 0, keepdims: int = 1, select_last_index: int = 0, ) -> Var: + r""" +Computes the indices of the min elements of the input tensor's element +along the provided axis. The resulting tensor has the same rank as the +input if keepdims equals 1. If keepdims equals 0, then the resulting +tensor has the reduced dimension pruned. If select_last_index is True +(default False), the index of the last occurrence of the min is selected +if the min appears more than once in the input. Otherwise the index of +the first occurrence is selected. The type of the output tensor is +integer. + +Parameters +========== +data + Type T. + An input tensor. +axis + Attribute. + The axis in which to compute the arg indices. Accepted range is [-r, + r-1] where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +select_last_index + Attribute. + Whether to select the last index or the first index if the {name} + appears in multiple indices, default is False (first index). + +Returns +======= +reduced : Var + Type tensor(int64). + Reduced output tensor with integer data type. + +Notes +===== +Signature: ``ai.onnx@13::ArgMin``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ArgMin( + _ArgMin.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + select_last_index=AttrInt64(select_last_index, name="select_last_index"), + ), _ArgMin.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def asin(input: Var, ) -> Var: + r""" +Calculates the arcsine (inverse of sine) of the given input tensor, +element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The arcsine of the input tensor computed element-wise + +Notes +===== +Signature: ``ai.onnx@7::Asin``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Asin( + _Asin.Attributes( + ), _Asin.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def asinh(input: Var, ) -> Var: + r""" +Calculates the hyperbolic arcsine of the given input tensor +element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The hyperbolic arcsine values of the input tensor computed element-wise + +Notes +===== +Signature: ``ai.onnx@9::Asinh``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _ArgMin( - _ArgMin.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - select_last_index=AttrInt64( - select_last_index, name="select_last_index" - ), - ), - _ArgMin.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) + return _Asinh( + _Asinh.Attributes( + ), _Asinh.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def asin( - input: Var, -) -> Var: +def atan(input: Var, ) -> Var: r""" - Calculates the arcsine (inverse of sine) of the given input tensor, - element-wise. +Calculates the arctangent (inverse of tangent) of the given input +tensor, element-wise. - Parameters - ========== - input - Type T. - Input tensor +Parameters +========== +input + Type T. + Input tensor - Returns - ======= - output : Var - Type T. - The arcsine of the input tensor computed element-wise +Returns +======= +output : Var + Type T. + The arctangent of the input tensor computed element-wise - Notes - ===== - Signature: ``ai.onnx@7::Asin``. +Notes +===== +Signature: ``ai.onnx@7::Atan``. - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _Asin( - _Asin.Attributes(), - _Asin.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Atan( + _Atan.Attributes( + ), _Atan.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def asinh( - input: Var, -) -> Var: +def atanh(input: Var, ) -> Var: r""" - Calculates the hyperbolic arcsine of the given input tensor - element-wise. +Calculates the hyperbolic arctangent of the given input tensor +element-wise. - Parameters - ========== - input - Type T. - Input tensor +Parameters +========== +input + Type T. + Input tensor - Returns - ======= - output : Var - Type T. - The hyperbolic arcsine values of the input tensor computed element-wise +Returns +======= +output : Var + Type T. + The hyperbolic arctangent values of the input tensor computed + element-wise - Notes - ===== - Signature: ``ai.onnx@9::Asinh``. +Notes +===== +Signature: ``ai.onnx@9::Atanh``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Atanh( + _Atanh.Attributes( + ), _Atanh.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def average_pool(X: Var, *, auto_pad: str = "NOTSET", ceil_mode: int = 0, count_include_pad: int = 0, kernel_shape: Iterable[int], pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + r""" +AveragePool consumes an input tensor X and applies average pooling +across the tensor according to kernel sizes, stride sizes, and pad +lengths. average pooling consisting of computing the average on all +values of a subset of the input tensor according to the kernel size and +downsampling the data into the output tensor Y for further processing. +The output spatial shape will be following: + +:: + + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + +or + +:: + + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + +if ceil_mode is enabled + +:: + + * pad_shape[i] is sum of pads along axis i + +``auto_pad`` is a DEPRECATED attribute. If you are using them currently, +the output spatial shape will be following when ceil_mode is enabled: + +:: + + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + +or when ceil_mode is disabled: + +:: + + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor(input_spatial_shape[i] / strides_spatial_shape[i]) + +And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: + +:: + + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + +The output of each pooling window is divided by the number of elements +(exclude pad when attribute count_include_pad is zero). + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. Optionally, if dimension denotation is in + effect, the operation expects the input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. +ceil_mode + Attribute. + Whether to use ceil or floor (default) to compute the output shape. +count_include_pad + Attribute. + Whether include pad pixels when calculating values for the edges. + Default is 0, doesn't count include pad. +kernel_shape + Attribute. + The size of the kernel along each axis. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + +Returns +======= +Y : Var + Type T. + Output data tensor from average or max pooling across the input tensor. + Dimensions will vary based on various kernel, stride, and pad sizes. + Floor value of the dimension is used + +Notes +===== +Signature: ``ai.onnx@11::AveragePool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _AveragePool( + _AveragePool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + count_include_pad=AttrInt64(count_include_pad, name="count_include_pad"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _AveragePool.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def batch_normalization(X: Var, scale: Var, B: Var, input_mean: Var, input_var: Var, *, epsilon: float = 9.999999747378752e-06, momentum: float = 0.8999999761581421, training_mode: int = 0, ) -> tuple[Var, Var, Var]: + r""" +Carries out batch normalization as described in the paper +https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, +There are five required inputs 'X', 'scale', 'B', 'input_mean' and +'input_var'. Note that 'input_mean' and 'input_var' are expected to be +the estimated statistics in inference mode (training_mode=False, +default), and the running statistics in training mode +(training_mode=True). There are multiple cases for the number of +outputs, which we list below: + +- Output case #1: Y, running_mean, running_var (training_mode=True) +- Output case #2: Y (training_mode=False) + +When training_mode=False, extra outputs are invalid. The outputs are +updated as follows when training_mode=True: + +:: + + running_mean = input_mean * momentum + current_mean * (1 - momentum) + running_var = input_var * momentum + current_var * (1 - momentum) + + Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B + +where: + +:: + + current_mean = ReduceMean(X, axis=all_except_channel_index) + current_var = ReduceVar(X, axis=all_except_channel_index) + +Notice that ``ReduceVar`` refers to the population variance, and it +equals to ``sum(sqrd(x_i - x_avg)) / N`` where ``N`` is the population +size (this formula does not use sample size ``N - 1``). + +The computation of ReduceMean and ReduceVar uses float to avoid overflow +for float16 inputs. + +When training_mode=False: + +:: + + Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B + +For previous (depreciated) non-spatial cases, implementors are suggested +to flatten the input shape to (N x C \* D1 \* D2 \* ... \* Dn) before a +BatchNormalization Op. This operator has **optional** inputs/outputs. +See `the doc `__ for +more details about the representation of optional arguments. An empty +string may be used in the place of an actual argument's name to indicate +a missing argument. Trailing optional arguments (those not followed by +an argument that is present) may also be simply omitted. + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions are in the form + of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number + of channels. Statistics are computed for every channel of C over N and + D1 to Dn dimensions. For image data, input dimensions become (N x C x H + x W). The op also accepts single dimension input of size N in which case + C is assumed to be 1 +scale + Type T1. + Scale tensor of shape (C). +B + Type T1. + Bias tensor of shape (C). +input_mean + Type T2. + running (training) or estimated (testing) mean tensor of shape (C). +input_var + Type T2. + running (training) or estimated (testing) variance tensor of shape (C). +epsilon + Attribute. + The epsilon value to use to avoid division by zero. +momentum + Attribute. + Factor used in computing the running mean and variance.e.g., + running_mean = running_mean \* momentum + mean \* (1 - momentum). +training_mode + Attribute. + If set to true, it indicates BatchNormalization is being used for + training, and outputs 1 and 2 are to be computed. + +Returns +======= +Y : Var + Type T. + The output tensor of the same shape as X +running_mean : Var + Type T2. + The running mean after the BatchNormalization operator. +running_var : Var + Type T2. + The running variance after the BatchNormalization operator. This op uses + the population size (N) for calculating variance, and not the sample + size N-1. + +Notes +===== +Signature: ``ai.onnx@15::BatchNormalization``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _BatchNormalization( + _BatchNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + momentum=AttrFloat32(momentum, name="momentum"), + training_mode=AttrInt64(training_mode, name="training_mode"), + ), _BatchNormalization.Inputs( + X=unwrap_vars(X), scale=unwrap_vars(scale), B=unwrap_vars(B), input_mean=unwrap_vars(input_mean), input_var=unwrap_vars(input_var), ), ).get_output_vars( + X=get_value(X), scale=get_value(scale), B=get_value(B), input_mean=get_value(input_mean), input_var=get_value(input_var), )._unpack_to_any() + + +def bernoulli(input: Var, *, dtype: Optional[npt.DTypeLike] = None, seed: Optional[float] = None, ) -> Var: + r""" +Draws binary random numbers (0 or 1) from a Bernoulli distribution. The +input tensor should be a tensor containing probabilities p (a value in +the range [0,1]) to be used for drawing the binary random number, where +an output of 1 is produced with probability p and an output of 0 is +produced with probability (1-p). + +This operator is non-deterministic and may not produce the same values +in different implementations (even if a seed is specified). + +Parameters +========== +input + Type T1. + All values in input have to be in the range:[0, 1]. +dtype + Attribute. + The data type for the elements of the output tensor. if not specified, + we will use the data type of the input tensor. +seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + +Returns +======= +output : Var + Type T2. + The returned output tensor only has values 0 or 1, same shape as input + tensor. + +Notes +===== +Signature: ``ai.onnx@15::Bernoulli``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Bernoulli( + _Bernoulli.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), _Bernoulli.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def bit_shift(X: Var, Y: Var, *, direction: str, ) -> Var: + r""" +Bitwise shift operator performs element-wise operation. For each input +element, if the attribute "direction" is "RIGHT", this operator moves +its binary representation toward the right side so that the input value +is effectively decreased. If the attribute "direction" is "LEFT", bits +of binary representation moves toward the left side, which results the +increase of its actual value. The input X is the tensor to be shifted +and another input Y specifies the amounts of shifting. For example, if +"direction" is "Right", X is [1, 4], and S is [1, 1], the corresponding +output Z would be [0, 2]. If "direction" is "LEFT" with X=[1, 2] and +S=[1, 2], the corresponding output Y would be [2, 8]. + +Because this operator supports Numpy-style broadcasting, X's and Y's +shapes are not necessarily identical. This operator supports +**multidirectional (i.e., Numpy-style) broadcasting**; for more details +please check `the +doc `__. + +Parameters +========== +X + Type T. + First operand, input to be shifted. +Y + Type T. + Second operand, amounts of shift. +direction + Attribute. + Direction of moving bits. It can be either "RIGHT" (for right shift) or + "LEFT" (for left shift). + +Returns +======= +Z : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@11::BitShift``. + +Type constraints: + - T: `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _BitShift( + _BitShift.Attributes( + direction=AttrString(direction, name="direction"), + ), _BitShift.Inputs( + X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( + X=get_value(X), Y=get_value(Y), ).Z + + +def blackman_window(size: Var, *, output_datatype: int = 1, periodic: int = 1, ) -> Var: + r""" +Generates a Blackman window as described in the paper +https://ieeexplore.ieee.org/document/1455106. + +Parameters +========== +size + Type T1. + A scalar value indicating the length of the window. +output_datatype + Attribute. + The data type of the output tensor. Strictly must be one of the values + from DataType enum in TensorProto whose values correspond to T2. The + default value is 1 = FLOAT. +periodic + Attribute. + If 1, returns a window to be used as periodic function. If 0, return a + symmetric window. When 'periodic' is specified, hann computes a window + of length size + 1 and returns the first size points. The default value + is 1. + +Returns +======= +output : Var + Type T2. + A Blackman window with length: size. The output has the shape: [size]. + +Notes +===== +Signature: ``ai.onnx@17::BlackmanWindow``. + +Type constraints: + - T1: `tensor(int32)`, `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _BlackmanWindow( + _BlackmanWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), _BlackmanWindow.Inputs( + size=unwrap_vars(size), ), ).get_output_vars( + size=get_value(size), ).output + + +def cast(input: Var, *, to: npt.DTypeLike, ) -> Var: + r""" +The operator casts the elements of a given input tensor to a data type +specified by the 'to' argument and returns an output tensor of the same +size in the converted type. The 'to' argument must be one of the data +types specified in the 'DataType' enum field in the TensorProto message. + +Casting from string tensor in plain (e.g., "3.14" and "1000") and +scientific numeric representations (e.g., "1e-5" and "1E8") to float +types is supported. For example, converting string "100.5" to an integer +may yield result 100. There are some string literals reserved for +special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are +positive infinity, negative infinity, and not-a-number, respectively. +Any string which can exactly match "+INF" in a case-insensitive way +would be mapped to positive infinite. Similarly, this case-insensitive +rule is applied to "INF" and "NaN". When casting from numeric tensors to +string tensors, plain floating-point representation (such as +"314.15926") would be used. Converting non-numerical-literal string such +as "Hello World!" is an undefined behavior. Cases of converting string +representing floating-point arithmetic value, such as "2.718", to INT is +an undefined behavior. + +Conversion from a numerical type to any numerical type is always +allowed. User must be aware of precision loss and value change caused by +range difference between two types. For example, a 64-bit float +3.1415926459 may be round to a 32-bit float 3.141592. Similarly, +converting an integer 36 to Boolean may produce 1 because we truncate +bits which can't be stored in the targeted type. + +In more detail, the conversion among numerical types should follow these +rules: + +- Casting from floating point to: + + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. + +- Casting from fixed point to: + + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. + +- Casting from bool to: + + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. + +Parameters +========== +input + Type T1. + Input tensor to be cast. +to + Attribute. + The data type to which the elements of the input tensor are cast. + Strictly must be one of the types from DataType enum in TensorProto + +Returns +======= +output : Var + Type T2. + Output tensor with the same shape as input with type specified by the + 'to' argument + +Notes +===== +Signature: ``ai.onnx@13::Cast``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Cast( + _Cast.Attributes( + to=AttrDtype(to, name="to"), + ), _Cast.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def cast_like(input: Var, target_type: Var, ) -> Var: + r""" +The operator casts the elements of a given input tensor (the first +input) to the same data type as the elements of the second input tensor. +See documentation of the Cast operator for further details. + +Parameters +========== +input + Type T1. + Input tensor to be cast. +target_type + Type T2. + The (first) input tensor will be cast to produce a tensor of the same + type as this (second input) tensor. + +Returns +======= +output : Var + Type T2. + Output tensor produced by casting the first input tensor to have the + same type as the second input tensor. + +Notes +===== +Signature: ``ai.onnx@15::CastLike``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _CastLike( + _CastLike.Attributes( + ), _CastLike.Inputs( + input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), ).get_output_vars( + input=get_value(input), target_type=get_value(target_type), ).output + + +def ceil(X: Var, ) -> Var: + r""" +Ceil takes one input data (Tensor) and produces one output data +(Tensor) where the ceil is, y = ceil(x), is applied to the tensor +elementwise. If x is integral, +0, -0, NaN, or infinite, x itself is +returned. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@13::Ceil``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Ceil( + _Ceil.Attributes( + ), _Ceil.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def celu(X: Var, *, alpha: float = 1.0, ) -> Var: + r""" +Continuously Differentiable Exponential Linear Units: Perform the linear +unit element-wise on the input tensor X using formula: + +:: + + max(0,x) + min(0,alpha*(exp(x/alpha)-1)) + +Parameters +========== +X + Type T. + Input tensor +alpha + Attribute. + The Alpha value in Celu formula which control the shape of the unit. The + default value is 1.0. + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@12::Celu``. + +Type constraints: + - T: `tensor(float)` + """ + return _Celu( + _Celu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), _Celu.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def clip(input: Var, min: Optional[Var] = None, max: Optional[Var] = None, ) -> Var: + r""" +Clip operator limits the given input within an interval. The interval is +specified by the inputs 'min' and 'max'. They default to +numeric_limits::lowest() and numeric_limits::max(), respectively. + +Parameters +========== +input + Type T. + Input tensor whose elements to be clipped +min + Type T. + Minimum value, under which element is replaced by min. It must be a + scalar(tensor of empty shape). +max + Type T. + Maximum value, above which element is replaced by max. It must be a + scalar(tensor of empty shape). + +Returns +======= +output : Var + Type T. + Output tensor with clipped input elements + +Notes +===== +Signature: ``ai.onnx@13::Clip``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Clip( + _Clip.Attributes( + ), _Clip.Inputs( + input=unwrap_vars(input), min=unwrap_vars(min), max=unwrap_vars(max), ), ).get_output_vars( + input=get_value(input), min=get_value(min), max=get_value(max), ).output + + +def compress(input: Var, condition: Var, *, axis: Optional[int] = None, ) -> Var: + r""" +Selects slices from an input tensor along a given axis where condition +evaluates to True for each axis index. In case axis is not provided, +input is flattened before elements are selected. Compress behaves like +numpy.compress: +https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html + +Parameters +========== +input + Type T. + Tensor of rank r >= 1. +condition + Type T1. + Rank 1 tensor of booleans to indicate which slices or data elements to + be selected. Its length can be less than the input length along the axis + or the flattened input size if axis is not specified. In such cases data + slices or elements exceeding the condition length are discarded. +axis + Attribute. + (Optional) Axis along which to take slices. If not specified, input is + flattened before elements being selected. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + +Returns +======= +output : Var + Type T. + Tensor of rank r if axis is specified. Otherwise output is a Tensor of + rank 1. + +Notes +===== +Signature: ``ai.onnx@11::Compress``. + +Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return _Compress( + _Compress.Attributes( + axis=AttrInt64.maybe(axis, name="axis"), + ), _Compress.Inputs( + input=unwrap_vars(input), condition=unwrap_vars(condition), ), ).get_output_vars( + input=get_value(input), condition=get_value(condition), ).output + + +def concat(inputs: Sequence[Var], *, axis: int, ) -> Var: + r""" +Concatenate a list of tensors into a single tensor. All input tensors +must have the same shape, except for the dimension size of the axis to +concatenate on. + +Parameters +========== +inputs + Type T. + List of tensors for concatenation +axis + Attribute. + Which axis to concat on. A negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(inputs).. + +Returns +======= +concat_result : Var + Type T. + Concatenated tensor + +Notes +===== +Signature: ``ai.onnx@13::Concat``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Concat( + _Concat.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _Concat.Inputs( + inputs=unwrap_vars(inputs), ), ).get_output_vars( + inputs=get_value(inputs), ).concat_result + + +def concat_from_sequence(input_sequence: Var, *, axis: int, new_axis: int = 0, ) -> Var: + r""" +Concatenate a sequence of tensors into a single tensor. All input +tensors must have the same shape, except for the dimension size of the +axis to concatenate on. By default 'new_axis' is 0, the behavior is +similar to numpy.concatenate. When 'new_axis' is 1, the behavior is +similar to numpy.stack. + +Parameters +========== +input_sequence + Type S. + Sequence of tensors for concatenation +axis + Attribute. + Which axis to concat on. Accepted range in ``[-r, r - 1]``, where ``r`` + is the rank of input tensors. When ``new_axis`` is 1, accepted range is + ``[-r - 1, r]``. +new_axis + Attribute. + Insert and concatenate on a new axis or not, default 0 means do not + insert new axis. + +Returns +======= +concat_result : Var + Type T. + Concatenated tensor + +Notes +===== +Signature: ``ai.onnx@11::ConcatFromSequence``. + +Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ConcatFromSequence( + _ConcatFromSequence.Attributes( + axis=AttrInt64(axis, name="axis"), + new_axis=AttrInt64(new_axis, name="new_axis"), + ), _ConcatFromSequence.Inputs( + input_sequence=unwrap_vars(input_sequence), ), ).get_output_vars( + input_sequence=get_value(input_sequence), ).concat_result + + +def constant(*, value: Optional[np.ndarray] = None, value_float: Optional[float] = None, value_floats: Optional[Iterable[float]] = None, value_int: Optional[int] = None, value_ints: Optional[Iterable[int]] = None, value_string: Optional[str] = None, value_strings: Optional[Iterable[str]] = None, ) -> Var: + r""" +This operator produces a constant tensor. Exactly one of the provided +attributes, either value, sparse_value, or value\_\* must be specified. + +Parameters +========== +sparse_value + Attribute. + The value for the elements of the output tensor in sparse format. +value + Attribute. + The value for the elements of the output tensor. +value_float + Attribute. + The value for the sole element for the scalar, float32, output tensor. +value_floats + Attribute. + The values for the elements for the 1D, float32, output tensor. +value_int + Attribute. + The value for the sole element for the scalar, int64, output tensor. +value_ints + Attribute. + The values for the elements for the 1D, int64, output tensor. +value_string + Attribute. + The value for the sole element for the scalar, UTF-8 string, output + tensor. +value_strings + Attribute. + The values for the elements for the 1D, UTF-8 string, output tensor. + +Returns +======= +output : Var + Type T. + Output tensor containing the same value of the provided tensor. + +Notes +===== +Signature: ``ai.onnx@13::Constant``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), _Constant.Inputs( + ), ).get_output_vars( + ).output + + +def constant_of_shape(input: Var, *, value: Optional[np.ndarray] = None, ) -> Var: + r""" +Generate a tensor with given value and shape. + +Parameters +========== +input + Type T1. + 1D tensor. The shape of the expected output tensor. If empty tensor is + given, the output would be a scalar. All values must be >= 0. +value + Attribute. + (Optional) The value of the output elements.Should be a one-element + tensor. If not specified, it defaults to a tensor of value 0 and + datatype float32 + +Returns +======= +output : Var + Type T2. + Output tensor of shape specified by 'input'.If attribute 'value' is + specified, the value and datatype of the output tensor is taken from + 'value'.If attribute 'value' is not specified, the value in the output + defaults to 0, and the datatype defaults to float32. + +Notes +===== +Signature: ``ai.onnx@9::ConstantOfShape``. + +Type constraints: + - T1: `tensor(int64)` + - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), _ConstantOfShape.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def conv(X: Var, W: Var, B: Optional[Var] = None, *, auto_pad: str = "NOTSET", dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + r""" +The convolution operator consumes an input tensor and a filter, and +computes the output. + +Parameters +========== +X + Type T. + Input data tensor from previous layer; has size (N x C x H x W), where N + is the batch size, C is the number of channels, and H and W are the + height and width. Note that this is for the 2D image. Otherwise the size + is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in + effect, the operation expects input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. +W + Type T. + The weight tensor that will be used in the convolutions; has size (M x + C/group x kH x kW), where C is the number of channels, and kH and kW are + the height and width of the kernel, and M is the number of feature maps. + For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x + k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. + Optionally, if dimension denotation is in effect, the operation expects + the weight tensor to arrive with the dimension denotation of + [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL + ...]. Assuming zero based indices for the shape array, X.shape[1] == + (W.shape[1] \* group) == C and W.shape[0] mod G == 0. Or in other words + FILTER_IN_CHANNEL multiplied by the number of groups should be equal to + DATA_CHANNEL and the number of feature maps M should be a multiple of + the number of groups G. +B + Type T. + Optional 1D bias to be added to the convolution, has size of M. +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. +dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults is 1 along each spatial axis. +group + Attribute. + number of groups input channels and output channels are divided into. +kernel_shape + Attribute. + The shape of the convolution kernel. If not present, should be inferred + from input W. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults is 1 + along each spatial axis. + +Returns +======= +Y : Var + Type T. + Output data tensor that contains the result of the convolution. The + output dimensions are functions of the kernel size, stride size, and pad + lengths. + +Notes +===== +Signature: ``ai.onnx@11::Conv``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Conv( + _Conv.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _Conv.Inputs( + X=unwrap_vars(X), W=unwrap_vars(W), B=unwrap_vars(B), ), ).get_output_vars( + X=get_value(X), W=get_value(W), B=get_value(B), ).Y + + +def conv_integer(x: Var, w: Var, x_zero_point: Optional[Var] = None, w_zero_point: Optional[Var] = None, *, auto_pad: str = "NOTSET", dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + r""" +The integer convolution operator consumes an input tensor, its +zero-point, a filter, and its zero-point, and computes the output. The +production MUST never overflow. The accumulation may overflow if and +only if in 32 bits. + +Parameters +========== +x + Type T1. + Input data tensor from previous layer; has size (N x C x H x W), where N + is the batch size, C is the number of channels, and H and W are the + height and width. Note that this is for the 2D image. Otherwise the size + is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in + effect, the operation expects input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. +w + Type T2. + The weight tensor that will be used in the convolutions; has size (M x + C/group x kH x kW), where C is the number of channels, and kH and kW are + the height and width of the kernel, and M is the number of feature maps. + For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x + k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. + Optionally, if dimension denotation is in effect, the operation expects + the weight tensor to arrive with the dimension denotation of + [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL + ...]. X.shape[1] == (W.shape[1] \* group) == C (assuming zero based + indices for the shape array). Or in other words FILTER_IN_CHANNEL should + be equal to DATA_CHANNEL. +x_zero_point + Type T1. + Zero point tensor for input 'x'. It's optional and default value is 0. + It's a scalar, which means a per-tensor/layer quantization. +w_zero_point + Type T2. + Zero point tensor for input 'w'. It's optional and default value is 0. + It could be a scalar or a 1-D tensor, which means a per-tensor/layer or + per output channel quantization. If it's a 1-D tensor, its number of + elements should be equal to the number of output channels (M) +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. +dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults to 1 along each axis. +group + Attribute. + number of groups input channels and output channels are divided into. + default is 1. +kernel_shape + Attribute. + The shape of the convolution kernel. If not present, should be inferred + from input 'w'. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0.The value represent the number + of pixels added to the beginning and end part of the corresponding + axis.\ ``pads`` format should be as follow [x1_begin, x2_begin...x1_end, + x2_end,...], where xi_begin the number ofpixels added at the beginning + of axis ``i`` and xi_end, the number of pixels added at the end of axis + ``i``.This attribute cannot be used simultaneously with auto_pad + attribute. If not present, the padding defaultsto 0 along start and end + of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each axis. + +Returns +======= +y : Var + Type T3. + Output data tensor that contains the result of the convolution. The + output dimensions are functions of the kernel size, stride size, and pad + lengths. + +Notes +===== +Signature: ``ai.onnx@10::ConvInteger``. + +Type constraints: + - T1: `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(int32)` + """ + return _ConvInteger( + _ConvInteger.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _ConvInteger.Inputs( + x=unwrap_vars(x), w=unwrap_vars(w), x_zero_point=unwrap_vars(x_zero_point), w_zero_point=unwrap_vars(w_zero_point), ), ).get_output_vars( + x=get_value(x), w=get_value(w), x_zero_point=get_value(x_zero_point), w_zero_point=get_value(w_zero_point), ).y + + +def conv_transpose(X: Var, W: Var, B: Optional[Var] = None, *, auto_pad: str = "NOTSET", dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, output_padding: Optional[Iterable[int]] = None, output_shape: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + r""" +The convolution transpose operator consumes an input tensor and a +filter, and computes the output. + +If the pads parameter is provided the shape of the output is calculated +via the following equation: + +output_shape[i] = stride[i] \* (input_size[i] - 1) + output_padding[i] + +((kernel_shape[i] - 1) \* dilations[i] + 1) - pads[start_i] - +pads[end_i] + +output_shape can also be explicitly specified in which case pads values +are auto generated using these equations: + +total_padding[i] = stride[i] \* (input_size[i] - 1) + output_padding[i] ++ ((kernel_shape[i] - 1) \* dilations[i] + 1) - output_shape[i] If +(auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; +pads[end_i] = total_padding[i] - (total_padding[i]/2) Else: +pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = +(total_padding[i]/2). + +Parameters +========== +X + Type T. + Input data tensor from previous layer; has size (N x C x H x W), where N + is the batch size, C is the number of channels, and H and W are the + height and width. Note that this is for the 2D image. Otherwise the size + is (N x C x D1 x D2 ... x Dn) +W + Type T. + The weight tensor that will be used in the convolutions; has size (C x + M/group x kH x kW), where C is the number of channels, and kH and kW are + the height and width of the kernel, and M is the number of feature maps. + For more than 2 dimensions, the weight shape will be (C x M/group x k1 x + k2 x ... x kn), where (k1 x k2 x ... x kn) is the dimension of the + kernel. The number of channels in the output should be equal to + W.shape[1] \* group (assuming zero based indices of the shape array) +B + Type T. + Optional 1D bias to be added to the convolution, has size of M. +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = input_shape[i] * strides[i]`` for each axis ``i``. + The padding is split between the two sides equally or almost equally + (depending on whether it is even or odd). In case the padding is an odd + number, the extra padding is added at the end for SAME_UPPER and at the + beginning for SAME_LOWER. +dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults to 1 along each spatial axis. +group + Attribute. + number of groups input channels and output channels are divided into. +kernel_shape + Attribute. + The shape of the convolution kernel. If not present, should be inferred + from input W. +output_padding + Attribute. + Additional elements added to the side with higher coordinate indices in + the output. Each padding value in "output_padding" must be less than the + corresponding stride/dilation dimension. By default, this attribute is a + zero vector. Note that this attribute doesn't directly affect the + computed output values. It only controls the selection of the computed + values, so changing this attribute only adds or removes output elements. + If "output_shape" is explicitly provided, "output_padding" does not + contribute additional size to "output_shape" but participates in the + computation of the needed padding amount. This is also called adjs or + adjustment in some frameworks. +output_shape + Attribute. + The shape of the output can be explicitly set which will cause pads + values to be auto generated. If output_shape is specified pads values + are ignored. See doc for details for equations to generate pads. Note + that the output_shape attribute value should not include dimensions for + batch size and channels, which are automatically inferred. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + +Returns +======= +Y : Var + Type T. + Output data tensor that contains the result of the convolution. The + output dimensions are functions of the kernel size, stride size, pad + lengths and group count. The number of channels in the output should be + equal to W.shape[1] \* group (assuming zero based indices of the shape + array) + +Notes +===== +Signature: ``ai.onnx@11::ConvTranspose``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _ConvTranspose( + _ConvTranspose.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + output_padding=AttrInt64s.maybe(output_padding, name="output_padding"), + output_shape=AttrInt64s.maybe(output_shape, name="output_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _ConvTranspose.Inputs( + X=unwrap_vars(X), W=unwrap_vars(W), B=unwrap_vars(B), ), ).get_output_vars( + X=get_value(X), W=get_value(W), B=get_value(B), ).Y + + +def cos(input: Var, ) -> Var: + r""" +Calculates the cosine of the given input tensor, element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The cosine of the input tensor computed element-wise + +Notes +===== +Signature: ``ai.onnx@7::Cos``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Cos( + _Cos.Attributes( + ), _Cos.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def cosh(input: Var, ) -> Var: + r""" +Calculates the hyperbolic cosine of the given input tensor element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The hyperbolic cosine values of the input tensor computed element-wise + +Notes +===== +Signature: ``ai.onnx@9::Cosh``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Cosh( + _Cosh.Attributes( + ), _Cosh.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def cumsum(x: Var, axis: Var, *, exclusive: int = 0, reverse: int = 0, ) -> Var: + r""" +Performs cumulative sum of the input elements along the given axis. By +default, it will do the sum inclusively meaning the first element is +copied as is. Through an ``exclusive`` attribute, this behavior can +change to exclude the first element. It can also perform summation in +the opposite direction of the axis. For that, set ``reverse`` attribute +to 1. + +Example: + +:: + + input_x = [1, 2, 3] + axis=0 + output = [1, 3, 6] + exclusive=1 + output = [0, 1, 3] + exclusive=0 + reverse=1 + output = [6, 5, 3] + exclusive=1 + reverse=1 + output = [5, 3, 0] + +Parameters +========== +x + Type T. + An input tensor that is to be processed. +axis + Type T2. + A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value + means counting dimensions from the back. +exclusive + Attribute. + If set to 1 will return exclusive sum in which the top element is not + included. In other terms, if set to 1, the j-th output element would be + the sum of the first (j-1) elements. Otherwise, it would be the sum of + the first j elements. +reverse + Attribute. + If set to 1 will perform the sums in reverse direction. + +Returns +======= +y : Var + Type T. + Output tensor of the same type as 'x' with cumulative sums of the x's + elements + +Notes +===== +Signature: ``ai.onnx@14::CumSum``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return _CumSum( + _CumSum.Attributes( + exclusive=AttrInt64(exclusive, name="exclusive"), + reverse=AttrInt64(reverse, name="reverse"), + ), _CumSum.Inputs( + x=unwrap_vars(x), axis=unwrap_vars(axis), ), ).get_output_vars( + x=get_value(x), axis=get_value(axis), ).y + + +def dft(input: Var, dft_length: Optional[Var] = None, *, axis: int = 1, inverse: int = 0, onesided: int = 0, ) -> Var: + r""" +Computes the discrete Fourier transform of input. + +Parameters +========== +input + Type T1. + For real input, the following shape is expected: + [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][1]. For complex + input, the following shape is expected: + [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][2]. The first + dimension is the batch dimension. The following N dimensions correspond + to the signal's dimensions. The final dimension represents the real and + imaginary parts of the value in that order. +dft_length + Type T2. + The length of the signal as a scalar. If greater than the axis + dimension, the signal will be zero-padded up to dft_length. If less than + the axis dimension, only the first dft_length values will be used as the + signal. It's an optional value. +axis + Attribute. + The axis on which to perform the DFT. By default this value is set to 1, + which corresponds to the first dimension after the batch index. Negative + value means counting dimensions from the back. Accepted range is + :math:`[-r, -2] \cup [0, r-2]` where ``r = rank(input)``. The last + dimension is for representing complex numbers and thus is an invalid + axis. +inverse + Attribute. + Whether to perform the inverse discrete fourier transform. By default + this value is set to 0, which corresponds to false. +onesided + Attribute. + If onesided is 1, only values for w in [0, 1, 2, ..., floor(n_fft/2) + + 1] are returned because the real-to-complex Fourier transform satisfies + the conjugate symmetry, i.e., X[m, w] = X[m, n_fft-w]\*. Note if the + input or window tensors are complex, then onesided output is not + possible. Enabling onesided with real inputs performs a Real-valued fast + Fourier transform (RFFT). When invoked with real or complex valued + input, the default value is 0. Values can be 0 or 1. + +Returns +======= +output : Var + Type T1. + The Fourier Transform of the input vector. If onesided is 0, the + following shape is expected: + [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][2]. If axis=1 and + onesided is 1, the following shape is expected: + [batch_idx][floor(signal_dim1/2)+1][signal_dim2]...[signal_dimN][2]. If + axis=2 and onesided is 1, the following shape is expected: + [batch_idx][signal_dim1][floor(signal_dim2/2)+1]...[signal_dimN][2]. If + axis=N and onesided is 1, the following shape is expected: + [batch_idx][signal_dim1][signal_dim2]...[floor(signal_dimN/2)+1][2]. The + signal_dim at the specified axis is equal to the dft_length. + +Notes +===== +Signature: ``ai.onnx@17::DFT``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return _DFT( + _DFT.Attributes( + axis=AttrInt64(axis, name="axis"), + inverse=AttrInt64(inverse, name="inverse"), + onesided=AttrInt64(onesided, name="onesided"), + ), _DFT.Inputs( + input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), ), ).get_output_vars( + input=get_value(input), dft_length=get_value(dft_length), ).output + + +def depth_to_space(input: Var, *, blocksize: int, mode: str = "DCR", ) -> Var: + r""" +DepthToSpace rearranges (permutes) data from depth into blocks of +spatial data. This is the reverse transformation of SpaceToDepth. More +specifically, this op outputs a copy of the input tensor where values +from the depth dimension are moved in spatial blocks to the height and +width dimensions. By default, ``mode`` = ``DCR``. In the DCR mode, +elements along the depth dimension from the input tensor are rearranged +in the following order: depth, column, and then row. The output y is +computed from the input x as below: + +:: + + b, c, h, w = x.shape + tmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w]) + tmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2]) + y = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize]) + +In the CRD mode, elements along the depth dimension from the input +tensor are rearranged in the following order: column, row, and the +depth. The output y is computed from the input x as below: + +:: + + b, c, h, w = x.shape + tmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w]) + tmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3]) + y = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize]) + +Parameters +========== +input + Type T. + Input tensor of [N,C,H,W], where N is the batch axis, C is the channel + or depth, H is the height and W is the width. +blocksize + Attribute. + Blocks of [blocksize, blocksize] are moved. +mode + Attribute. + DCR (default) for depth-column-row order re-arrangement. Use CRD for + column-row-depth order. + +Returns +======= +output : Var + Type T. + Output tensor of [N, C/(blocksize \* blocksize), H \* blocksize, W \* + blocksize]. + +Notes +===== +Signature: ``ai.onnx@13::DepthToSpace``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _DepthToSpace( + _DepthToSpace.Attributes( + blocksize=AttrInt64(blocksize, name="blocksize"), + mode=AttrString(mode, name="mode"), + ), _DepthToSpace.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def dequantize_linear(x: Var, x_scale: Var, x_zero_point: Optional[Var] = None, *, axis: int = 1, ) -> Var: + r""" +The linear dequantization operator. It consumes a quantized tensor, a +scale, and a zero point to compute the full precision tensor. The +dequantization formula is ``y = (x - x_zero_point) * x_scale``. +``x_scale`` and ``x_zero_point`` must have same shape, and can be either +a scalar for per-tensor / per layer quantization, or a 1-D tensor for +per-axis quantization. ``x_zero_point`` and ``x`` must have same type. +``x`` and ``y`` must have same shape. In the case of dequantizing int32, +there's no zero point (zero point is supposed to be 0). + +Parameters +========== +x + Type T. + N-D quantized input tensor to be de-quantized. +x_scale + Type tensor(float). + Scale for input 'x'. It can be a scalar, which means a per-tensor/layer + dequantization, or a 1-D tensor for per-axis dequantization. +x_zero_point + Type T. + Zero point for input 'x'. Shape must match x_scale. It's optional. Zero + point is 0 when it's not specified. +axis + Attribute. + (Optional) The axis of the dequantizing dimension of the input tensor. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + +Returns +======= +y : Var + Type tensor(float). + N-D full precision output tensor. It has same shape as input 'x'. + +Notes +===== +Signature: ``ai.onnx@13::DequantizeLinear``. + +Type constraints: + - T: `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` + """ + return _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _DequantizeLinear.Inputs( + x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), ).get_output_vars( + x=get_value(x), x_scale=get_value(x_scale), x_zero_point=get_value(x_zero_point), ).y + + +def det(X: Var, ) -> Var: + r""" +Det calculates determinant of a square matrix or batches of square +matrices. Det takes one input tensor of shape ``[*, M, M]``, where ``*`` +is zero or more batch dimensions, and the inner-most 2 dimensions form +square matrices. The output is a tensor of shape ``[*]``, containing the +determinants of all input submatrices. e.g., When the input is 2-D, the +output is a scalar(shape is empty: ``[]``). + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@11::Det``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Det( + _Det.Attributes( + ), _Det.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def div(A: Var, B: Var, ) -> Var: + r""" +Performs element-wise binary division (with Numpy-style broadcasting +support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +(Opset 14 change): Extend supported types to include uint8, int8, +uint16, and int16. + +Parameters +========== +A + Type T. + First operand. +B + Type T. + Second operand. + +Returns +======= +C : Var + Type T. + Result, has same element type as two inputs + +Notes +===== +Signature: ``ai.onnx@14::Div``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Div( + _Div.Attributes( + ), _Div.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def dropout(data: Var, ratio: Optional[Var] = None, training_mode: Optional[Var] = None, *, seed: Optional[int] = None, ) -> tuple[Var, Var]: + r""" +Dropout takes an input floating-point tensor, an optional input ratio +(floating-point scalar) and an optional input training_mode (boolean +scalar). It produces two tensor outputs, output (floating-point tensor) +and mask (optional ``Tensor``). If ``training_mode`` is true then +the output Y will be a random dropout; Note that this Dropout scales the +masked input data by the following equation, so to convert the trained +model into inference mode, the user can simply not pass +``training_mode`` input or set it to false. + +:: + + output = scale * data * mask, + +where + +:: + + scale = 1. / (1. - ratio). + +This operator has **optional** inputs/outputs. See `the +doc `__ for more +details about the representation of optional arguments. An empty string +may be used in the place of an actual argument's name to indicate a +missing argument. Trailing optional arguments (those not followed by an +argument that is present) may also be simply omitted. + +Parameters +========== +data + Type T. + The input data as Tensor. +ratio + Type T1. + The ratio of random dropout, with value in [0, 1). If this input was not + set, or if it was set to 0, the output would be a simple copy of the + input. If it's non-zero, output will be a random dropout of the scaled + input, which is typically the case during training. It is an optional + value, if not specified it will default to 0.5. +training_mode + Type T2. + If set to true then it indicates dropout is being used for training. It + is an optional value hence unless specified explicitly, it is false. If + it is false, ratio is ignored and the operation mimics inference mode + where nothing will be dropped from the input data and if mask is + requested as output it will contain all ones. +seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + +Returns +======= +output : Var + Type T. + The output. +mask : Var + Type T2. + The output mask. + +Notes +===== +Signature: ``ai.onnx@13::Dropout``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(bool)` + """ + return _Dropout( + _Dropout.Attributes( + seed=AttrInt64.maybe(seed, name="seed"), + ), _Dropout.Inputs( + data=unwrap_vars(data), ratio=unwrap_vars(ratio), training_mode=unwrap_vars(training_mode), ), ).get_output_vars( + data=get_value(data), ratio=get_value(ratio), training_mode=get_value(training_mode), )._unpack_to_any() + + +def dynamic_quantize_linear(x: Var, ) -> tuple[Var, Var, Var]: + r""" +A Function to fuse calculation for Scale, Zero Point and FP32->8Bit +conversion of FP32 Input data. Outputs Scale, ZeroPoint and Quantized +Input for a given FP32 Input. Scale is calculated as: + +:: + + y_scale = (maximum(0, max(x)) - minimum(0, min(x))) / (qmax - qmin) + +- where qmax and qmin are max and min values for quantization range + i.e. [0, 255] in case of uint8 +- data range is adjusted to include 0. + +Zero point is calculated as: + +:: + + intermediate_zero_point = qmin - min(x)/y_scale + y_zero_point = cast(round(saturate(itermediate_zero_point))) + +- where qmax and qmin are max and min values for quantization range + .i.e [0, 255] in case of uint8 +- for saturation, it saturates to [0, 255] if it's uint8, or [-127, + 127] if it's int8. Right now only uint8 is supported. +- rounding to nearest ties to even. + +Data quantization formula is: + +:: + + y = saturate (round (x / y_scale) + y_zero_point) + +- for saturation, it saturates to [0, 255] if it's uint8, or [-127, + 127] if it's int8. Right now only uint8 is supported. +- rounding to nearest ties to even. + +Parameters +========== +x + Type T1. + Input tensor + +Returns +======= +y : Var + Type T2. + Quantized output tensor +y_scale : Var + Type tensor(float). + Output scale. It's a scalar, which means a per-tensor/layer + quantization. +y_zero_point : Var + Type T2. + Output zero point. It's a scalar, which means a per-tensor/layer + quantization. + +Notes +===== +Signature: ``ai.onnx@11::DynamicQuantizeLinear``. + +Type constraints: + - T1: `tensor(float)` + - T2: `tensor(uint8)` + """ + return _DynamicQuantizeLinear( + _DynamicQuantizeLinear.Attributes( + ), _DynamicQuantizeLinear.Inputs( + x=unwrap_vars(x), ), ).get_output_vars( + x=get_value(x), )._unpack_to_any() + + +def einsum(Inputs: Sequence[Var], *, equation: str, ) -> Var: + r""" +An einsum of the form ``term1, term2 -> output-term`` produces an output +tensor using the following equation + +:: + + output[output-term] = reduce-sum( input1[term1] * input2[term2] ) + +where the reduce-sum performs a summation over all the indices occurring +in the input terms (term1, term2) that do not occur in the output-term. + +The Einsum operator evaluates algebraic tensor operations on a sequence +of tensors, using the Einstein summation convention. The equation string +contains a comma-separated sequence of lower case letters. Each term +corresponds to an operand tensor, and the characters within the terms +correspond to operands dimensions. + +This sequence may be followed by "->" to separate the left and right +hand side of the equation. If the equation contains "->" followed by the +right-hand side, the explicit (not classical) form of the Einstein +summation is performed, and the right-hand side indices indicate output +tensor dimensions. In other cases, output indices are (implicitly) set +to the alphabetically sorted sequence of indices appearing exactly once +in the equation. + +When a dimension character is repeated in the left-hand side, it +represents summation along the dimension. + +The equation may contain ellipsis ("...") to enable broadcasting. +Ellipsis must indicate a fixed number of dimensions. Specifically, every +occurrence of ellipsis in the equation must represent the same number of +dimensions. The right-hand side may contain exactly one ellipsis. In +implicit mode, the ellipsis dimensions are set to the beginning of the +output. The equation string may contain space (U+0020) character. + +Parameters +========== +Inputs + Type T. + Operands +equation + Attribute. + Einsum expression string. + +Returns +======= +Output : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@12::Einsum``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Einsum( + _Einsum.Attributes( + equation=AttrString(equation, name="equation"), + ), _Einsum.Inputs( + Inputs=unwrap_vars(Inputs), ), ).get_output_vars( + Inputs=get_value(Inputs), ).Output + + +def elu(X: Var, *, alpha: float = 1.0, ) -> Var: + r""" +Elu takes one input data (Tensor) and produces one output data +(Tensor) where the function +``f(x) = alpha * (exp(x) - 1.) for x < 0``, ``f(x) = x for x >= 0``., is +applied to the tensor elementwise. + +Parameters +========== +X + Type T. + 1D input tensor +alpha + Attribute. + Coefficient of ELU. + +Returns +======= +Y : Var + Type T. + 1D output tensor + +Notes +===== +Signature: ``ai.onnx@6::Elu``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Elu( + _Elu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), _Elu.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def equal(A: Var, B: Var, ) -> Var: + r""" +Returns the tensor resulted from performing the ``equal`` logical +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. + +Returns +======= +C : Var + Type T1. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@13::Equal``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return _Equal( + _Equal.Attributes( + ), _Equal.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def erf(input: Var, ) -> Var: + r""" +Computes the error function of the given input tensor element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The error function of the input tensor computed element-wise. It has the + same shape and type of the input. + +Notes +===== +Signature: ``ai.onnx@13::Erf``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Erf( + _Erf.Attributes( + ), _Erf.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def exp(input: Var, ) -> Var: + r""" +Calculates the exponential of the given input tensor, element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The exponential of the input tensor computed element-wise + +Notes +===== +Signature: ``ai.onnx@13::Exp``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Exp( + _Exp.Attributes( + ), _Exp.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def expand(input: Var, shape: Var, ) -> Var: + r""" +Broadcast the input tensor following the given shape and the broadcast +rule. The broadcast rule is similar to numpy.array(input) \* +numpy.ones(shape): Dimensions are right alignment; Two corresponding +dimensions must have the same value, or one of them is equal to 1. Also, +this operator is similar to numpy.broadcast_to(input, shape), but the +major difference is numpy.broadcast_to() does not allow shape to be +smaller than input.size(). It is possible that the output.shape is not +equal to shape, when some dimensions in shape is equal to 1, or the +shape.ndim < input.shape.ndim. + +Parameters +========== +input + Type T. + Input tensor +shape + Type tensor(int64). + A 1-D tensor indicates the shape you want to expand to, following the + broadcast rule + +Returns +======= +output : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@13::Expand``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Expand( + _Expand.Attributes( + ), _Expand.Inputs( + input=unwrap_vars(input), shape=unwrap_vars(shape), ), ).get_output_vars( + input=get_value(input), shape=get_value(shape), ).output + + +def eye_like(input: Var, *, dtype: Optional[npt.DTypeLike] = None, k: int = 0, ) -> Var: + r""" +Generate a 2D tensor (matrix) with ones on the diagonal and zeros +everywhere else. Only 2D tensors are supported, i.e. input T1 must be of +rank 2. The shape of the output tensor is the same as the input tensor. +The data type can be specified by the 'dtype' argument. If 'dtype' is +not specified, then the type of input tensor is used. By default, the +main diagonal is populated with ones, but attribute 'k' can be used to +populate upper or lower diagonals. The 'dtype' argument must be one of +the data types specified in the 'DataType' enum field in the TensorProto +message and be valid as an output type. + +Parameters +========== +input + Type T1. + 2D input tensor to copy shape, and optionally, type information from. +dtype + Attribute. + (Optional) The data type for the elements of the output tensor. If not + specified,the data type of the input tensor T1 is used. If input tensor + T1 is also notspecified, then type defaults to 'float'. +k + Attribute. + (Optional) Index of the diagonal to be populated with ones. Default is + 0. If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the + main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a + lower diagonal. + +Returns +======= +output : Var + Type T2. + Output tensor, same shape as input tensor T1. + +Notes +===== +Signature: ``ai.onnx@9::EyeLike``. + +Type constraints: + - T1: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _EyeLike( + _EyeLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + k=AttrInt64(k, name="k"), + ), _EyeLike.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def flatten(input: Var, *, axis: int = 1, ) -> Var: + r""" +Flattens the input tensor into a 2D matrix. If input tensor has shape +(d_0, d_1, ... d_n) then the output will have shape (d_0 X d_1 ... +d\_(axis-1), d_axis X d\_(axis+1) ... X dn). + +Parameters +========== +input + Type T. + A tensor of rank >= axis. +axis + Attribute. + Indicate up to which input dimensions (exclusive) should be flattened to + the outer dimension of the output. The value for axis must be in the + range [-r, r], where r is the rank of the input tensor. Negative value + means counting dimensions from the back. When axis = 0, the shape of the + output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input + tensor is (d_0, d_1, ... d_n). + +Returns +======= +output : Var + Type T. + A 2D tensor with the contents of the input tensor, with input dimensions + up to axis flattened to the outer dimension of the output and remaining + input dimensions flattened into the inner dimension of the output. + +Notes +===== +Signature: ``ai.onnx@13::Flatten``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Flatten( + _Flatten.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _Flatten.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def floor(X: Var, ) -> Var: + r""" +Floor takes one input data (Tensor) and produces one output data +(Tensor) where the floor is, y = floor(x), is applied to the tensor +elementwise. If x is integral, +0, -0, NaN, or infinite, x itself is +returned. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@13::Floor``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Floor( + _Floor.Attributes( + ), _Floor.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def gru(X: Var, W: Var, R: Var, B: Optional[Var] = None, sequence_lens: Optional[Var] = None, initial_h: Optional[Var] = None, *, activation_alpha: Optional[Iterable[float]] = None, activation_beta: Optional[Iterable[float]] = None, activations: Optional[Iterable[str]] = None, clip: Optional[float] = None, direction: str = "forward", hidden_size: Optional[int] = None, layout: int = 0, linear_before_reset: int = 0, ) -> tuple[Var, Var]: + r""" +Computes an one-layer GRU. This operator is usually supported via some +custom implementation such as CuDNN. + +Notations: + +- ``X`` - input tensor +- ``z`` - update gate +- ``r`` - reset gate +- ``h`` - hidden gate +- ``t`` - time step (t-1 means previous time step) +- ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden + gates +- ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden + gates +- ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates +- ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates +- ``WB[zrh]`` - W parameter weight matrix for backward update, reset, + and hidden gates +- ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, + and hidden gates +- ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden + gates +- ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden + gates +- ``H`` - Hidden state +- ``num_directions`` - 2 if direction == bidirectional else 1 + +Activation functions: + +- Relu(x) - max(0, x) +- Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) +- Sigmoid(x) - 1/(1 + e^{-x}) + +NOTE: Below are optional + +- Affine(x) - alpha \* x + beta +- LeakyRelu(x) - x if x >= 0 else alpha \* x +- ThresholdedRelu(x) - x if x >= alpha else 0 +- ScaledTanh(x) - alpha \* Tanh(beta \* x) +- HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) +- Elu(x) - x if x >= 0 else alpha \* (e^x - 1) +- Softsign(x) - x/(1 + \|x\|) +- Softplus(x) - log(1 + e^x) + +Equations (Default: f=Sigmoid, g=Tanh): + +- zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) +- rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) +- ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when + linear_before_reset = 0 +- ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when + linear_before_reset != 0 +- Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** + inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. + +Parameters +========== +X + Type T. + The input sequences packed (and potentially padded) into one 3-D tensor + with the shape of ``[seq_length, batch_size, input_size]``. +W + Type T. + The weight tensor for the gates. Concatenation of ``W[zrh]`` and + ``WB[zrh]`` (if bidirectional) along dimension 0. This tensor has shape + ``[num_directions, 3*hidden_size, input_size]``. +R + Type T. + The recurrence weight tensor. Concatenation of ``R[zrh]`` and + ``RB[zrh]`` (if bidirectional) along dimension 0. This tensor has shape + ``[num_directions, 3*hidden_size, hidden_size]``. +B + Type T. + The bias tensor for the gates. Concatenation of ``[Wb[zrh], Rb[zrh]]`` + and ``[WBb[zrh], RBb[zrh]]`` (if bidirectional) along dimension 0. This + tensor has shape ``[num_directions, 6*hidden_size]``. Optional: If not + specified - assumed to be 0 +sequence_lens + Type T1. + Optional tensor specifying lengths of the sequences in a batch. If not + specified - assumed all sequences in the batch to have length + ``seq_length``. It has shape ``[batch_size]``. +initial_h + Type T. + Optional initial value of the hidden. If not specified - assumed to be + 0. It has shape ``[num_directions, batch_size, hidden_size]``. +activation_alpha + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX + operators.For example with LeakyRelu, the default alpha is 0.01. +activation_beta + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX operators. +activations + Attribute. + A list of 2 (or 4 if bidirectional) activation functions for update, + reset, and hidden gates. The activation functions must be one of the + activation functions specified above. Optional: See the equations for + default if not specified. +clip + Attribute. + Cell clip threshold. Clipping bounds the elements of a tensor in the + range of [-threshold, +threshold] and is applied to the input of + activations. No clip if not specified. +direction + Attribute. + Specify if the RNN is forward, reverse, or bidirectional. Must be one of + forward (default), reverse, or bidirectional. +hidden_size + Attribute. + Number of neurons in the hidden layer +layout + Attribute. + The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the + following shapes are expected: X.shape = [seq_length, batch_size, + input_size], Y.shape = [seq_length, num_directions, batch_size, + hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, + hidden_size]. If 1, the following shapes are expected: X.shape = + [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, + num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, + num_directions, hidden_size]. +linear_before_reset + Attribute. + When computing the output of the hidden gate, apply the linear + transformation before multiplying by the output of the reset gate. + +Returns +======= +Y : Var + Type T. + A tensor that concats all the intermediate output values of the hidden. + It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. +Y_h : Var + Type T. + The last output value of the hidden. It has shape + ``[num_directions, batch_size, hidden_size]``. + +Notes +===== +Signature: ``ai.onnx@14::GRU``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(int32)` + """ + return _GRU( + _GRU.Attributes( + activation_alpha=AttrFloat32s.maybe(activation_alpha, name="activation_alpha"), + activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), + activations=AttrStrings.maybe(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + layout=AttrInt64(layout, name="layout"), + linear_before_reset=AttrInt64(linear_before_reset, name="linear_before_reset"), + ), _GRU.Inputs( + X=unwrap_vars(X), W=unwrap_vars(W), R=unwrap_vars(R), B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), ), ).get_output_vars( + X=get_value(X), W=get_value(W), R=get_value(R), B=get_value(B), sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), )._unpack_to_any() + + +def gather(data: Var, indices: Var, *, axis: int = 0, ) -> Var: + r""" +Given ``data`` tensor of rank r >= 1, and ``indices`` tensor of rank q, +gather entries of the axis dimension of ``data`` (by default outer-most +one as axis=0) indexed by ``indices``, and concatenates them in an +output tensor of rank q + (r - 1). + +If ``axis = 0``, let ``k = indices[i_{0}, ..., i_{q-1}]`` then +``output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]``: + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + indices = [ + [0, 1], + [1, 2], + ] + output = [ + [ + [1.0, 1.2], + [2.3, 3.4], + ], + [ + [2.3, 3.4], + [4.5, 5.7], + ], + ] + +If ``axis = 1``, let ``k = indices[i_{0}, ..., i_{q-1}]`` then +``output[j_{0}, i_{0}, ..., i_{q-1}, j_{1}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]``: + +:: + + data = [ + [1.0, 1.2, 1.9], + [2.3, 3.4, 3.9], + [4.5, 5.7, 5.9], + ] + indices = [ + [0, 2], + ] + axis = 1, + output = [ + [[1.0, 1.9]], + [[2.3, 3.9]], + [[4.5, 5.9]], + ] + +Parameters +========== +data + Type T. + Tensor of rank r >= 1. +indices + Type Tind. + Tensor of int32/int64 indices, of any rank q. All index values are + expected to be within bounds [-s, s-1] along axis of size s. It is an + error if any of the index values are out of bounds. +axis + Attribute. + Which axis to gather on. Negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(data). + +Returns +======= +output : Var + Type T. + Tensor of rank q + (r - 1). + +Notes +===== +Signature: ``ai.onnx@13::Gather``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return _Gather( + _Gather.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _Gather.Inputs( + data=unwrap_vars(data), indices=unwrap_vars(indices), ), ).get_output_vars( + data=get_value(data), indices=get_value(indices), ).output + + +def gather_elements(data: Var, indices: Var, *, axis: int = 0, ) -> Var: + r""" +GatherElements takes two inputs ``data`` and ``indices`` of the same +rank r >= 1 and an optional attribute ``axis`` that identifies an axis +of ``data`` (by default, the outer-most axis, that is axis 0). It is an +indexing operation that produces its output by indexing into the input +data tensor at index positions determined by elements of the ``indices`` +tensor. Its output shape is the same as the shape of ``indices`` and +consists of one value (gathered from the ``data``) for each element in +``indices``. + +For instance, in the 3-D case (r = 3), the output produced is determined +by the following equations: + +:: + + out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0, + out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1, + out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2, + +This operator is also the inverse of ScatterElements. It is similar to +Torch's gather operation. + +Example 1: + +:: + + data = [ + [1, 2], + [3, 4], + ] + indices = [ + [0, 0], + [1, 0], + ] + axis = 1 + output = [ + [1, 1], + [4, 3], + ] + +Example 2: + +:: + + data = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + ] + indices = [ + [1, 2, 0], + [2, 0, 0], + ] + axis = 0 + output = [ + [4, 8, 3], + [7, 2, 3], + ] + +Parameters +========== +data + Type T. + Tensor of rank r >= 1. +indices + Type Tind. + Tensor of int32/int64 indices, with the same rank r as the input. All + index values are expected to be within bounds [-s, s-1] along axis of + size s. It is an error if any of the index values are out of bounds. +axis + Attribute. + Which axis to gather on. Negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(data). + +Returns +======= +output : Var + Type T. + Tensor of the same shape as indices. + +Notes +===== +Signature: ``ai.onnx@13::GatherElements``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return _GatherElements( + _GatherElements.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _GatherElements.Inputs( + data=unwrap_vars(data), indices=unwrap_vars(indices), ), ).get_output_vars( + data=get_value(data), indices=get_value(indices), ).output + + +def gather_nd(data: Var, indices: Var, *, batch_dims: int = 0, ) -> Var: + r""" +Given ``data`` tensor of rank ``r`` >= 1, ``indices`` tensor of rank +``q`` >= 1, and ``batch_dims`` integer ``b``, this operator gathers +slices of ``data`` into an output tensor of rank +``q + r - indices_shape[-1] - 1 - b``. + +``indices`` is an q-dimensional integer tensor, best thought of as a +``(q-1)``-dimensional tensor of index-tuples into ``data``, where each +element defines a slice of ``data`` + +``batch_dims`` (denoted as ``b``) is an integer indicating the number of +batch dimensions, i.e the leading ``b`` number of dimensions of ``data`` +tensor and ``indices`` are representing the batches, and the gather +starts from the ``b+1`` dimension. + +Some salient points about the inputs' rank and shape: + +1) r >= 1 and q >= 1 are to be honored. There is no dependency condition + to be met between ranks ``r`` and ``q`` + +2) The first ``b`` dimensions of the shape of ``indices`` tensor and + ``data`` tensor must be equal. + +3) b < min(q, r) is to be honored. + +4) The ``indices_shape[-1]`` should have a value between 1 (inclusive) + and rank ``r-b`` (inclusive) + +5) All values in ``indices`` are expected to be within bounds [-s, s-1] + along axis of size ``s`` (i.e.) + ``-data_shape[i] <= indices[...,i] <= data_shape[i] - 1``. It is an + error if any of the index values are out of bounds. + +The output is computed as follows: + +The output tensor is obtained by mapping each index-tuple in the +``indices`` tensor to the corresponding slice of the input ``data``. + +1) If ``indices_shape[-1] > r-b`` => error condition + +2) If ``indices_shape[-1] == r-b``, since the rank of ``indices`` is + ``q``, ``indices`` can be thought of as ``N`` ``(q-b-1)``-dimensional + tensors containing 1-D tensors of dimension ``r-b``, where ``N`` is + an integer equals to the product of 1 and all the elements in the + batch dimensions of the indices_shape. Let us think of each such + ``r-b`` ranked tensor as ``indices_slice``. Each *scalar value* + corresponding to ``data[0:b-1,indices_slice]`` is filled into the + corresponding location of the ``(q-b-1)``-dimensional tensor to form + the ``output`` tensor (Example 1 below) + +3) If ``indices_shape[-1] < r-b``, since the rank of ``indices`` is + ``q``, ``indices`` can be thought of as ``N`` ``(q-b-1)``-dimensional + tensor containing 1-D tensors of dimension ``< r-b``. Let us think of + each such tensors as ``indices_slice``. Each *tensor slice* + corresponding to ``data[0:b-1, indices_slice , :]`` is filled into + the corresponding location of the ``(q-b-1)``-dimensional tensor to + form the ``output`` tensor (Examples 2, 3, 4 and 5 below) + +This operator is the inverse of ``ScatterND``. + +**Example 1** + +:: + + batch_dims = 0 + data = [[0,1],[2,3]] # data_shape = [2, 2] + indices = [[0,0],[1,1]] # indices_shape = [2, 2] + output = [0,3] # output_shape = [2] + +**Example 2** + +:: + + batch_dims = 0 + data = [[0,1],[2,3]] # data_shape = [2, 2] + indices = [[1],[0]] # indices_shape = [2, 1] + output = [[2,3],[0,1]] # output_shape = [2, 2] + +**Example 3** + +:: + + batch_dims = 0 + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + indices = [[0,1],[1,0]] # indices_shape = [2, 2] + output = [[2,3],[4,5]] # output_shape = [2, 2] + +**Example 4** + +:: + + batch_dims = 0 + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2] + output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2] + +**Example 5** + +:: + + batch_dims = 1 + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + indices = [[1],[0]] # indices_shape = [2, 1] + output = [[2,3],[4,5]] # output_shape = [2, 2] + +Parameters +========== +data + Type T. + Tensor of rank r >= 1. +indices + Type tensor(int64). + Tensor of rank q >= 1. All index values are expected to be within bounds + [-s, s-1] along axis of size s. It is an error if any of the index + values are out of bounds. +batch_dims + Attribute. + The number of batch dimensions. The gather of indexing starts from + dimension of data[batch_dims:] + +Returns +======= +output : Var + Type T. + Tensor of rank q + r - indices_shape[-1] - 1. + +Notes +===== +Signature: ``ai.onnx@13::GatherND``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _GatherND( + _GatherND.Attributes( + batch_dims=AttrInt64(batch_dims, name="batch_dims"), + ), _GatherND.Inputs( + data=unwrap_vars(data), indices=unwrap_vars(indices), ), ).get_output_vars( + data=get_value(data), indices=get_value(indices), ).output + + +def gemm(A: Var, B: Var, C: Optional[Var] = None, *, alpha: float = 1.0, beta: float = 1.0, transA: int = 0, transB: int = 0, ) -> Var: + r""" +General Matrix multiplication: +https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + +- A' = transpose(A) if transA else A +- B' = transpose(B) if transB else B + +Compute Y = alpha \* A' \* B' + beta \* C, where input tensor A has +shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input +tensor C is broadcastable to shape (M, N), and output tensor Y has shape +(M, N). A will be transposed before doing the computation if attribute +transA is non-zero, same for B and transB. This operator supports +**unidirectional broadcasting** (tensor C should be unidirectional +broadcastable to tensor A \* B); for more details please check `the +doc `__. +This operator has **optional** inputs/outputs. See `the +doc `__ for more +details about the representation of optional arguments. An empty string +may be used in the place of an actual argument's name to indicate a +missing argument. Trailing optional arguments (those not followed by an +argument that is present) may also be simply omitted. + +Parameters +========== +A + Type T. + Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, + M) if transA is non-zero. +B + Type T. + Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, + K) if transB is non-zero. +C + Type T. + Optional input tensor C. If not specified, the computation is done as if + C is a scalar 0. The shape of C should be unidirectional broadcastable + to (M, N). +alpha + Attribute. + Scalar multiplier for the product of input tensors A \* B. +beta + Attribute. + Scalar multiplier for input tensor C. +transA + Attribute. + Whether A should be transposed +transB + Attribute. + Whether B should be transposed + +Returns +======= +Y : Var + Type T. + Output tensor of shape (M, N). + +Notes +===== +Signature: ``ai.onnx@13::Gemm``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _Gemm( + _Gemm.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + transA=AttrInt64(transA, name="transA"), + transB=AttrInt64(transB, name="transB"), + ), _Gemm.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), C=unwrap_vars(C), ), ).get_output_vars( + A=get_value(A), B=get_value(B), C=get_value(C), ).Y + + +def global_average_pool(X: Var, ) -> Var: + r""" +GlobalAveragePool consumes an input tensor X and applies average pooling +across the values in the same channel. This is equivalent to AveragePool +with kernel size equal to the spatial dimension of input tensor. + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. + +Returns +======= +Y : Var + Type T. + Output data tensor from pooling across the input tensor. The output + tensor has the same rank as the input. The first two dimensions of + output shape are the same as the input (N x C), while the other + dimensions are all 1. + +Notes +===== +Signature: ``ai.onnx@1::GlobalAveragePool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _GlobalAveragePool( + _GlobalAveragePool.Attributes( + ), _GlobalAveragePool.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def global_lp_pool(X: Var, *, p: int = 2, ) -> Var: + r""" +GlobalLpPool consumes an input tensor X and applies lp pool pooling +across the values in the same channel. This is equivalent to LpPool with +kernel size equal to the spatial dimension of input tensor. + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. +p + Attribute. + p value of the Lp norm used to pool over the input data. + +Returns +======= +Y : Var + Type T. + Output data tensor from pooling across the input tensor. The output + tensor has the same rank as the input. The first two dimensions of + output shape are the same as the input (N x C), while the other + dimensions are all 1. + +Notes +===== +Signature: ``ai.onnx@2::GlobalLpPool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _GlobalLpPool( + _GlobalLpPool.Attributes( + p=AttrInt64(p, name="p"), + ), _GlobalLpPool.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def global_max_pool(X: Var, ) -> Var: + r""" +GlobalMaxPool consumes an input tensor X and applies max pooling across +the values in the same channel. This is equivalent to MaxPool with +kernel size equal to the spatial dimension of input tensor. + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. + +Returns +======= +Y : Var + Type T. + Output data tensor from pooling across the input tensor. The output + tensor has the same rank as the input. The first two dimensions of + output shape are the same as the input (N x C), while the other + dimensions are all 1. + +Notes +===== +Signature: ``ai.onnx@1::GlobalMaxPool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _GlobalMaxPool( + _GlobalMaxPool.Attributes( + ), _GlobalMaxPool.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def greater(A: Var, B: Var, ) -> Var: + r""" +Returns the tensor resulted from performing the ``greater`` logical +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. + +Returns +======= +C : Var + Type T1. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@13::Greater``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return _Greater( + _Greater.Attributes( + ), _Greater.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def greater_or_equal(A: Var, B: Var, ) -> Var: + r""" +Returns the tensor resulted from performing the ``greater_equal`` +logical operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. + +Returns +======= +C : Var + Type T1. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@16::GreaterOrEqual``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return _GreaterOrEqual( + _GreaterOrEqual.Attributes( + ), _GreaterOrEqual.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def grid_sample(X: Var, grid: Var, *, align_corners: int = 0, mode: str = "bilinear", padding_mode: str = "zeros", ) -> Var: + r""" +Given an input ``X`` and a flow-field ``grid``, computes the output +``Y`` using ``X`` values and pixel locations from ``grid``. Currently, +only spatial (4-D) inputs are supported. For input ``X`` with shape (N, +C, H, W) and ``grid`` with shape (N, H_out, W_out, 2), the output ``Y`` +will have shape (N, C, H_out, W_out). + +The tensor ``X`` contains values at centers of square pixels in a H by W +2-dimensional image. The tensor ``grid`` describes normalized positions +where the output ``Y`` is to be computed using a specified interpolation +method (the mode) and a padding mode (for grid positions falling outside +the 2-dimensional image). + +Elements in ``grid[N, H_out, W_out]`` are size-2 vectors specifying +positions in the 2-dimensional space of ``X``. They are used to +interpolate output values of ``Y[N, C, H_out, W_out]``. + +The GridSample operator is often used in doing grid generator and +sampler in the `Spatial Transformer +Networks `__. See also in +`torch.nn.functional.grid_sample `__. + +Parameters +========== +X + Type T1. + 4-D tensor of shape (N, C, H, W), where N is the batch size, C is the + numbers of channels, H and W are the height and width of the input data. +grid + Type T2. + Input offset, 4-D tensor of shape (N, H_out, W_out, 2), where H_out and + W_out are the height and width of grid and output, Grid specifies the + sampling pixel locations normalized by the input spatial dimensions. + Therefore, it should have most values in the range of [-1, 1]. If grid + has values outside the range of [-1, 1], the corresponding outputs will + be handled as defined by padding_mode. +align_corners + Attribute. + If align_corners=1, the extrema (-1 and 1) are considered as referring + to the center points of the input's corner pixels. If align_corners=0, + they are instead considered as referring to the corner points of the + input's corner pixels, making the sampling more resolution agnostic. +mode + Attribute. + Three interpolation modes: bilinear (default), nearest and bicubic. +padding_mode + Attribute. + Support padding modes for outside grid values: ``zeros``\ (default), + ``border``, ``reflection``. zeros: use 0 for out-of-bound grid + locations, border: use border values for out-of-bound grid locations, + reflection: use values at locations reflected by the border for + out-of-bound grid locations. If index 0 represents the margin pixel, the + reflected value at index -1 will be the same as the value at index 1. + For location far away from the border, it will keep being reflected + until becoming in bound. If pixel location x = -3.5 reflects by border + -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = + 0.5. + +Returns +======= +Y : Var + Type T1. + 4-D tensor of shape (N, C, H_out, W_out) of sampled values. For integer + input types, intermediate values are computed as floating point and cast + to integer at the end. + +Notes +===== +Signature: ``ai.onnx@16::GridSample``. + +Type constraints: + - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _GridSample( + _GridSample.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + mode=AttrString(mode, name="mode"), + padding_mode=AttrString(padding_mode, name="padding_mode"), + ), _GridSample.Inputs( + X=unwrap_vars(X), grid=unwrap_vars(grid), ), ).get_output_vars( + X=get_value(X), grid=get_value(grid), ).Y + + +def hamming_window(size: Var, *, output_datatype: int = 1, periodic: int = 1, ) -> Var: + r""" +Generates a Hamming window as described in the paper +https://ieeexplore.ieee.org/document/1455106. + +Parameters +========== +size + Type T1. + A scalar value indicating the length of the window. +output_datatype + Attribute. + The data type of the output tensor. Strictly must be one of the values + from DataType enum in TensorProto whose values correspond to T2. The + default value is 1 = FLOAT. +periodic + Attribute. + If 1, returns a window to be used as periodic function. If 0, return a + symmetric window. When 'periodic' is specified, hann computes a window + of length size + 1 and returns the first size points. The default value + is 1. + +Returns +======= +output : Var + Type T2. + A Hamming window with length: size. The output has the shape: [size]. + +Notes +===== +Signature: ``ai.onnx@17::HammingWindow``. + +Type constraints: + - T1: `tensor(int32)`, `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _HammingWindow( + _HammingWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), _HammingWindow.Inputs( + size=unwrap_vars(size), ), ).get_output_vars( + size=get_value(size), ).output + + +def hann_window(size: Var, *, output_datatype: int = 1, periodic: int = 1, ) -> Var: + r""" +Generates a Hann window as described in the paper +https://ieeexplore.ieee.org/document/1455106. + +Parameters +========== +size + Type T1. + A scalar value indicating the length of the window. +output_datatype + Attribute. + The data type of the output tensor. Strictly must be one of the values + from DataType enum in TensorProto whose values correspond to T2. The + default value is 1 = FLOAT. +periodic + Attribute. + If 1, returns a window to be used as periodic function. If 0, return a + symmetric window. When 'periodic' is specified, hann computes a window + of length size + 1 and returns the first size points. The default value + is 1. + +Returns +======= +output : Var + Type T2. + A Hann window with length: size. The output has the shape: [size]. + +Notes +===== +Signature: ``ai.onnx@17::HannWindow``. + +Type constraints: + - T1: `tensor(int32)`, `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _HannWindow( + _HannWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), _HannWindow.Inputs( + size=unwrap_vars(size), ), ).get_output_vars( + size=get_value(size), ).output + + +def hard_sigmoid(X: Var, *, alpha: float = 0.20000000298023224, beta: float = 0.5, ) -> Var: + r""" +HardSigmoid takes one input data (Tensor) and produces one output +data (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha +\* x + beta)), is applied to the tensor elementwise. + +Parameters +========== +X + Type T. + Input tensor +alpha + Attribute. + Value of alpha. +beta + Attribute. + Value of beta. + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@6::HardSigmoid``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _HardSigmoid( + _HardSigmoid.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + ), _HardSigmoid.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def hard_swish(X: Var, ) -> Var: + r""" +HardSwish takes one input data (Tensor) and produces one output data +(Tensor) where the HardSwish function, y = x \* max(0, min(1, alpha +\* x + beta)) = x \* HardSigmoid(x), where alpha = 1/6 and +beta = 0.5, is applied to the tensor elementwise. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@14::HardSwish``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _HardSwish( + _HardSwish.Attributes( + ), _HardSwish.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def hardmax(input: Var, *, axis: int = -1, ) -> Var: + r""" +The operator computes the hardmax values for the given input: + +Hardmax(element in input, axis) = 1 if the element is the first maximum +value along the specified axis, 0 otherwise + +The "axis" attribute indicates the dimension along which Hardmax will be +performed. The output tensor has the same shape and contains the Hardmax +values of the corresponding input. + +Parameters +========== +input + Type T. + The input tensor of rank >= axis. +axis + Attribute. + Describes the dimension Hardmax will be performed on. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(input). + +Returns +======= +output : Var + Type T. + The output values with the same shape as the input tensor. + +Notes +===== +Signature: ``ai.onnx@13::Hardmax``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Hardmax( + _Hardmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _Hardmax.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def identity(input: Var, ) -> Var: + r""" +Identity operator + +Parameters +========== +input + Type V. + Input tensor + +Returns +======= +output : Var + Type V. + Tensor to copy input into. + +Notes +===== +Signature: ``ai.onnx@16::Identity``. + +Type constraints: + - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Identity( + _Identity.Attributes( + ), _Identity.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def if_(cond: Var, *, else_branch: Callable[[], Iterable[Var]], then_branch: Callable[[], Iterable[Var]], ) -> Sequence[Var]: + r""" +If conditional + +Parameters +========== +cond + Type B. + Condition for the if. The tensor must contain a single element. +else_branch + Attribute. + Graph to run if condition is false. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the then_branch. +then_branch + Attribute. + Graph to run if condition is true. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the else_branch. + +Returns +======= +outputs : Sequence[Var] + Type V. + Values that are live-out to the enclosing scope. The return values in + the ``then_branch`` and ``else_branch`` must be of the same data type. + The ``then_branch`` and ``else_branch`` may produce tensors with the + same element type and different shapes. If corresponding outputs from + the then-branch and the else-branch have static shapes S1 and S2, then + the shape of the corresponding output variable of the if-node (if + present) must be compatible with both S1 and S2 as it represents the + union of both possible shapes.For example, if in a model file, the first + output of ``then_branch`` is typed float tensor with shape [2] and the + first output of ``else_branch`` is another float tensor with shape [3], + If's first output should have (a) no shape set, or (b) a shape of rank 1 + with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank + 1 with a unique ``dim_param``. In contrast, the first output cannot have + the shape [2] since [2] and [3] are not compatible. + +Notes +===== +Signature: ``ai.onnx@16::If``. + +Type constraints: + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + _else_branch_subgraph: Graph = subgraph( + (), + else_branch + ) + _then_branch_subgraph: Graph = subgraph( + (), + then_branch + ) + return _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), _If.Inputs( + cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), ).get_output_vars( + cond=get_value(cond), ).outputs + + +def instance_normalization(input: Var, scale: Var, B: Var, *, epsilon: float = 9.999999747378752e-06, ) -> Var: + r""" +Carries out instance normalization as described in the paper +https://arxiv.org/abs/1607.08022. + +y = scale \* (x - mean) / sqrt(variance + epsilon) + B, where mean and +variance are computed per instance per channel. + +Parameters +========== +input + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. +scale + Type T. + The input 1-dimensional scale tensor of size C. +B + Type T. + The input 1-dimensional bias tensor of size C. +epsilon + Attribute. + The epsilon value to use to avoid division by zero. + +Returns +======= +output : Var + Type T. + The output tensor of the same shape as input. + +Notes +===== +Signature: ``ai.onnx@6::InstanceNormalization``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _InstanceNormalization( + _InstanceNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + ), _InstanceNormalization.Inputs( + input=unwrap_vars(input), scale=unwrap_vars(scale), B=unwrap_vars(B), ), ).get_output_vars( + input=get_value(input), scale=get_value(scale), B=get_value(B), ).output + + +def isinf(X: Var, *, detect_negative: int = 1, detect_positive: int = 1, ) -> Var: + r""" +Map infinity to true and other values to false. + +Parameters +========== +X + Type T1. + input +detect_negative + Attribute. + (Optional) Whether map negative infinity to true. Default to 1 so that + negative infinity induces true. Set this attribute to 0 if negative + infinity should be mapped to false. +detect_positive + Attribute. + (Optional) Whether map positive infinity to true. Default to 1 so that + positive infinity induces true. Set this attribute to 0 if positive + infinity should be mapped to false. + +Returns +======= +Y : Var + Type T2. + output + +Notes +===== +Signature: ``ai.onnx@10::IsInf``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)` + - T2: `tensor(bool)` + """ + return _IsInf( + _IsInf.Attributes( + detect_negative=AttrInt64(detect_negative, name="detect_negative"), + detect_positive=AttrInt64(detect_positive, name="detect_positive"), + ), _IsInf.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def isnan(X: Var, ) -> Var: + r""" +Returns which elements of the input are NaN. + +Parameters +========== +X + Type T1. + input - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Asinh( - _Asinh.Attributes(), - _Asinh.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) +Returns +======= +Y : Var + Type T2. + output + +Notes +===== +Signature: ``ai.onnx@13::IsNaN``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(bool)` + """ + return _IsNaN( + _IsNaN.Attributes( + ), _IsNaN.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def lrn(X: Var, *, alpha: float = 9.999999747378752e-05, beta: float = 0.75, bias: float = 1.0, size: int, ) -> Var: + r""" +Local Response Normalization proposed in the `AlexNet +paper `__. +It normalizes over local input regions. The local region is defined +across the channels. For an element ``X[n, c, d1, ..., dk]`` in a tensor +of shape ``(N x C x D1 x D2, ..., Dk)``, its region is +``{X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}``. + +``square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2)``, where +``max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))``. + +``Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta`` + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. Optionally, if dimension denotation is in + effect, the operation expects the input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. +alpha + Attribute. + Scaling parameter. +beta + Attribute. + The exponent. +bias + Attribute. + +size + Attribute. + The number of channels to sum over + +Returns +======= +Y : Var + Type T. + Output tensor, which has the shape and type as input tensor + +Notes +===== +Signature: ``ai.onnx@13::LRN``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _LRN( + _LRN.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + bias=AttrFloat32(bias, name="bias"), + size=AttrInt64(size, name="size"), + ), _LRN.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def lstm(X: Var, W: Var, R: Var, B: Optional[Var] = None, sequence_lens: Optional[Var] = None, initial_h: Optional[Var] = None, initial_c: Optional[Var] = None, P: Optional[Var] = None, *, activation_alpha: Optional[Iterable[float]] = None, activation_beta: Optional[Iterable[float]] = None, activations: Optional[Iterable[str]] = None, clip: Optional[float] = None, direction: str = "forward", hidden_size: Optional[int] = None, input_forget: int = 0, layout: int = 0, ) -> tuple[Var, Var, Var]: + r""" +Computes an one-layer LSTM. This operator is usually supported via some +custom implementation such as CuDNN. + +Notations: + +- ``X`` - input tensor +- ``i`` - input gate +- ``o`` - output gate +- ``f`` - forget gate +- ``c`` - cell gate +- ``t`` - time step (t-1 means previous time step) +- ``W[iofc]`` - W parameter weight matrix for input, output, forget, + and cell gates +- ``R[iofc]`` - R recurrence weight matrix for input, output, forget, + and cell gates +- ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell + gates +- ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell + gates +- ``P[iof]`` - P peephole weight vector for input, output, and forget + gates +- ``WB[iofc]`` - W parameter weight matrix for backward input, output, + forget, and cell gates +- ``RB[iofc]`` - R recurrence weight matrix for backward input, output, + forget, and cell gates +- ``WBb[iofc]`` - W bias vectors for backward input, output, forget, + and cell gates +- ``RBb[iofc]`` - R bias vectors for backward input, output, forget, + and cell gates +- ``PB[iof]`` - P peephole weight vector for backward input, output, + and forget gates +- ``H`` - Hidden state +- ``num_directions`` - 2 if direction == bidirectional else 1 + +Activation functions: + +- Relu(x) - max(0, x) +- Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) +- Sigmoid(x) - 1/(1 + e^{-x}) + +NOTE: Below are optional + +- Affine(x) - alpha*x + beta +- LeakyRelu(x) - x if x >= 0 else alpha \* x +- ThresholdedRelu(x) - x if x >= alpha else 0 +- ScaledTanh(x) - alpha\ *Tanh(beta*\ x) +- HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) +- Elu(x) - x if x >= 0 else alpha*(e^x - 1) +- Softsign(x) - x/(1 + \|x\|) +- Softplus(x) - log(1 + e^x) + +Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): + +- it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) +- ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) +- ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) +- Ct = ft (.) Ct-1 + it (.) ct +- ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) +- Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See + `the doc `__ for + more details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. + +Parameters +========== +X + Type T. + The input sequences packed (and potentially padded) into one 3-D tensor + with the shape of ``[seq_length, batch_size, input_size]``. +W + Type T. + The weight tensor for the gates. Concatenation of ``W[iofc]`` and + ``WB[iofc]`` (if bidirectional) along dimension 0. The tensor has shape + ``[num_directions, 4*hidden_size, input_size]``. +R + Type T. + The recurrence weight tensor. Concatenation of ``R[iofc]`` and + ``RB[iofc]`` (if bidirectional) along dimension 0. This tensor has shape + ``[num_directions, 4*hidden_size, hidden_size]``. +B + Type T. + The bias tensor for input gate. Concatenation of + ``[Wb[iofc], Rb[iofc]]``, and ``[WBb[iofc], RBb[iofc]]`` (if + bidirectional) along dimension 0. This tensor has shape + ``[num_directions, 8*hidden_size]``. Optional: If not specified - + assumed to be 0. +sequence_lens + Type T1. + Optional tensor specifying lengths of the sequences in a batch. If not + specified - assumed all sequences in the batch to have length + ``seq_length``. It has shape ``[batch_size]``. +initial_h + Type T. + Optional initial value of the hidden. If not specified - assumed to be + 0. It has shape ``[num_directions, batch_size, hidden_size]``. +initial_c + Type T. + Optional initial value of the cell. If not specified - assumed to be 0. + It has shape ``[num_directions, batch_size, hidden_size]``. +P + Type T. + The weight tensor for peepholes. Concatenation of ``P[iof]`` and + ``PB[iof]`` (if bidirectional) along dimension 0. It has shape + ``[num_directions, 3*hidde_size]``. Optional: If not specified - assumed + to be 0. +activation_alpha + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX + operators.For example with LeakyRelu, the default alpha is 0.01. +activation_beta + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX operators. +activations + Attribute. + A list of 3 (or 6 if bidirectional) activation functions for input, + output, forget, cell, and hidden. The activation functions must be one + of the activation functions specified above. Optional: See the equations + for default if not specified. +clip + Attribute. + Cell clip threshold. Clipping bounds the elements of a tensor in the + range of [-threshold, +threshold] and is applied to the input of + activations. No clip if not specified. +direction + Attribute. + Specify if the RNN is forward, reverse, or bidirectional. Must be one of + forward (default), reverse, or bidirectional. +hidden_size + Attribute. + Number of neurons in the hidden layer +input_forget + Attribute. + Couple the input and forget gates if 1. +layout + Attribute. + The shape format of inputs X, initial_h, initial_c and outputs Y, Y_h, + Y_c. If 0, the following shapes are expected: X.shape = [seq_length, + batch_size, input_size], Y.shape = [seq_length, num_directions, + batch_size, hidden_size], initial_h.shape = Y_h.shape = initial_c.shape + = Y_c.shape = [num_directions, batch_size, hidden_size]. If 1, the + following shapes are expected: X.shape = [batch_size, seq_length, + input_size], Y.shape = [batch_size, seq_length, num_directions, + hidden_size], initial_h.shape = Y_h.shape = initial_c.shape = Y_c.shape + = [batch_size, num_directions, hidden_size]. + +Returns +======= +Y : Var + Type T. + A tensor that concats all the intermediate output values of the hidden. + It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. +Y_h : Var + Type T. + The last output value of the hidden. It has shape + ``[num_directions, batch_size, hidden_size]``. +Y_c : Var + Type T. + The last output value of the cell. It has shape + ``[num_directions, batch_size, hidden_size]``. + +Notes +===== +Signature: ``ai.onnx@14::LSTM``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(int32)` + """ + return _LSTM( + _LSTM.Attributes( + activation_alpha=AttrFloat32s.maybe(activation_alpha, name="activation_alpha"), + activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), + activations=AttrStrings.maybe(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + input_forget=AttrInt64(input_forget, name="input_forget"), + layout=AttrInt64(layout, name="layout"), + ), _LSTM.Inputs( + X=unwrap_vars(X), W=unwrap_vars(W), R=unwrap_vars(R), B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), initial_c=unwrap_vars(initial_c), P=unwrap_vars(P), ), ).get_output_vars( + X=get_value(X), W=get_value(W), R=get_value(R), B=get_value(B), sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), initial_c=get_value(initial_c), P=get_value(P), )._unpack_to_any() + + +def layer_normalization(X: Var, Scale: Var, B: Optional[Var] = None, *, axis: int = -1, epsilon: float = 9.999999747378752e-06, stash_type: int = 1, ) -> tuple[Var, Var, Var]: + r""" +This is layer normalization defined in ONNX as function. The overall +computation can be split into two stages. The first stage is +standardization, which makes the normalized elements have zero mean and +unit variances. The computation required by standardization can be +described by the following equations. +``Mean = ReduceMean(X) D = Sub(X, Mean) DD = Mul(D, D) Var = ReduceMean(DD) VarEps = Add(Var, epsilon) StdDev = Sqrt(VarEps) InvStdDev = Reciprocal(StdDev) Normalized = Mul(D, InvStdDev)`` +where ``normalized_axes`` is ``[axis, ..., rank of X - 1]``. The +variables ``Var`` and ``StdDev`` stand for variance and standard +deviation, respectively. The second output is ``Mean`` and the last one +is ``InvStdDev``. Depending on ``stash_type`` attribute, the actual +computation must happen in different floating-point precision. For +example, if ``stash_type`` is 1, this operator casts all input variables +to 32-bit float, perform the computation, and finally cast +``Normalized`` back to the original type of ``X``. The second stage then +scales and shifts the outcome of the first stage using +``NormalizedScaled = Mul(Normalized, Scale) Y = Add(NormalizedScaled, B)`` +The second stage doesn't depends on ``stash_type``. All equations are in +`this syntax `__. +The same variable (i.e., input, output, and attribute) uses the same +name in the equations above and this operator's definition. Let ``d[i]`` +indicate the i-th dimension of ``X``. If ``X``'s shape is +``[d[0], ..., d[axis-1], d[axis], ..., d[rank-1]]``, the shape of +``Mean`` and ``InvStdDev`` is ``[d[0], ..., d[axis-1], 1, ..., 1]``. +``Y`` and ``X`` have the same shape. This operator supports +unidirectional broadcasting (tensors ``Scale`` and ``B`` should be +unidirectional broadcastable to tensor ``X``); for more details please +check `the +doc `__. + +Parameters +========== +X + Type T. + Tensor to be normalized. +Scale + Type T. + Scale tensor. +B + Type T. + Bias tensor. +axis + Attribute. + The first normalization dimension. If rank(X) is r, axis' allowed range + is [-r, r). Negative value means counting dimensions from the back. +epsilon + Attribute. + The epsilon value to use to avoid division by zero. +stash_type + Attribute. + Type of Mean and InvStdDev. This also specifies stage one's computation + precision. + +Returns +======= +Y : Var + Type T. + Normalized tensor. +Mean : Var + Type U. + Saved mean used during training to speed up gradient computation +InvStdDev : Var + Type U. + Saved inverse standard deviation used during training to speed up + gradient computation. + +Notes +===== +Signature: ``ai.onnx@17::LayerNormalization``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - U: `tensor(bfloat16)`, `tensor(float)` + """ + return _LayerNormalization( + _LayerNormalization.Attributes( + axis=AttrInt64(axis, name="axis"), + epsilon=AttrFloat32(epsilon, name="epsilon"), + stash_type=AttrInt64(stash_type, name="stash_type"), + ), _LayerNormalization.Inputs( + X=unwrap_vars(X), Scale=unwrap_vars(Scale), B=unwrap_vars(B), ), ).get_output_vars( + X=get_value(X), Scale=get_value(Scale), B=get_value(B), )._unpack_to_any() + + +def leaky_relu(X: Var, *, alpha: float = 0.009999999776482582, ) -> Var: + r""" +LeakyRelu takes input data (Tensor) and an argument alpha, and +produces one output data (Tensor) where the function +``f(x) = alpha * x for x < 0``, ``f(x) = x for x >= 0``, is applied to +the data tensor elementwise. + +Parameters +========== +X + Type T. + Input tensor +alpha + Attribute. + Coefficient of leakage. + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@16::LeakyRelu``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _LeakyRelu( + _LeakyRelu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), _LeakyRelu.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def less(A: Var, B: Var, ) -> Var: + r""" +Returns the tensor resulted from performing the ``less`` logical +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. + +Returns +======= +C : Var + Type T1. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@13::Less``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return _Less( + _Less.Attributes( + ), _Less.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def less_or_equal(A: Var, B: Var, ) -> Var: + r""" +Returns the tensor resulted from performing the ``less_equal`` logical +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. + +Returns +======= +C : Var + Type T1. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@16::LessOrEqual``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return _LessOrEqual( + _LessOrEqual.Attributes( + ), _LessOrEqual.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def log(input: Var, ) -> Var: + r""" +Calculates the natural log of the given input tensor, element-wise. +Parameters +========== +input + Type T. + Input tensor -def atan( - input: Var, -) -> Var: - r""" - Calculates the arctangent (inverse of tangent) of the given input - tensor, element-wise. +Returns +======= +output : Var + Type T. + The natural log of the input tensor computed element-wise - Parameters - ========== - input - Type T. - Input tensor +Notes +===== +Signature: ``ai.onnx@13::Log``. - Returns - ======= - output : Var - Type T. - The arctangent of the input tensor computed element-wise +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Log( + _Log.Attributes( + ), _Log.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def log_softmax(input: Var, *, axis: int = -1, ) -> Var: + r""" +The operator computes the log of softmax values for the given input: + +LogSoftmax(input, axis) = Log(Softmax(input, axis=axis)) + +The "axis" attribute indicates the dimension along which LogSoftmax will +be performed. The output tensor has the same shape and contains the +LogSoftmax values of the corresponding input. + +Parameters +========== +input + Type T. + The input tensor of rank >= axis. +axis + Attribute. + Describes the dimension LogSoftmax will be performed on. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(input). + +Returns +======= +output : Var + Type T. + The output values with the same shape as the input tensor. + +Notes +===== +Signature: ``ai.onnx@13::LogSoftmax``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _LogSoftmax( + _LogSoftmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _LogSoftmax.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def loop(M: Optional[Var] = None, cond: Optional[Var] = None, v_initial: Sequence[Var] = (), *, body: Callable[..., Iterable[Var]], ) -> Sequence[Var]: + r""" +Generic Looping construct. This loop has multiple termination +conditions: + +1) Trip count. Iteration count specified at runtime. Set by specifying + the input M. Optional. Set to empty string to omit. Note that a + static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. +2) Loop termination condition. This is an input to the op that + determines whether to run the first iteration and also a loop-carried + dependency for the body graph. The body graph must yield a value for + the condition variable, whether this input is provided or not. + +This table summarizes the operating modes of this operator with +equivalent C-style code: + +Operator inputs defined as (max_trip_count, condition_var). + +- input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } + +- input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } + +- input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } + +- input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } + +- input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } + +*Sample usage - cond as well as trip count* + +:: + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + +*Sample equivalent C code* + +:: + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + +There are several things of note in this code snippet: + +1) Values from the enclosing scope (i.e. variable "a" here) are in scope + and can be referenced in the inputs of the loop. +2) Any values computed in the loop body that needs to be used in a + subsequent iteration or after the loop are modelled using a pair of + variables in the loop-body, consisting of an input variable (eg., + b_in) and an output variable (eg., b_out). These are referred to as + loop-carried dependences. The loop operation node supplies the input + value of the input variable for the first iteration, and returns the + output value of the output variable produced by the final iteration. +3) Scan_output variables are used to implicitly concatenate values + computed across all the iterations. In the above example, the value + of user_defined_val computed over all iterations are concatenated and + returned as the value of user_defined_vals after the loop. +4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + +Note that the semantics of this op support "diagonal" or "wavefront" +execution. (See Step 3 here for an example: +https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). +Frontends should emit multi-layer RNNs as a series of While operators +(with time being the inner looping dimension), with each successive +layer consuming the scan_outputs from the previous layer, possibly going +through several point-wise operators (e.g. dropout, residual +connections, linear layer). + +The input/output of subgraph (produced by loop node) matching is based +on order instead of name. The implementation will figure out the names +based on this order. + +Parameters +========== +M + Type I. + A maximum trip-count for the loop specified at runtime. Optional. Pass + empty string to skip. +cond + Type B. + A boolean termination condition. Optional. Pass empty string to skip. +v_initial + Type V. + The initial values of any loop-carried dependencies (values that change + across loop iterations) +body + Attribute. + The graph run each iteration. It has 2+N inputs: (iteration_num, + condition, loop carried dependencies...). It has 1+N+K outputs: + (condition, loop carried dependencies..., scan_outputs...). Each + scan_output is created by concatenating the value of the specified + output value at the end of each iteration of the loop. It is an error if + the dimensions or data type of these scan_outputs change across loop + iterations. + +Returns +======= +v_final_and_scan_outputs : Sequence[Var] + Type V. + Final N loop carried dependency values then K scan_outputs. Scan outputs + must be Tensors. + +Notes +===== +Signature: ``ai.onnx@16::Loop``. + +Type constraints: + - I: `tensor(int64)` + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + _body_subgraph: Graph = subgraph( + typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))])+ [var.unwrap_type() for var in v_initial], + body + ) + return _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), _Loop.Inputs( + M=unwrap_vars(M), cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, ).get_output_vars( + M=get_value(M), cond=get_value(cond), v_initial=get_value(v_initial), ).v_final_and_scan_outputs + + +def lp_normalization(input: Var, *, axis: int = -1, p: int = 2, ) -> Var: + r""" +Given a matrix, apply Lp-normalization along the provided axis. + +Parameters +========== +input + Type T. + Input matrix +axis + Attribute. + The axis on which to apply normalization, -1 mean last axis. +p + Attribute. + The order of the normalization, only 1 or 2 are supported. + +Returns +======= +output : Var + Type T. + Matrix after normalization + +Notes +===== +Signature: ``ai.onnx@1::LpNormalization``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _LpNormalization( + _LpNormalization.Attributes( + axis=AttrInt64(axis, name="axis"), + p=AttrInt64(p, name="p"), + ), _LpNormalization.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def lp_pool(X: Var, *, auto_pad: str = "NOTSET", kernel_shape: Iterable[int], p: int = 2, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + r""" +LpPool consumes an input tensor X and applies Lp pooling across the +tensor according to kernel sizes, stride sizes, and pad lengths. Lp +pooling consisting of computing the Lp norm on all values of a subset of +the input tensor according to the kernel size and downsampling the data +into the output tensor Y for further processing. + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. +kernel_shape + Attribute. + The size of the kernel along each axis. +p + Attribute. + p value of the Lp norm used to pool over the input data. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + +Returns +======= +Y : Var + Type T. + Output data tensor from Lp pooling across the input tensor. Dimensions + will vary based on various kernel, stride, and pad sizes. + +Notes +===== +Signature: ``ai.onnx@11::LpPool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _LpPool( + _LpPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + p=AttrInt64(p, name="p"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _LpPool.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def matmul(A: Var, B: Var, ) -> Var: + r""" +Matrix product that behaves like numpy.matmul: +https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + +Parameters +========== +A + Type T. + N-dimensional matrix A +B + Type T. + N-dimensional matrix B + +Returns +======= +Y : Var + Type T. + Matrix multiply results from A \* B + +Notes +===== +Signature: ``ai.onnx@13::MatMul``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _MatMul( + _MatMul.Attributes( + ), _MatMul.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).Y + + +def matmul_integer(A: Var, B: Var, a_zero_point: Optional[Var] = None, b_zero_point: Optional[Var] = None, ) -> Var: + r""" +Matrix product that behaves like numpy.matmul: +https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. +The production MUST never overflow. The accumulation may overflow if and +only if in 32 bits. + +Parameters +========== +A + Type T1. + N-dimensional matrix A +B + Type T2. + N-dimensional matrix B +a_zero_point + Type T1. + Zero point tensor for input 'A'. It's optional and default value is 0. + It could be a scalar or N-D tensor. Scalar refers to per tensor + quantization whereas N-D refers to per row quantization. If the input is + 2D of shape [M, K] then zero point tensor may be an M element vector + [zp_1, zp_2, ..., zp_M]. If the input is N-D tensor with shape [D1, D2, + M, K] then zero point tensor may have shape [D1, D2, M, 1]. +b_zero_point + Type T2. + Zero point tensor for input 'B'. It's optional and default value is 0. + It could be a scalar or a N-D tensor, Scalar refers to per tensor + quantization whereas N-D refers to per col quantization. If the input is + 2D of shape [K, N] then zero point tensor may be an N element vector + [zp_1, zp_2, ..., zp_N]. If the input is N-D tensor with shape [D1, D2, + K, N] then zero point tensor may have shape [D1, D2, 1, N]. + +Returns +======= +Y : Var + Type T3. + Matrix multiply results from A \* B + +Notes +===== +Signature: ``ai.onnx@10::MatMulInteger``. + +Type constraints: + - T1: `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(int32)` + """ + return _MatMulInteger( + _MatMulInteger.Attributes( + ), _MatMulInteger.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), a_zero_point=unwrap_vars(a_zero_point), b_zero_point=unwrap_vars(b_zero_point), ), ).get_output_vars( + A=get_value(A), B=get_value(B), a_zero_point=get_value(a_zero_point), b_zero_point=get_value(b_zero_point), ).Y + + +def max(data_0: Sequence[Var], ) -> Var: + r""" +Element-wise max of each of the input tensors (with Numpy-style +broadcasting support). All inputs and outputs must have the same data +type. This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +data_0 + Type T. + List of tensors for max. + +Returns +======= +max : Var + Type T. + Output tensor. + +Notes +===== +Signature: ``ai.onnx@13::Max``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Max( + _Max.Attributes( + ), _Max.Inputs( + data_0=unwrap_vars(data_0), ), ).get_output_vars( + data_0=get_value(data_0), ).max + + +def max_pool(X: Var, *, auto_pad: str = "NOTSET", ceil_mode: int = 0, dilations: Optional[Iterable[int]] = None, kernel_shape: Iterable[int], pads: Optional[Iterable[int]] = None, storage_order: int = 0, strides: Optional[Iterable[int]] = None, ) -> tuple[Var, Var]: + r""" +MaxPool consumes an input tensor X and applies max pooling across the +tensor according to kernel sizes, stride sizes, and pad lengths. max +pooling consisting of computing the max on all values of a subset of the +input tensor according to the kernel size and downsampling the data into +the output tensor Y for further processing. The output spatial shape is +calculated differently depending on whether explicit padding is used, +where pads is employed, or auto padding is used, where auto_pad is +utilized. With explicit padding +(https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): + +:: + + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + +or + +:: + + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + +if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis +``i``. Sliding windows that would start in the right padded region are +ignored. + +``auto_pad`` is a DEPRECATED attribute. If you are using them currently, +the output spatial shape will be following when ceil_mode is enabled: + +:: + + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + +or when ceil_mode is disabled +(https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): + +:: + + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 + +And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: + +:: + + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + +The output of each pooling window is maximum number of elements exclude +pad. + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. Optionally, if dimension denotation is in + effect, the operation expects the input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. +ceil_mode + Attribute. + Whether to use ceil or floor (default) to compute the output shape. +dilations + Attribute. + Dilation value along each spatial axis of filter. If not present, the + dilation defaults to 1 along each spatial axis. +kernel_shape + Attribute. + The size of the kernel along each axis. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. +storage_order + Attribute. + The storage order of the tensor. 0 is row major, and 1 is column major. + This attribute is used only to convert an n-tuple index value into a + single integer value for producing the second output. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + +Returns +======= +Y : Var + Type T. + Output data tensor from average or max pooling across the input tensor. + Dimensions will vary based on various kernel, stride, and pad sizes. + Floor value of the dimension is used +Indices : Var + Type I. + Indices tensor from max pooling across the input tensor. The dimensions + of indices are the same as output tensor. The values in indices of are + the indices of the selected values during pooling. The indices are + computed as flatten 1-D tensor, and the indices do not consider padding. + So the values in indices are in [0, N x C x D1 x ... x Dn). + +Notes +===== +Signature: ``ai.onnx@12::MaxPool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int8)`, `tensor(uint8)` + - I: `tensor(int64)` + """ + return _MaxPool( + _MaxPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + storage_order=AttrInt64(storage_order, name="storage_order"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _MaxPool.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), )._unpack_to_any() + + +def max_roi_pool(X: Var, rois: Var, *, pooled_shape: Iterable[int], spatial_scale: float = 1.0, ) -> Var: + r""" +ROI max pool consumes an input tensor X and region of interests (RoIs) +to apply max pooling across each RoI, to produce output 4-D tensor of +shape (num_rois, channels, pooled_shape[0], pooled_shape[1]). + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. +rois + Type T. + RoIs (Regions of Interest) to pool over. Should be a 2-D tensor of shape + (num_rois, 5) given as [[batch_id, x1, y1, x2, y2], ...]. +pooled_shape + Attribute. + ROI pool output shape (height, width). +spatial_scale + Attribute. + Multiplicative spatial scale factor to translate ROI coordinates from + their input scale to the scale used when pooling. + +Returns +======= +Y : Var + Type T. + RoI pooled output 4-D tensor of shape (num_rois, channels, + pooled_shape[0], pooled_shape[1]). + +Notes +===== +Signature: ``ai.onnx@1::MaxRoiPool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _MaxRoiPool( + _MaxRoiPool.Attributes( + pooled_shape=AttrInt64s(pooled_shape, name="pooled_shape"), + spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), + ), _MaxRoiPool.Inputs( + X=unwrap_vars(X), rois=unwrap_vars(rois), ), ).get_output_vars( + X=get_value(X), rois=get_value(rois), ).Y + + +def max_unpool(X: Var, I: Var, output_shape: Optional[Var] = None, *, kernel_shape: Iterable[int], pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + r""" +MaxUnpool essentially computes the partial inverse of the MaxPool op. +The input information to this op is typically the output information +from a MaxPool op. The first input tensor X is the tensor that needs to +be unpooled, which is typically the pooled tensor (first output) from +MaxPool. The second input tensor, I, contains the indices to the +(locally maximal) elements corresponding to the elements in the first +input tensor X. Input tensor I is typically the second output of the +MaxPool op. The third (optional) input is a tensor that specifies the +output size of the unpooling operation. + +MaxUnpool is intended to do 'partial' inverse of the MaxPool op. +'Partial' because all the non-maximal values from the original input to +MaxPool are set to zero in the output of the MaxUnpool op. Pooling the +result of an unpooling operation should give back the original input to +the unpooling op. + +MaxUnpool can produce the same output size for several input sizes, +which makes unpooling op ambiguous. The third input argument, +output_size, is meant to disambiguate the op and produce output tensor +of known/predictable size. + +In addition to the inputs, MaxUnpool takes three attributes, namely +kernel_shape, strides, and pads, which define the exact unpooling op. +The attributes typically have the same values as the corresponding +pooling op that the unpooling op is trying to invert. + +Parameters +========== +X + Type T1. + Input data tensor that has to be unpooled. This tensor is typically the + first output of the MaxPool op.Dimensions for image case are (N x C x H + x W), where N is the batch size, C is the number of channels, and H and + W are the height and the width of the data. For non-image case, the + dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the + batch size. Optionally, if dimension denotation is in effect, the + operation expects the input data tensor to arrive with the dimension + denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE + ...]. +I + Type T2. + Input data tensor containing the indices corresponding to elements in + the first input tensor X.This tensor is typically the second output of + the MaxPool op.Dimensions must be the same as input tensor X. The + indices are linear, i.e. computed considering the tensor as flattened + 1-D tensor, assuming row-major storage. Also, the linear indices should + not consider padding. So the values in indices are in the range [0, N x + C x D1 x ... x Dn). +output_shape + Type T2. + The shape of the output can be explicitly set which will cause pads + values to be auto generated. If 'output_shape' is specified, 'pads' + values are ignored. +kernel_shape + Attribute. + The size of the kernel along each axis. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + +Returns +======= +output : Var + Type T1. + Output data tensor that contains the result of the unpooling. + +Notes +===== +Signature: ``ai.onnx@11::MaxUnpool``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int64)` + """ + return _MaxUnpool( + _MaxUnpool.Attributes( + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _MaxUnpool.Inputs( + X=unwrap_vars(X), I=unwrap_vars(I), output_shape=unwrap_vars(output_shape), ), ).get_output_vars( + X=get_value(X), I=get_value(I), output_shape=get_value(output_shape), ).output + + +def mean(data_0: Sequence[Var], ) -> Var: + r""" +Element-wise mean of each of the input tensors (with Numpy-style +broadcasting support). All inputs and outputs must have the same data +type. This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +data_0 + Type T. + List of tensors for mean. + +Returns +======= +mean : Var + Type T. + Output tensor. + +Notes +===== +Signature: ``ai.onnx@13::Mean``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Mean( + _Mean.Attributes( + ), _Mean.Inputs( + data_0=unwrap_vars(data_0), ), ).get_output_vars( + data_0=get_value(data_0), ).mean + + +def mean_variance_normalization(X: Var, *, axes: Iterable[int] = (0, 2, 3), ) -> Var: + r""" +A MeanVarianceNormalization Function: Perform mean variance +normalization on the input tensor X using formula: +``(X-EX)/sqrt(E(X-EX)^2)`` + +Parameters +========== +X + Type T. + Input tensor +axes + Attribute. + A list of integers, along which to reduce. The default is to calculate + along axes [0,2,3] for calculating mean and variance along each channel. + Two variables with the same C-coordinate are associated with the same + mean and variance. + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@13::MeanVarianceNormalization``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _MeanVarianceNormalization( + _MeanVarianceNormalization.Attributes( + axes=AttrInt64s(axes, name="axes"), + ), _MeanVarianceNormalization.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def mel_weight_matrix(num_mel_bins: Var, dft_length: Var, sample_rate: Var, lower_edge_hertz: Var, upper_edge_hertz: Var, *, output_datatype: int = 1, ) -> Var: + r""" +Generate a MelWeightMatrix that can be used to re-weight a Tensor +containing a linearly sampled frequency spectra (from DFT or STFT) into +num_mel_bins frequency information based on the [lower_edge_hertz, +upper_edge_hertz] range on the mel scale. This function defines the mel +scale in terms of a frequency in hertz according to the following +formula: + +:: + + mel(f) = 2595 * log10(1 + f/700) + +In the returned matrix, all the triangles (filterbanks) have a peak +value of 1.0. + +The returned MelWeightMatrix can be used to right-multiply a spectrogram +S of shape [frames, num_spectrogram_bins] of linear scale spectrum +values (e.g. STFT magnitudes) to generate a "mel spectrogram" M of shape +[frames, num_mel_bins]. + +Parameters +========== +num_mel_bins + Type T1. + The number of bands in the mel spectrum. +dft_length + Type T1. + The size of the original DFT. The size of the original DFT is used to + infer the size of the onesided DFT, which is understood to be + floor(dft_length/2) + 1, i.e. the spectrogram only contains the + nonredundant DFT bins. +sample_rate + Type T1. + Samples per second of the input signal used to create the spectrogram. + Used to figure out the frequencies corresponding to each spectrogram + bin, which dictates how they are mapped into the mel scale. +lower_edge_hertz + Type T2. + Lower bound on the frequencies to be included in the mel spectrum. This + corresponds to the lower edge of the lowest triangular band. +upper_edge_hertz + Type T2. + The desired top edge of the highest frequency band. +output_datatype + Attribute. + The data type of the output tensor. Strictly must be one of the values + from DataType enum in TensorProto whose values correspond to T3. The + default value is 1 = FLOAT. + +Returns +======= +output : Var + Type T3. + The Mel Weight Matrix. The output has the shape: [floor(dft_length/2) + + 1][num_mel_bins]. + +Notes +===== +Signature: ``ai.onnx@17::MelWeightMatrix``. + +Type constraints: + - T1: `tensor(int32)`, `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T3: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _MelWeightMatrix( + _MelWeightMatrix.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + ), _MelWeightMatrix.Inputs( + num_mel_bins=unwrap_vars(num_mel_bins), dft_length=unwrap_vars(dft_length), sample_rate=unwrap_vars(sample_rate), lower_edge_hertz=unwrap_vars(lower_edge_hertz), upper_edge_hertz=unwrap_vars(upper_edge_hertz), ), ).get_output_vars( + num_mel_bins=get_value(num_mel_bins), dft_length=get_value(dft_length), sample_rate=get_value(sample_rate), lower_edge_hertz=get_value(lower_edge_hertz), upper_edge_hertz=get_value(upper_edge_hertz), ).output + + +def min(data_0: Sequence[Var], ) -> Var: + r""" +Element-wise min of each of the input tensors (with Numpy-style +broadcasting support). All inputs and outputs must have the same data +type. This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +data_0 + Type T. + List of tensors for min. + +Returns +======= +min : Var + Type T. + Output tensor. + +Notes +===== +Signature: ``ai.onnx@13::Min``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Min( + _Min.Attributes( + ), _Min.Inputs( + data_0=unwrap_vars(data_0), ), ).get_output_vars( + data_0=get_value(data_0), ).min + + +def mod(A: Var, B: Var, *, fmod: int = 0, ) -> Var: + r""" +Performs element-wise binary modulus (with Numpy-style broadcasting +support). The sign of the remainder is the same as that of the Divisor. + +Mod operator can also behave like C fmod() or numpy.fmod. In this case, +the sign of the remainder however, will be the same as the Dividend (in +contrast to integer mod). To force a behavior like numpy.fmod() an +'fmod' Attribute is provided. This attribute is set to 0 by default +causing the behavior to be like integer mod. Setting this attribute to 1 +causes the remainder to be calculated similar to that of numpy.fmod(). + +If the input type is floating point, then ``fmod`` attribute must be set +to 1. + +In case of dividend being zero, the results will be platform dependent. + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + Dividend tensor +B + Type T. + Divisor tensor +fmod + Attribute. + Whether the operator should behave like fmod (default=0 meaning it will + do integer mods); Set this to 1 to force fmod treatment + +Returns +======= +C : Var + Type T. + Remainder tensor + +Notes +===== +Signature: ``ai.onnx@13::Mod``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Mod( + _Mod.Attributes( + fmod=AttrInt64(fmod, name="fmod"), + ), _Mod.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def mul(A: Var, B: Var, ) -> Var: + r""" +Performs element-wise binary multiplication (with Numpy-style +broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +(Opset 14 change): Extend supported types to include uint8, int8, +uint16, and int16. + +Parameters +========== +A + Type T. + First operand. +B + Type T. + Second operand. + +Returns +======= +C : Var + Type T. + Result, has same element type as two inputs + +Notes +===== +Signature: ``ai.onnx@14::Mul``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Mul( + _Mul.Attributes( + ), _Mul.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def multinomial(input: Var, *, dtype: npt.DTypeLike = np.int32, sample_size: int = 1, seed: Optional[float] = None, ) -> Var: + r""" +Generate a tensor of samples from a multinomial distribution according +to the probabilities of each of the possible outcomes. + +Parameters +========== +input + Type T1. + Input tensor with shape [batch_size, class_size], where class_size is + the number of all possible outcomes. Each value along the axis zero + represents the unnormalized log-probability of each corresponding + outcome in a batch. +dtype + Attribute. + (Optional) The data type for the elements of the output tensor, if not + specified, we will use int32. +sample_size + Attribute. + Number of times to sample. +seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + +Returns +======= +output : Var + Type T2. + Output tensor with shape [batch_size, sample_size], where sample_size is + the number of times to sample. Each value along the axis zero represents + the outcome of the corresponding sample in a batch. - Notes - ===== - Signature: ``ai.onnx@7::Atan``. +Notes +===== +Signature: ``ai.onnx@7::Multinomial``. - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int32)`, `tensor(int64)` """ - return ( - _Atan( - _Atan.Attributes(), - _Atan.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Multinomial( + _Multinomial.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + sample_size=AttrInt64(sample_size, name="sample_size"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), _Multinomial.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def atanh( - input: Var, -) -> Var: +def neg(X: Var, ) -> Var: r""" - Calculates the hyperbolic arctangent of the given input tensor - element-wise. +Neg takes one input data (Tensor) and produces one output data +(Tensor) where each element flipped sign, y = -x, is applied to the +tensor elementwise. - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The hyperbolic arctangent values of the input tensor computed - element-wise - - Notes - ===== - Signature: ``ai.onnx@9::Atanh``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Atanh( - _Atanh.Attributes(), - _Atanh.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) +Parameters +========== +X + Type T. + Input tensor +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@13::Neg``. -def average_pool( - X: Var, - *, - auto_pad: str = "NOTSET", - ceil_mode: int = 0, - count_include_pad: int = 0, - kernel_shape: Iterable[int], - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: - r""" - AveragePool consumes an input tensor X and applies average pooling - across the tensor according to kernel sizes, stride sizes, and pad - lengths. average pooling consisting of computing the average on all - values of a subset of the input tensor according to the kernel size and - downsampling the data into the output tensor Y for further processing. - The output spatial shape will be following: - - :: - - output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) - - or - - :: - - output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) - - if ceil_mode is enabled - - :: - - * pad_shape[i] is sum of pads along axis i - - ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, - the output spatial shape will be following when ceil_mode is enabled: - - :: - - VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) - - or when ceil_mode is disabled: - - :: - - VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor(input_spatial_shape[i] / strides_spatial_shape[i]) - - And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: - - :: - - pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] - - The output of each pooling window is divided by the number of elements - (exclude pad when attribute count_include_pad is zero). - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. Optionally, if dimension denotation is in - effect, the operation expects the input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. - ceil_mode - Attribute. - Whether to use ceil or floor (default) to compute the output shape. - count_include_pad - Attribute. - Whether include pad pixels when calculating values for the edges. - Default is 0, doesn't count include pad. - kernel_shape - Attribute. - The size of the kernel along each axis. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - - Returns - ======= - Y : Var - Type T. - Output data tensor from average or max pooling across the input tensor. - Dimensions will vary based on various kernel, stride, and pad sizes. - Floor value of the dimension is used - - Notes - ===== - Signature: ``ai.onnx@11::AveragePool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ - return ( - _AveragePool( - _AveragePool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - count_include_pad=AttrInt64( - count_include_pad, name="count_include_pad" - ), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _AveragePool.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _Neg( + _Neg.Attributes( + ), _Neg.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y -def batch_normalization( - X: Var, - scale: Var, - B: Var, - input_mean: Var, - input_var: Var, - *, - epsilon: float = 9.999999747378752e-06, - momentum: float = 0.8999999761581421, - training_mode: int = 0, -) -> tuple[Var, Var, Var]: +def negative_log_likelihood_loss(input: Var, target: Var, weight: Optional[Var] = None, *, ignore_index: Optional[int] = None, reduction: str = "mean", ) -> Var: r""" - Carries out batch normalization as described in the paper - https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, - There are five required inputs 'X', 'scale', 'B', 'input_mean' and - 'input_var'. Note that 'input_mean' and 'input_var' are expected to be - the estimated statistics in inference mode (training_mode=False, - default), and the running statistics in training mode - (training_mode=True). There are multiple cases for the number of - outputs, which we list below: - - - Output case #1: Y, running_mean, running_var (training_mode=True) - - Output case #2: Y (training_mode=False) - - When training_mode=False, extra outputs are invalid. The outputs are - updated as follows when training_mode=True: - - :: - - running_mean = input_mean * momentum + current_mean * (1 - momentum) - running_var = input_var * momentum + current_var * (1 - momentum) - - Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B - - where: - - :: - - current_mean = ReduceMean(X, axis=all_except_channel_index) - current_var = ReduceVar(X, axis=all_except_channel_index) - - Notice that ``ReduceVar`` refers to the population variance, and it - equals to ``sum(sqrd(x_i - x_avg)) / N`` where ``N`` is the population - size (this formula does not use sample size ``N - 1``). - - The computation of ReduceMean and ReduceVar uses float to avoid overflow - for float16 inputs. - - When training_mode=False: - - :: - - Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B - - For previous (depreciated) non-spatial cases, implementors are suggested - to flatten the input shape to (N x C \* D1 \* D2 \* ... \* Dn) before a - BatchNormalization Op. This operator has **optional** inputs/outputs. - See `the doc `__ for - more details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to indicate - a missing argument. Trailing optional arguments (those not followed by - an argument that is present) may also be simply omitted. - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions are in the form - of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number - of channels. Statistics are computed for every channel of C over N and - D1 to Dn dimensions. For image data, input dimensions become (N x C x H - x W). The op also accepts single dimension input of size N in which case - C is assumed to be 1 - scale - Type T1. - Scale tensor of shape (C). - B - Type T1. - Bias tensor of shape (C). - input_mean - Type T2. - running (training) or estimated (testing) mean tensor of shape (C). - input_var - Type T2. - running (training) or estimated (testing) variance tensor of shape (C). - epsilon - Attribute. - The epsilon value to use to avoid division by zero. - momentum - Attribute. - Factor used in computing the running mean and variance.e.g., - running_mean = running_mean \* momentum + mean \* (1 - momentum). - training_mode - Attribute. - If set to true, it indicates BatchNormalization is being used for - training, and outputs 1 and 2 are to be computed. - - Returns - ======= - Y : Var - Type T. - The output tensor of the same shape as X - running_mean : Var - Type T2. - The running mean after the BatchNormalization operator. - running_var : Var - Type T2. - The running variance after the BatchNormalization operator. This op uses - the population size (N) for calculating variance, and not the sample - size N-1. - - Notes - ===== - Signature: ``ai.onnx@15::BatchNormalization``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _BatchNormalization( - _BatchNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - momentum=AttrFloat32(momentum, name="momentum"), - training_mode=AttrInt64(training_mode, name="training_mode"), - ), - _BatchNormalization.Inputs( - X=unwrap_vars(X), - scale=unwrap_vars(scale), - B=unwrap_vars(B), - input_mean=unwrap_vars(input_mean), - input_var=unwrap_vars(input_var), - ), - ) - .get_output_vars( - X=get_value(X), - scale=get_value(scale), - B=get_value(B), - input_mean=get_value(input_mean), - input_var=get_value(input_var), - ) - ._unpack_to_any() - ) +A NegativeLogLikelihoodLoss operator computes (weighted) negative log +likelihood loss. Its "input" tensor has the shape of (N, C, d1, d2, ..., +dk) where k >= 0. The "input" tensor contains log-probabilities for +input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). The +operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). +It encodes class labels (one of C classes) or it may contain a special +value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x +dk samples. The loss value for input[n, :, d_1, d_2,...d_k] being +classified as class c = target[n][d_1][d_2]...[d_k] is computed as: + +:: + + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. + +When an optional "weight" is provided, the sample loss is calculated as: + +:: + + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. + +loss is zero for the case when target-value equals ignore_index. + +:: + + loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index + +If "reduction" attribute is set to "none", the operator's output will be +the above loss with shape (N, d1, d2, ..., dk). If "reduction" attribute +is set to "mean" (the default attribute value), the output loss is +(weight) averaged: + +:: + + mean(loss), if "weight" is not provided, + +or if weight is provided, + +:: + + sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. + +If "reduction" attribute is set to "sum", the output is a scalar: +``sum(loss)``. + +See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. + +Example 1: + +:: + + // negative log likelihood loss, "none" reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] + + // print(loss) + // [[-3. -2.] + // [-0. -2.]] + +Example 2: + +:: + + // weighted negative log likelihood loss, sum reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + + loss = np.sum(loss) + // print(loss) + // -1.1 + +Example 3: + +:: + + // weighted negative log likelihood loss, mean reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + weight_total = 0 + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + weight_total = weight_total + weight[c] + + loss = np.sum(loss) / weight_total + // print(loss) + // -1.57 + +Parameters +========== +input + Type T. + Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk). +target + Type Tind. + Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value + shall be in range of [0, C). If ignore_index is specified, it may have a + value outside [0, C) and the target values should either be in the range + [0, C) or have the value ignore_index. +weight + Type T. + Optional rescaling weight tensor. If given, it has to be a tensor of + size C. Otherwise, it is treated as if having all ones. +ignore_index + Attribute. + Specifies a target value that is ignored and does not contribute to the + input gradient. It's an optional value. +reduction + Attribute. + Type of reduction to apply to loss: none, sum, mean (default). 'none': + the output is the loss for each sample. 'sum': the output will be + summed. 'mean': the sum of the output will be divided by the sum of + applied weights. + +Returns +======= +loss : Var + Type T. + The negative log likelihood loss + +Notes +===== +Signature: ``ai.onnx@13::NegativeLogLikelihoodLoss``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return _NegativeLogLikelihoodLoss( + _NegativeLogLikelihoodLoss.Attributes( + ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), + reduction=AttrString(reduction, name="reduction"), + ), _NegativeLogLikelihoodLoss.Inputs( + input=unwrap_vars(input), target=unwrap_vars(target), weight=unwrap_vars(weight), ), ).get_output_vars( + input=get_value(input), target=get_value(target), weight=get_value(weight), ).loss + + +def non_max_suppression(boxes: Var, scores: Var, max_output_boxes_per_class: Optional[Var] = None, iou_threshold: Optional[Var] = None, score_threshold: Optional[Var] = None, *, center_point_box: int = 0, ) -> Var: + r""" +Filter out boxes that have high intersection-over-union (IOU) overlap +with previously selected boxes. Bounding boxes with score less than +score_threshold are removed. Bounding box format is indicated by +attribute center_point_box. Note that this algorithm is agnostic to +where the origin is in the coordinate system and more generally is +invariant to orthogonal transformations and translations of the +coordinate system; thus translating or reflections of the coordinate +system result in the same boxes being selected by the algorithm. The +selected_indices output is a set of integers indexing into the input +collection of bounding boxes representing the selected boxes. The +bounding box coordinates corresponding to the selected indices can then +be obtained using the Gather or GatherND operation. + +Parameters +========== +boxes + Type tensor(float). + An input tensor with shape [num_batches, spatial_dimension, 4]. The + single box data format is indicated by center_point_box. +scores + Type tensor(float). + An input tensor with shape [num_batches, num_classes, spatial_dimension] +max_output_boxes_per_class + Type tensor(int64). + Integer representing the maximum number of boxes to be selected per + batch per class. It is a scalar. Default to 0, which means no output. +iou_threshold + Type tensor(float). + Float representing the threshold for deciding whether boxes overlap too + much with respect to IOU. It is scalar. Value range [0, 1]. Default to + 0. +score_threshold + Type tensor(float). + Float representing the threshold for deciding when to remove boxes based + on score. It is a scalar. +center_point_box + Attribute. + Integer indicate the format of the box data. The default is 0. 0 - the + box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are + the coordinates of any diagonal pair of box corners and the coordinates + can be provided as normalized (i.e., lying in the interval [0, 1]) or + absolute. Mostly used for TF models. 1 - the box data is supplied as + [x_center, y_center, width, height]. Mostly used for Pytorch models. + +Returns +======= +selected_indices : Var + Type tensor(int64). + selected indices from the boxes tensor. [num_selected_indices, 3], the + selected index format is [batch_index, class_index, box_index]. + +Notes +===== +Signature: ``ai.onnx@11::NonMaxSuppression``. + + """ + return _NonMaxSuppression( + _NonMaxSuppression.Attributes( + center_point_box=AttrInt64(center_point_box, name="center_point_box"), + ), _NonMaxSuppression.Inputs( + boxes=unwrap_vars(boxes), scores=unwrap_vars(scores), max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), iou_threshold=unwrap_vars(iou_threshold), score_threshold=unwrap_vars(score_threshold), ), ).get_output_vars( + boxes=get_value(boxes), scores=get_value(scores), max_output_boxes_per_class=get_value(max_output_boxes_per_class), iou_threshold=get_value(iou_threshold), score_threshold=get_value(score_threshold), ).selected_indices + + +def non_zero(X: Var, ) -> Var: + r""" +Returns the indices of the elements that are non-zero (in row-major +order - by dimension). NonZero behaves similar to numpy.nonzero: +https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html, +but for scalar input, NonZero produces output shape (0, N) instead of +(1, N), which is different from Numpy's behavior. + +Parameters +========== +X + Type T. + input +Returns +======= +Y : Var + Type tensor(int64). + output + +Notes +===== +Signature: ``ai.onnx@13::NonZero``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _NonZero( + _NonZero.Attributes( + ), _NonZero.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def not_(X: Var, ) -> Var: + r""" +Returns the negation of the input tensor element-wise. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@1::Not``. + +Type constraints: + - T: `tensor(bool)` + """ + return _Not( + _Not.Attributes( + ), _Not.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def one_hot(indices: Var, depth: Var, values: Var, *, axis: int = -1, ) -> Var: + r""" +Produces a one-hot tensor based on inputs. The locations represented by +the index values in the 'indices' input tensor will have 'on_value' and +the other locations will have 'off_value' in the output tensor, where +'on_value' and 'off_value' are specified as part of required input +argument 'values', which is a two-element tensor of format [off_value, +on_value]. The rank of the output tensor will be one greater than the +rank of the input tensor. The additional dimension is for one-hot +representation. The additional dimension will be inserted at the +position specified by 'axis'. If 'axis' is not specified then then +additional dimension will be inserted as the innermost dimension, i.e. +axis=-1. The size of the additional dimension is specified by required +scalar input 'depth'. The type of the output tensor is the same as the +type of the 'values' input. Any entries in the 'indices' input tensor +with values outside the range [-depth, depth-1] will result in one-hot +representation with all 'off_value' values in the output tensor. + +:: + + when axis = 0: + output[input[i, j, k], i, j, k] = 1 for all i, j, k and 0 otherwise. + + when axis = -1: + output[i, j, k, input[i, j, k]] = 1 for all i, j, k and 0 otherwise. + +Parameters +========== +indices + Type T1. + Input tensor containing indices. Any entries in the 'indices' input + tensor with values outside the range [-depth, depth-1] will result in + one-hot representation with all 'off_value' values in the output + tensor.In case 'indices' is of non-integer type, the values will be + casted to int64 before use. +depth + Type T2. + Scalar or Rank 1 tensor containing exactly one element, specifying the + number of classes in one-hot tensor. This is also the size of the + one-hot dimension (specified by 'axis' attribute) added on in the output + tensor. The values in the 'indices' input tensor are expected to be in + the range [-depth, depth-1]. In case 'depth' is of non-integer type, it + will be casted to int64 before use. +values + Type T3. + Rank 1 tensor containing exactly two elements, in the format [off_value, + on_value], where 'on_value' is the value used for filling locations + specified in 'indices' input tensor, and 'off_value' is the value used + for filling locations other than those specified in 'indices' input + tensor. +axis + Attribute. + (Optional) Axis along which one-hot representation in added. Default: + axis=-1. axis=-1 means that the additional dimension will be inserted as + the innermost/last dimension in the output tensor. Negative value means + counting dimensions from the back. Accepted range is [-r-1, r] where r = + rank(indices). + +Returns +======= +output : Var + Type T3. + Tensor of rank one greater than input tensor 'indices', i.e. + rank(output) = rank(indices) + 1. The data type for the elements of the + output tensor is the same as the type of input 'values' is used. + +Notes +===== +Signature: ``ai.onnx@11::OneHot``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T3: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _OneHot( + _OneHot.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _OneHot.Inputs( + indices=unwrap_vars(indices), depth=unwrap_vars(depth), values=unwrap_vars(values), ), ).get_output_vars( + indices=get_value(indices), depth=get_value(depth), values=get_value(values), ).output + + +def optional(input: Optional[Var] = None, *, type: Optional[Type] = None, ) -> Var: + r""" +Constructs an optional-type value containing either an empty optional of +a certain type specified by the attribute, or a non-empty value +containing the input element. + +Parameters +========== +input + Type V. + The input element. +type + Attribute. + Type of the element in the optional output + +Returns +======= +output : Var + Type O. + The optional output enclosing the input element. + +Notes +===== +Signature: ``ai.onnx@15::Optional``. + +Type constraints: + - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` + """ + return _Optional( + _Optional.Attributes( + type=AttrType.maybe(type, name="type"), + ), _Optional.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def optional_get_element(input: Var, ) -> Var: + r""" +Outputs the element in the optional-type input. It is an error if the +input value does not have an element and the behavior is undefined in +this case. + +Parameters +========== +input + Type O. + The optional input. + +Returns +======= +output : Var + Type V. + Output element in the optional input. + +Notes +===== +Signature: ``ai.onnx@15::OptionalGetElement``. + +Type constraints: + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` + - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _OptionalGetElement( + _OptionalGetElement.Attributes( + ), _OptionalGetElement.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def optional_has_element(input: Var, ) -> Var: + r""" +Returns true if the optional-type input contains an element. If it is an +empty optional-type, this op returns false. + +Parameters +========== +input + Type O. + The optional input. + +Returns +======= +output : Var + Type B. + A scalar boolean tensor. If true, it indicates that optional-type input + contains an element. Otherwise, it is empty. + +Notes +===== +Signature: ``ai.onnx@15::OptionalHasElement``. + +Type constraints: + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` + - B: `tensor(bool)` + """ + return _OptionalHasElement( + _OptionalHasElement.Attributes( + ), _OptionalHasElement.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def or_(A: Var, B: Var, ) -> Var: + r""" +Returns the tensor resulted from performing the ``or`` logical operation +elementwise on the input tensors ``A`` and ``B`` (with Numpy-style +broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. -def bernoulli( - input: Var, - *, - dtype: Optional[npt.DTypeLike] = None, - seed: Optional[float] = None, -) -> Var: - r""" - Draws binary random numbers (0 or 1) from a Bernoulli distribution. The - input tensor should be a tensor containing probabilities p (a value in - the range [0,1]) to be used for drawing the binary random number, where - an output of 1 is produced with probability p and an output of 0 is - produced with probability (1-p). +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. - This operator is non-deterministic and may not produce the same values - in different implementations (even if a seed is specified). +Returns +======= +C : Var + Type T1. + Result tensor. - Parameters - ========== - input - Type T1. - All values in input have to be in the range:[0, 1]. - dtype - Attribute. - The data type for the elements of the output tensor. if not specified, - we will use the data type of the input tensor. - seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - - Returns - ======= - output : Var - Type T2. - The returned output tensor only has values 0 or 1, same shape as input - tensor. - - Notes - ===== - Signature: ``ai.onnx@15::Bernoulli``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Notes +===== +Signature: ``ai.onnx@7::Or``. + +Type constraints: + - T: `tensor(bool)` + - T1: `tensor(bool)` """ - return ( - _Bernoulli( - _Bernoulli.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), - _Bernoulli.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Or( + _Or.Attributes( + ), _Or.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C -def bit_shift( - X: Var, - Y: Var, - *, - direction: str, -) -> Var: +def prelu(X: Var, slope: Var, ) -> Var: r""" - Bitwise shift operator performs element-wise operation. For each input - element, if the attribute "direction" is "RIGHT", this operator moves - its binary representation toward the right side so that the input value - is effectively decreased. If the attribute "direction" is "LEFT", bits - of binary representation moves toward the left side, which results the - increase of its actual value. The input X is the tensor to be shifted - and another input Y specifies the amounts of shifting. For example, if - "direction" is "Right", X is [1, 4], and S is [1, 1], the corresponding - output Z would be [0, 2]. If "direction" is "LEFT" with X=[1, 2] and - S=[1, 2], the corresponding output Y would be [2, 8]. - - Because this operator supports Numpy-style broadcasting, X's and Y's - shapes are not necessarily identical. This operator supports - **multidirectional (i.e., Numpy-style) broadcasting**; for more details - please check `the - doc `__. - - Parameters - ========== - X - Type T. - First operand, input to be shifted. - Y - Type T. - Second operand, amounts of shift. - direction - Attribute. - Direction of moving bits. It can be either "RIGHT" (for right shift) or - "LEFT" (for left shift). - - Returns - ======= - Z : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@11::BitShift``. - - Type constraints: - - T: `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _BitShift( - _BitShift.Attributes( - direction=AttrString(direction, name="direction"), - ), - _BitShift.Inputs( - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ) - .get_output_vars( - X=get_value(X), - Y=get_value(Y), - ) - .Z - ) +PRelu takes input data (Tensor) and slope tensor as input, and +produces one output data (Tensor) where the function +``f(x) = slope * x for x < 0``, ``f(x) = x for x >= 0``., is applied to +the data tensor elementwise. This operator supports **unidirectional +broadcasting** (tensor slope should be unidirectional broadcastable to +input tensor X); for more details please check `the +doc `__. +Parameters +========== +X + Type T. + Input tensor +slope + Type T. + Slope tensor. The shape of slope can be smaller than first input X; if + so, its shape must be unidirectional broadcastable to X + +Returns +======= +Y : Var + Type T. + Output tensor (same size as X) -def blackman_window( - size: Var, - *, - output_datatype: int = 1, - periodic: int = 1, -) -> Var: - r""" - Generates a Blackman window as described in the paper - https://ieeexplore.ieee.org/document/1455106. - - Parameters - ========== - size - Type T1. - A scalar value indicating the length of the window. - output_datatype - Attribute. - The data type of the output tensor. Strictly must be one of the values - from DataType enum in TensorProto whose values correspond to T2. The - default value is 1 = FLOAT. - periodic - Attribute. - If 1, returns a window to be used as periodic function. If 0, return a - symmetric window. When 'periodic' is specified, hann computes a window - of length size + 1 and returns the first size points. The default value - is 1. - - Returns - ======= - output : Var - Type T2. - A Blackman window with length: size. The output has the shape: [size]. - - Notes - ===== - Signature: ``ai.onnx@17::BlackmanWindow``. - - Type constraints: - - T1: `tensor(int32)`, `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Notes +===== +Signature: ``ai.onnx@16::PRelu``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _PRelu( + _PRelu.Attributes( + ), _PRelu.Inputs( + X=unwrap_vars(X), slope=unwrap_vars(slope), ), ).get_output_vars( + X=get_value(X), slope=get_value(slope), ).Y + + +def pad(data: Var, pads: Var, constant_value: Optional[Var] = None, *, mode: str = "constant", ) -> Var: + r""" +Given a tensor containing the data to be padded (``data``), a tensor +containing the number of start and end pad values for axis (``pads``), +(optionally) a ``mode``, and (optionally) ``constant_value``, a padded +tensor (``output``) is generated. + +The three supported ``modes`` are (similar to corresponding modes +supported by ``numpy.pad``): + +1) ``constant``\ (default) - pads with a given constant value as + specified by ``constant_value`` (which defaults to 0, empty string, + or False) + +2) ``reflect`` - pads with the reflection of the vector mirrored on the + first and last values of the vector along each axis + +3) ``edge`` - pads with the edge values of array + +Example 1 (``constant`` mode): Insert 0 pads to the beginning of the +second dimension. + +data = [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], ] + +pads = [0, 2, 0, 0] + +mode = 'constant' + +constant_value = 0.0 + +output = [ [0.0, 0.0, 1.0, 1.2], [0.0, 0.0, 2.3, 3.4], [0.0, 0.0, 4.5, +5.7], ] + +Example 2 (``reflect`` mode): data = [ [1.0, 1.2], [2.3, 3.4], [4.5, +5.7], ] + +pads = [0, 2, 0, 0] + +mode = 'reflect' + +output = [ [1.0, 1.2, 1.0, 1.2], [2.3, 3.4, 2.3, 3.4], [4.5, 5.7, 4.5, +5.7], ] + +Example 3 (``edge`` mode): data = [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], +] + +pads = [0, 2, 0, 0] + +mode = 'edge' + +output = [ [1.0, 1.0, 1.0, 1.2], [2.3, 2.3, 2.3, 3.4], [4.5, 4.5, 4.5, +5.7], ] + +Parameters +========== +data + Type T. + Input tensor. +pads + Type tensor(int64). + Tensor of integers indicating the number of padding elements to add or + remove (if negative) at the beginning and end of each axis. For 2D input + tensor, it is the number of pixels. ``pads`` should be a 1D tensor of + shape [2 \* input_rank]. ``pads`` format should be: [x1_begin, + x2_begin,...,x1_end, x2_end,...], where xi_begin is the number of pad + values added at the beginning of axis ``i`` and xi_end, the number of + pad values added at the end of axis ``i``. +constant_value + Type T. + (Optional) A scalar value to be used if the mode chosen is ``constant`` + (by default it is 0, empty string or False). +mode + Attribute. + Supported modes: ``constant``\ (default), ``reflect``, ``edge`` + +Returns +======= +output : Var + Type T. + Tensor after padding. + +Notes +===== +Signature: ``ai.onnx@13::Pad``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), _Pad.Inputs( + data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), ), ).get_output_vars( + data=get_value(data), pads=get_value(pads), constant_value=get_value(constant_value), ).output + + +def pow(X: Var, Y: Var, ) -> Var: + r""" +Pow takes input data (Tensor) and exponent Tensor, and produces one +output data (Tensor) where the function ``f(x) = x^exponent``, is +applied to the data tensor elementwise. This operator supports +**multidirectional (i.e., Numpy-style) broadcasting**; for more details +please check `the +doc `__. + +Parameters +========== +X + Type T. + First operand, base of the exponent. +Y + Type T1. + Second operand, power of the exponent. + +Returns +======= +Z : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@15::Pow``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)` + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Pow( + _Pow.Attributes( + ), _Pow.Inputs( + X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( + X=get_value(X), Y=get_value(Y), ).Z + + +def qlinear_conv(x: Var, x_scale: Var, x_zero_point: Var, w: Var, w_scale: Var, w_zero_point: Var, y_scale: Var, y_zero_point: Var, B: Optional[Var] = None, *, auto_pad: str = "NOTSET", dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + r""" +The convolution operator consumes a quantized input tensor, its scale +and zero point, a quantized filter, its scale and zero point, and +output's scale and zero point, and computes the quantized output. Each +scale and zero-point pair must have same shape. It means they must be +either scalars (per tensor) or 1-D tensors (per output channel). Each +input or output and its related zero point must have same type. When +bias is present it must be quantized using scale = input scale \* weight +scale and zero point as 0. + +Parameters +========== +x + Type T1. + Input data tensor from previous layer; has size (N x C x H x W), where N + is the batch size, C is the number of channels, and H and W are the + height and width. Note that this is for the 2D image. Otherwise the size + is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in + effect, the operation expects input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. +x_scale + Type tensor(float). + Scale tensor for input 'x'. It's a scalar, which means a + per-tensor/layer quantization. +x_zero_point + Type T1. + Zero point tensor for input 'x'. It's a scalar, which means a + per-tensor/layer quantization. +w + Type T2. + The weight tensor that will be used in the convolutions; has size (M x + C/group x kH x kW), where C is the number of channels, and kH and kW are + the height and width of the kernel, and M is the number of feature maps. + For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x + k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. + Optionally, if dimension denotation is in effect, the operation expects + the weight tensor to arrive with the dimension denotation of + [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL + ...]. X.shape[1] == (W.shape[1] \* group) == C (assuming zero based + indices for the shape array). Or in other words FILTER_IN_CHANNEL should + be equal to DATA_CHANNEL. +w_scale + Type tensor(float). + Scale tensor for input 'w'. It could be a scalar or a 1-D tensor, which + means a per-tensor/layer or per output channel quantization. If it's a + 1-D tensor, its number of elements should be equal to the number of + output channels (M). +w_zero_point + Type T2. + Zero point tensor for input 'w'. It could be a scalar or a 1-D tensor, + which means a per-tensor/layer or per output channel quantization. If + it's a 1-D tensor, its number of elements should be equal to the number + of output channels (M). +y_scale + Type tensor(float). + Scale tensor for output 'y'. It's a scalar, which means a + per-tensor/layer quantization. +y_zero_point + Type T3. + Zero point tensor for output 'y'. It's a scalar, which means a + per-tensor/layer quantization. +B + Type T4. + Optional 1D bias to be added to the convolution, has size of M. Bias + must be quantized using scale = x_scale \* w_scale and zero_point = 0 +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. +dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults to 1 along each spatial axis. +group + Attribute. + number of groups input channels and output channels are divided into. + default is 1. +kernel_shape + Attribute. + The shape of the convolution kernel. If not present, should be inferred + from input 'w'. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0.The value represent the number + of pixels added to the beginning and end part of the corresponding + axis.\ ``pads`` format should be as follow [x1_begin, x2_begin...x1_end, + x2_end,...], where xi_begin the number ofpixels added at the beginning + of axis ``i`` and xi_end, the number of pixels added at the end of axis + ``i``.This attribute cannot be used simultaneously with auto_pad + attribute. If not present, the padding defaultsto 0 along start and end + of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + +Returns +======= +y : Var + Type T3. + Output data tensor that contains the result of the convolution. The + output dimensions are functions of the kernel size, stride size, and pad + lengths. + +Notes +===== +Signature: ``ai.onnx@10::QLinearConv``. + +Type constraints: + - T1: `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(int8)`, `tensor(uint8)` + - T4: `tensor(int32)` + """ + return _QLinearConv( + _QLinearConv.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _QLinearConv.Inputs( + x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), w=unwrap_vars(w), w_scale=unwrap_vars(w_scale), w_zero_point=unwrap_vars(w_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), B=unwrap_vars(B), ), ).get_output_vars( + x=get_value(x), x_scale=get_value(x_scale), x_zero_point=get_value(x_zero_point), w=get_value(w), w_scale=get_value(w_scale), w_zero_point=get_value(w_zero_point), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), B=get_value(B), ).y + + +def qlinear_matmul(a: Var, a_scale: Var, a_zero_point: Var, b: Var, b_scale: Var, b_zero_point: Var, y_scale: Var, y_zero_point: Var, ) -> Var: + r""" +Matrix product that behaves like numpy.matmul: +https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. +It consumes two quantized input tensors, their scales and zero points, +scale and zero point of output, and computes the quantized output. The +quantization formula is y = saturate((x / y_scale) + y_zero_point). For +(x / y_scale), it is rounding to nearest ties to even. Refer to +https://en.wikipedia.org/wiki/Rounding for details. Scale and zero point +must have same shape. They must be either scalar (per tensor) or N-D +tensor (per row for 'a' and per column for 'b'). Scalar refers to per +tensor quantization whereas N-D refers to per row or per column +quantization. If the input is 2D of shape [M, K] then zero point and +scale tensor may be an M element vector [v_1, v_2, ..., v_M] for per row +quantization and K element vector of shape [v_1, v_2, ..., v_K] for per +column quantization. If the input is N-D tensor with shape [D1, D2, M, +K] then zero point and scale tensor may have shape [D1, D2, M, 1] for +per row quantization and shape [D1, D2, 1, K] for per column +quantization. Production must never overflow, and accumulation may +overflow if and only if in 32 bits. + +Parameters +========== +a + Type T1. + N-dimensional quantized matrix a +a_scale + Type tensor(float). + scale of quantized input a +a_zero_point + Type T1. + zero point of quantized input a +b + Type T2. + N-dimensional quantized matrix b +b_scale + Type tensor(float). + scale of quantized input b +b_zero_point + Type T2. + zero point of quantized input b +y_scale + Type tensor(float). + scale of quantized output y +y_zero_point + Type T3. + zero point of quantized output y + +Returns +======= +y : Var + Type T3. + Quantized matrix multiply results from a \* b + +Notes +===== +Signature: ``ai.onnx@10::QLinearMatMul``. + +Type constraints: + - T1: `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(int8)`, `tensor(uint8)` + """ + return _QLinearMatMul( + _QLinearMatMul.Attributes( + ), _QLinearMatMul.Inputs( + a=unwrap_vars(a), a_scale=unwrap_vars(a_scale), a_zero_point=unwrap_vars(a_zero_point), b=unwrap_vars(b), b_scale=unwrap_vars(b_scale), b_zero_point=unwrap_vars(b_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( + a=get_value(a), a_scale=get_value(a_scale), a_zero_point=get_value(a_zero_point), b=get_value(b), b_scale=get_value(b_scale), b_zero_point=get_value(b_zero_point), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y + + +def quantize_linear(x: Var, y_scale: Var, y_zero_point: Optional[Var] = None, *, axis: int = 1, ) -> Var: + r""" +The linear quantization operator. It consumes a high precision tensor, a +scale, and a zero point to compute the low precision / quantized tensor. +The scale factor and zero point must have same shape, and can be either +a scalar for per-tensor / per layer quantization, or a 1-D tensor for +per-axis quantization. The quantization formula is y = saturate ((x / +y_scale) + y_zero_point). For saturation, it saturates to [0, 255] if +it's uint8, or [-128, 127] if it's int8. For (x / y_scale), it's +rounding to the nearest even. Refer to +https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and +'y' must have same type. + +Parameters +========== +x + Type T1. + N-D full precision Input tensor to be quantized. +y_scale + Type tensor(float). + Scale for doing quantization to get 'y'. It can be a scalar, which means + per-tensor/layer quantization, or a 1-D Tensor for per-axis + quantization. +y_zero_point + Type T2. + Zero point for doing quantization to get 'y'. Shape must match y_scale. + Default is uint8 with zero point of 0 if it's not specified. +axis + Attribute. + (Optional) The axis of the quantization dimension of the input tensor. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + +Returns +======= +y : Var + Type T2. + N-D quantized output tensor. It has same shape as input 'x'. + +Notes +===== +Signature: ``ai.onnx@13::QuantizeLinear``. + +Type constraints: + - T1: `tensor(float)`, `tensor(int32)` + - T2: `tensor(int8)`, `tensor(uint8)` + """ + return _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _QuantizeLinear.Inputs( + x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( + x=get_value(x), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y + + +def rnn(X: Var, W: Var, R: Var, B: Optional[Var] = None, sequence_lens: Optional[Var] = None, initial_h: Optional[Var] = None, *, activation_alpha: Optional[Iterable[float]] = None, activation_beta: Optional[Iterable[float]] = None, activations: Iterable[str] = ('Tanh', 'Tanh'), clip: Optional[float] = None, direction: str = "forward", hidden_size: Optional[int] = None, layout: int = 0, ) -> tuple[Var, Var]: + r""" +Computes an one-layer simple RNN. This operator is usually supported via +some custom implementation such as CuDNN. + +Notations: + +- ``X`` - input tensor +- ``i`` - input gate +- ``t`` - time step (t-1 means previous time step) +- ``Wi`` - W parameter weight matrix for input gate +- ``Ri`` - R recurrence weight matrix for input gate +- ``Wbi`` - W parameter bias vector for input gate +- ``Rbi`` - R parameter bias vector for input gate +- ``WBi`` - W parameter weight matrix for backward input gate +- ``RBi`` - R recurrence weight matrix for backward input gate +- ``WBbi`` - WR bias vectors for backward input gate +- ``RBbi`` - RR bias vectors for backward input gate +- ``H`` - Hidden state +- ``num_directions`` - 2 if direction == bidirectional else 1 + +Activation functions: + +- Relu(x) - max(0, x) +- Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) +- Sigmoid(x) - 1/(1 + e^{-x}) + +NOTE: Below are optional + +- Affine(x) - alpha*x + beta +- LeakyRelu(x) - x if x >= 0 else alpha \* x +- ThresholdedRelu(x) - x if x >= alpha else 0 +- ScaledTanh(x) - alpha\ *Tanh(beta*\ x) +- HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) +- Elu(x) - x if x >= 0 else alpha*(e^x - 1) +- Softsign(x) - x/(1 + \|x\|) +- Softplus(x) - log(1 + e^x) + +Equations (Default: f=Tanh): + +- Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has + **optional** inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. + +Parameters +========== +X + Type T. + The input sequences packed (and potentially padded) into one 3-D tensor + with the shape of ``[seq_length, batch_size, input_size]``. +W + Type T. + The weight tensor for input gate. Concatenation of ``Wi`` and ``WBi`` + (if bidirectional). The tensor has shape + ``[num_directions, hidden_size, input_size]``. +R + Type T. + The recurrence weight tensor. Concatenation of ``Ri`` and ``RBi`` (if + bidirectional). The tensor has shape + ``[num_directions, hidden_size, hidden_size]``. +B + Type T. + The bias tensor for input gate. Concatenation of ``[Wbi, Rbi]`` and + ``[WBbi, RBbi]`` (if bidirectional). The tensor has shape + ``[num_directions, 2*hidden_size]``. Optional: If not specified - + assumed to be 0. +sequence_lens + Type T1. + Optional tensor specifying lengths of the sequences in a batch. If not + specified - assumed all sequences in the batch to have length + ``seq_length``. It has shape ``[batch_size]``. +initial_h + Type T. + Optional initial value of the hidden. If not specified - assumed to be + 0. It has shape ``[num_directions, batch_size, hidden_size]``. +activation_alpha + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX + operators.For example with LeakyRelu, the default alpha is 0.01. +activation_beta + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX operators. +activations + Attribute. + One (or two if bidirectional) activation function for input gate. The + activation function must be one of the activation functions specified + above. Optional: Default ``Tanh`` if not specified. +clip + Attribute. + Cell clip threshold. Clipping bounds the elements of a tensor in the + range of [-threshold, +threshold] and is applied to the input of + activations. No clip if not specified. +direction + Attribute. + Specify if the RNN is forward, reverse, or bidirectional. Must be one of + forward (default), reverse, or bidirectional. +hidden_size + Attribute. + Number of neurons in the hidden layer +layout + Attribute. + The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the + following shapes are expected: X.shape = [seq_length, batch_size, + input_size], Y.shape = [seq_length, num_directions, batch_size, + hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, + hidden_size]. If 1, the following shapes are expected: X.shape = + [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, + num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, + num_directions, hidden_size]. + +Returns +======= +Y : Var + Type T. + A tensor that concats all the intermediate output values of the hidden. + It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. +Y_h : Var + Type T. + The last output value of the hidden. It has shape + ``[num_directions, batch_size, hidden_size]``. + +Notes +===== +Signature: ``ai.onnx@14::RNN``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(int32)` + """ + return _RNN( + _RNN.Attributes( + activation_alpha=AttrFloat32s.maybe(activation_alpha, name="activation_alpha"), + activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), + activations=AttrStrings(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + layout=AttrInt64(layout, name="layout"), + ), _RNN.Inputs( + X=unwrap_vars(X), W=unwrap_vars(W), R=unwrap_vars(R), B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), ), ).get_output_vars( + X=get_value(X), W=get_value(W), R=get_value(R), B=get_value(B), sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), )._unpack_to_any() + + +def random_normal(*, dtype: npt.DTypeLike = np.float32, mean: float = 0.0, scale: float = 1.0, seed: Optional[float] = None, shape: Iterable[int], ) -> Var: + r""" +Generate a tensor with random values drawn from a normal distribution. +The shape of the tensor is specified by the ``shape`` argument and the +parameter of the normal distribution specified by ``mean`` and +``scale``. + +The data type is specified by the 'dtype' argument. The 'dtype' argument +must be one of the data types specified in the 'DataType' enum field in +the TensorProto message. + +Parameters +========== +dtype + Attribute. + The data type for the elements of the output tensor. Default is + TensorProto::FLOAT. +mean + Attribute. + The mean of the normal distribution. +scale + Attribute. + The standard deviation of the normal distribution. +seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. +shape + Attribute. + The shape of the output tensor. + +Returns +======= +output : Var + Type T. + Output tensor of random values drawn from normal distribution + +Notes +===== +Signature: ``ai.onnx@1::RandomNormal``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _RandomNormal( + _RandomNormal.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + mean=AttrFloat32(mean, name="mean"), + scale=AttrFloat32(scale, name="scale"), + seed=AttrFloat32.maybe(seed, name="seed"), + shape=AttrInt64s(shape, name="shape"), + ), _RandomNormal.Inputs( + ), ).get_output_vars( + ).output + + +def random_normal_like(input: Var, *, dtype: Optional[npt.DTypeLike] = None, mean: float = 0.0, scale: float = 1.0, seed: Optional[float] = None, ) -> Var: + r""" +Generate a tensor with random values drawn from a normal distribution. +The shape of the output tensor is copied from the shape of the input +tensor, and the parameters of the normal distribution are specified by +``mean`` and ``scale``. + +The data type is specified by the 'dtype' argument, or copied from the +input tensor if not provided. The 'dtype' argument must be one of the +data types specified in the 'DataType' enum field in the TensorProto +message, and be valid as an output type. + +Parameters +========== +input + Type T1. + Input tensor to copy shape and optionally type information from. +dtype + Attribute. + (Optional) The data type for the elements of the output tensor, if not + specified, we will use the data type of the input tensor. +mean + Attribute. + The mean of the normal distribution. +scale + Attribute. + The standard deviation of the normal distribution. +seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + +Returns +======= +output : Var + Type T2. + Output tensor of random values drawn from normal distribution + +Notes +===== +Signature: ``ai.onnx@1::RandomNormalLike``. + +Type constraints: + - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _RandomNormalLike( + _RandomNormalLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + mean=AttrFloat32(mean, name="mean"), + scale=AttrFloat32(scale, name="scale"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), _RandomNormalLike.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def random_uniform(*, dtype: npt.DTypeLike = np.float32, high: float = 1.0, low: float = 0.0, seed: Optional[float] = None, shape: Iterable[int], ) -> Var: + r""" +Generate a tensor with random values drawn from a uniform distribution. +The shape of the tensor is specified by the ``shape`` argument and the +range by ``low`` and ``high``. + +The data type is specified by the 'dtype' argument. The 'dtype' argument +must be one of the data types specified in the 'DataType' enum field in +the TensorProto message. + +Parameters +========== +dtype + Attribute. + The data type for the elements of the output tensor. If not specified, + default is TensorProto::FLOAT. +high + Attribute. + Upper boundary of the output values. +low + Attribute. + Lower boundary of the output values. +seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. +shape + Attribute. + The shape of the output tensor. + +Returns +======= +output : Var + Type T. + Output tensor of random values drawn from uniform distribution + +Notes +===== +Signature: ``ai.onnx@1::RandomUniform``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _RandomUniform( + _RandomUniform.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + high=AttrFloat32(high, name="high"), + low=AttrFloat32(low, name="low"), + seed=AttrFloat32.maybe(seed, name="seed"), + shape=AttrInt64s(shape, name="shape"), + ), _RandomUniform.Inputs( + ), ).get_output_vars( + ).output + + +def random_uniform_like(input: Var, *, dtype: Optional[npt.DTypeLike] = None, high: float = 1.0, low: float = 0.0, seed: Optional[float] = None, ) -> Var: + r""" +Generate a tensor with random values drawn from a uniform distribution. +The shape of the output tensor is copied from the shape of the input +tensor, and the parameters of the uniform distribution are specified by +``low`` and ``high``. + +The data type is specified by the 'dtype' argument, or copied from the +input tensor if not provided. The 'dtype' argument must be one of the +data types specified in the 'DataType' enum field in the TensorProto +message and be valid as an output type. + +Parameters +========== +input + Type T1. + Input tensor to copy shape and optionally type information from. +dtype + Attribute. + (Optional) The data type for the elements of the output tensor, if not + specified, we will use the data type of the input tensor. +high + Attribute. + Upper boundary of the output values. +low + Attribute. + Lower boundary of the output values. +seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + +Returns +======= +output : Var + Type T2. + Output tensor of random values drawn from uniform distribution + +Notes +===== +Signature: ``ai.onnx@1::RandomUniformLike``. + +Type constraints: + - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _RandomUniformLike( + _RandomUniformLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + high=AttrFloat32(high, name="high"), + low=AttrFloat32(low, name="low"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), _RandomUniformLike.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def range(start: Var, limit: Var, delta: Var, ) -> Var: + r""" +Generate a tensor containing a sequence of numbers that begin at +``start`` and extends by increments of ``delta`` up to ``limit`` +(exclusive). + +The number of elements in the output of range is computed as below: + +:: + + number_of_elements = max( ceil( (limit - start) / delta ) , 0 ) + +The pseudocode determining the contents of the output is shown below: + +:: + + for(int i=0; i Var: + r""" +Reciprocal takes one input data (Tensor) and produces one output data +(Tensor) where the reciprocal is, y = 1/x, is applied to the tensor +elementwise. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@13::Reciprocal``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Reciprocal( + _Reciprocal.Attributes( + ), _Reciprocal.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def reduce_l1(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the L1 norm of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields 0. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceL1``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _ReduceL1( + _ReduceL1.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceL1.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def reduce_l2(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the L2 norm of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields 0. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceL2``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _ReduceL2( + _ReduceL2.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceL2.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def reduce_log_sum(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the log sum of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields minus infinity (if +supported by the datatype) or undefined otherwise. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceLogSum``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _ReduceLogSum( + _ReduceLogSum.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceLogSum.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def reduce_log_sum_exp(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the log sum exponent of the input tensor's elements along the +provided axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields minus infinity (if +supported by the datatype) or undefined otherwise. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceLogSumExp``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _ReduceLogSumExp( + _ReduceLogSumExp.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceLogSumExp.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def reduce_max(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the max of the input tensor's elements along the provided axes. +The resulting tensor has the same rank as the input if ``keepdims`` +equals 1. If ``keepdims`` equals 0, then the resulting tensor has the +reduced dimension pruned. Input tensors of rank zero are valid. +Reduction over an empty set of values yields minus infinity (if +supported by the datatype) or the minimum value of the data type +otherwise. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceMax``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ReduceMax( + _ReduceMax.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceMax.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def reduce_mean(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the mean of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields undefined. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceMean``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _ReduceMean( + _ReduceMean.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceMean.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def reduce_min(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the min of the input tensor's elements along the provided axes. +The resulting tensor has the same rank as the input if ``keepdims`` +equals 1. If ``keepdims`` equals 0, then the resulting tensor has the +reduced dimension pruned. Input tensors of rank zero are valid. +Reduction over an empty set of values yields plus infinity (if supported +by the datatype) or the maximum value of the data type otherwise. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceMin``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ReduceMin( + _ReduceMin.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceMin.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def reduce_prod(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the product of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields 1. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceProd``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _ReduceProd( + _ReduceProd.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceProd.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def reduce_sum(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + r""" +Computes the sum of the input tensor's elements along the provided axes. +The resulting tensor has the same rank as the input if ``keepdims`` +equals 1. If ``keepdims`` equals 0, then the resulting tensor has the +reduced dimension pruned. Input tensors of rank zero are valid. +Reduction over an empty set of values yields 0. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceSum``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _ReduceSum( + _ReduceSum.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceSum.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_sum_square(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: + r""" +Computes the sum square of the input tensor's elements along the +provided axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields 0. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@13::ReduceSumSquare``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return _ReduceSumSquare( + _ReduceSumSquare.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _ReduceSumSquare.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).reduced + + +def relu(X: Var, ) -> Var: + r""" +Relu takes one input data (Tensor) and produces one output data +(Tensor) where the rectified linear function, y = max(0, x), is +applied to the tensor elementwise. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@14::Relu``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` + """ + return _Relu( + _Relu.Attributes( + ), _Relu.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def reshape(data: Var, shape: Var, *, allowzero: int = 0, ) -> Var: + r""" +Reshape the input tensor similar to numpy.reshape. First input is the +data tensor, second input is a shape tensor which specifies the output +shape. It outputs the reshaped tensor. At most one dimension of the new +shape can be -1. In this case, the value is inferred from the size of +the tensor and the remaining dimensions. A dimension could also be 0, in +which case the actual dimension value is unchanged (i.e. taken from the +input tensor). If 'allowzero' is set, and the new shape includes 0, the +dimension will be set explicitly to zero (i.e. not taken from input +tensor). Shape (second input) could be an empty shape, which means +converting to a scalar. The input tensor's shape and the output tensor's +shape are required to have the same number of elements. + +If the attribute 'allowzero' is set, it is invalid for the specified +shape to contain both a zero value and -1, as the value of the dimension +corresponding to -1 cannot be determined uniquely. + +Parameters +========== +data + Type T. + An input tensor. +shape + Type tensor(int64). + Specified shape for output. +allowzero + Attribute. + (Optional) By default, when any value in the 'shape' input is equal to + zero the corresponding dimension value is copied from the input tensor + dynamically. allowzero=1 indicates that if any value in the 'shape' + input is set to zero, the zero value is honored, similar to NumPy. + +Returns +======= +reshaped : Var + Type T. + Reshaped data. + +Notes +===== +Signature: ``ai.onnx@14::Reshape``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), _Reshape.Inputs( + data=unwrap_vars(data), shape=unwrap_vars(shape), ), ).get_output_vars( + data=get_value(data), shape=get_value(shape), ).reshaped + + +def resize(X: Var, roi: Optional[Var] = None, scales: Optional[Var] = None, sizes: Optional[Var] = None, *, coordinate_transformation_mode: str = "half_pixel", cubic_coeff_a: float = -0.75, exclude_outside: int = 0, extrapolation_value: float = 0.0, mode: str = "nearest", nearest_mode: str = "round_prefer_floor", ) -> Var: + r""" +Resize the input tensor. In general, it calculates every value in the +output tensor as a weighted average of neighborhood (a.k.a. sampling +locations) in the input tensor. Each dimension value of the output +tensor is: output_dimension = floor(input_dimension \* (roi_end - +roi_start) \* scale) if input "sizes" is not specified. + +Parameters +========== +X + Type T1. + N-D tensor +roi + Type T2. + 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is + the rank of X. The RoIs' coordinates are normalized in the coordinate + system of the input image. It only takes effect when + coordinate_transformation_mode is "tf_crop_and_resize" +scales + Type tensor(float). + The scale array along each dimension. It takes value greater than 0. If + it's less than 1, it's sampling down, otherwise, it's upsampling. The + number of elements of 'scales' should be the same as the rank of input + 'X'. One of 'scales' and 'sizes' MUST be specified and it is an error if + both are specified. If 'sizes' is needed, the user can use an empty + string as the name of 'scales' in this operator's input list. +sizes + Type tensor(int64). + The size of the output tensor. The number of elements of 'sizes' should + be the same as the rank of input 'X'. Only one of 'scales' and 'sizes' + can be specified. +coordinate_transformation_mode + Attribute. + This attribute describes how to transform the coordinate in the resized + tensor to the coordinate in the original tensor. + + The coordinate of each dimension is transformed individually. Let's + describe a case using axis x as an example. Denote x_resized as the + coordinate of axis x in the resized tensor, x_original as the coordinate + of axis x in the original tensor, length_original as the length of the + original tensor in axis x, length_resized as the length of the resized + tensor in axis x, roi_x = (start_x, end_x) of the axis x in input "roi", + scale = length_resized / length_original, + + if coordinate_transformation_mode is "half_pixel", x_original = + (x_resized + 0.5) / scale - 0.5, + + if coordinate_transformation_mode is "pytorch_half_pixel", x_original = + length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0, + + if coordinate_transformation_mode is "align_corners", x_original = + x_resized \* (length_original - 1) / (length_resized - 1), + + if coordinate_transformation_mode is "asymmetric", x_original = + x_resized / scale, + + if coordinate_transformation_mode is "tf_crop_and_resize", x_original = + length_resized > 1 ? start_x \* (length_original - 1) + x_resized \* + (end_x - start_x) \* (length_original - 1) / (length_resized - 1) : 0.5 + \* (start_x + end_x) \* (length_original - 1). +cubic_coeff_a + Attribute. + The coefficient 'a' used in cubic interpolation. Two common choice are + -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out + Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the + details. This attribute is valid only if "mode" is "cubic". +exclude_outside + Attribute. + If set to 1, the weight of sampling locations outside the tensor will be + set to 0 and the weight will be renormalized so that their sum is 1.0. + The default value is 0. +extrapolation_value + Attribute. + When coordinate_transformation_mode is "tf_crop_and_resize" and + x_original is outside the range [0, length_original - 1], this value is + used as the corresponding output value. Default is 0.0f. +mode + Attribute. + Three interpolation modes: nearest (default), linear and cubic. The + "linear" mode includes linear interpolation for 1D tensor and N-linear + interpolation for N-D tensor (for example, bilinear interpolation for 2D + tensor). The "cubic" mode includes cubic interpolation for 1D tensor and + N-cubic interpolation for N-D tensor (for example, bicubic interpolation + for 2D tensor). +nearest_mode + Attribute. + Four modes: round_prefer_floor (default, as known as round half down), + round_prefer_ceil (as known as round half up), floor, ceil. Only used by + nearest interpolation. It indicates how to get "nearest" pixel in input + tensor from x_original, so this attribute is valid only if "mode" is + "nearest". + +Returns +======= +Y : Var + Type T1. + N-D tensor after resizing + +Notes +===== +Signature: ``ai.onnx@13::Resize``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Resize( + _Resize.Attributes( + coordinate_transformation_mode=AttrString(coordinate_transformation_mode, name="coordinate_transformation_mode"), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32(extrapolation_value, name="extrapolation_value"), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), + ), _Resize.Inputs( + X=unwrap_vars(X), roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), ).get_output_vars( + X=get_value(X), roi=get_value(roi), scales=get_value(scales), sizes=get_value(sizes), ).Y + + +def reverse_sequence(input: Var, sequence_lens: Var, *, batch_axis: int = 1, time_axis: int = 0, ) -> Var: + r""" +Reverse batch of sequences having different lengths specified by +``sequence_lens``. + +For each slice i iterating on batch axis, the operator reverses the +first sequence_lens[i] elements on time axis, and copies elements whose +index's beyond sequence_lens[i] to the output. So the output slice i +contains reversed sequences on the first sequence_lens[i] elements, then +have original values copied for the other elements. + +Example 1: input = [[0.0, 4.0, 8.0, 12.0], [1.0, 5.0, 9.0, 13.0], [2.0, +6.0, 10.0, 14.0], [3.0, 7.0, 11.0, 15.0]] sequence_lens = [4, 3, 2, 1] +time_axis = 0 batch_axis = 1 + +output = [[3.0, 6.0, 9.0, 12.0], [2.0, 5.0, 8.0, 13.0], [1.0, 4.0, 10.0, +14.0], [0.0, 7.0, 11.0, 15.0]] + +Example 2: input = [[0.0, 1.0, 2.0, 3.0 ], [4.0, 5.0, 6.0, 7.0 ], [8.0, +9.0, 10.0, 11.0], [12.0, 13.0, 14.0, 15.0]] sequence_lens = [1, 2, 3, 4] +time_axis = 1 batch_axis = 0 + +output = [[0.0, 1.0, 2.0, 3.0 ], [5.0, 4.0, 6.0, 7.0 ], [10.0, 9.0, 8.0, +11.0], [15.0, 14.0, 13.0, 12.0]] + +Parameters +========== +input + Type T. + Tensor of rank r >= 2. +sequence_lens + Type tensor(int64). + Tensor specifying lengths of the sequences in a batch. It has shape + ``[batch_size]``. +batch_axis + Attribute. + (Optional) Specify which axis is batch axis. Must be one of 1 (default), + or 0. +time_axis + Attribute. + (Optional) Specify which axis is time axis. Must be one of 0 (default), + or 1. + +Returns +======= +Y : Var + Type T. + Tensor with same shape of input. + +Notes +===== +Signature: ``ai.onnx@10::ReverseSequence``. + +Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ReverseSequence( + _ReverseSequence.Attributes( + batch_axis=AttrInt64(batch_axis, name="batch_axis"), + time_axis=AttrInt64(time_axis, name="time_axis"), + ), _ReverseSequence.Inputs( + input=unwrap_vars(input), sequence_lens=unwrap_vars(sequence_lens), ), ).get_output_vars( + input=get_value(input), sequence_lens=get_value(sequence_lens), ).Y + + +def roi_align(X: Var, rois: Var, batch_indices: Var, *, coordinate_transformation_mode: str = "half_pixel", mode: str = "avg", output_height: int = 1, output_width: int = 1, sampling_ratio: int = 0, spatial_scale: float = 1.0, ) -> Var: + r""" +Region of Interest (RoI) align operation described in the `Mask R-CNN +paper `__. RoiAlign consumes an input +tensor X and region of interests (rois) to apply pooling across each +RoI; it produces a 4-D tensor of shape (num_rois, C, output_height, +output_width). + +RoiAlign is proposed to avoid the misalignment by removing quantizations +while converting from original image into feature map and from feature +map into RoI feature; in each ROI bin, the value of the sampled +locations are computed directly through bilinear interpolation. + +Parameters +========== +X + Type T1. + Input data tensor from the previous operator; 4-D feature map of shape + (N, C, H, W), where N is the batch size, C is the number of channels, + and H and W are the height and the width of the data. +rois + Type T1. + RoIs (Regions of Interest) to pool over; rois is 2-D input of shape + (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates + are in the coordinate system of the input image. Each coordinate set has + a 1:1 correspondence with the 'batch_indices' input. +batch_indices + Type T2. + 1-D tensor of shape (num_rois,) with each element denoting the index of + the corresponding image in the batch. +coordinate_transformation_mode + Attribute. + Allowed values are 'half_pixel' and 'output_half_pixel'. Use the value + 'half_pixel' to pixel shift the input coordinates by -0.5 (the + recommended behavior). Use the value 'output_half_pixel' to omit the + pixel shift for the input (use this for a backward-compatible behavior). +mode + Attribute. + The pooling method. Two modes are supported: 'avg' and 'max'. Default is + 'avg'. +output_height + Attribute. + default 1; Pooled output Y's height. +output_width + Attribute. + default 1; Pooled output Y's width. +sampling_ratio + Attribute. + Number of sampling points in the interpolation grid used to compute the + output value of each pooled output bin. If > 0, then exactly + sampling_ratio x sampling_ratio grid points are used. If == 0, then an + adaptive number of grid points are used (computed as ceil(roi_width / + output_width), and likewise for height). Default is 0. +spatial_scale + Attribute. + Multiplicative spatial scale factor to translate ROI coordinates from + their input spatial scale to the scale used when pooling, i.e., spatial + scale of the input feature map X relative to the input image. E.g.; + default is 1.0f. + +Returns +======= +Y : Var + Type T1. + RoI pooled output, 4-D tensor of shape (num_rois, C, output_height, + output_width). The r-th batch element Y[r-1] is a pooled feature map + corresponding to the r-th RoI X[r-1]. + +Notes +===== +Signature: ``ai.onnx@16::RoiAlign``. + +Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int64)` + """ + return _RoiAlign( + _RoiAlign.Attributes( + coordinate_transformation_mode=AttrString(coordinate_transformation_mode, name="coordinate_transformation_mode"), + mode=AttrString(mode, name="mode"), + output_height=AttrInt64(output_height, name="output_height"), + output_width=AttrInt64(output_width, name="output_width"), + sampling_ratio=AttrInt64(sampling_ratio, name="sampling_ratio"), + spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), + ), _RoiAlign.Inputs( + X=unwrap_vars(X), rois=unwrap_vars(rois), batch_indices=unwrap_vars(batch_indices), ), ).get_output_vars( + X=get_value(X), rois=get_value(rois), batch_indices=get_value(batch_indices), ).Y + + +def round(X: Var, ) -> Var: + r""" +Round takes one input Tensor and rounds the values, element-wise, +meaning it finds the nearest integer for each value. In case of halves, +the rule is to round them to the nearest even integer. If input x is +integral, +0, -0, NaN, or infinite, x itself is returned. The output +tensor has the same shape and type as the input. + +Examples: + +:: + + round([0.9]) = [1.0] + round([2.5]) = [2.0] + round([2.3]) = [2.0] + round([1.5]) = [2.0] + round([-4.5]) = [-4.0] + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@11::Round``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Round( + _Round.Attributes( + ), _Round.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def stft(signal: Var, frame_step: Var, window: Optional[Var] = None, frame_length: Optional[Var] = None, *, onesided: int = 1, ) -> Var: + r""" +Computes the Short-time Fourier Transform of the signal. + +Parameters +========== +signal + Type T1. + Input tensor representing a real or complex valued signal. For real + input, the following shape is expected: [batch_size][signal_length][1]. + For complex input, the following shape is expected: + [batch_size][signal_length][2], where [batch_size][signal_length][0] + represents the real component and [batch_size][signal_length][1] + represents the imaginary component of the signal. +frame_step + Type T2. + The number of samples to step between successive DFTs. +window + Type T1. + A tensor representing the window that will be slid over the signal.The + window must have rank 1 with shape: [window_shape]. It's an optional + value. +frame_length + Type T2. + A scalar representing the size of the DFT. It's an optional value. +onesided + Attribute. + If onesided is 1, only values for w in [0, 1, 2, ..., floor(n_fft/2) + + 1] are returned because the real-to-complex Fourier transform satisfies + the conjugate symmetry, i.e., X[m, w] = X[m,w]=X[m,n_fft-w]\*. Note if + the input or window tensors are complex, then onesided output is not + possible. Enabling onesided with real inputs performs a Real-valued fast + Fourier transform (RFFT).When invoked with real or complex valued input, + the default value is 1. Values can be 0 or 1. + +Returns +======= +output : Var + Type T1. + The Short-time Fourier Transform of the signals.If onesided is 1, the + output has the shape: [batch_size][frames][dft_unique_bins][2], where + dft_unique_bins is frame_length // 2 + 1 (the unique components of the + DFT) If onesided is 0, the output has the shape: + [batch_size][frames][frame_length][2], where frame_length is the length + of the DFT. + +Notes +===== +Signature: ``ai.onnx@17::STFT``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return _STFT( + _STFT.Attributes( + onesided=AttrInt64(onesided, name="onesided"), + ), _STFT.Inputs( + signal=unwrap_vars(signal), frame_step=unwrap_vars(frame_step), window=unwrap_vars(window), frame_length=unwrap_vars(frame_length), ), ).get_output_vars( + signal=get_value(signal), frame_step=get_value(frame_step), window=get_value(window), frame_length=get_value(frame_length), ).output + + +def scan(initial_state_and_scan_inputs: Sequence[Var], *, body: Callable[..., Iterable[Var]], num_scan_inputs: int, scan_input_axes: Optional[Iterable[int]] = None, scan_input_directions: Optional[Iterable[int]] = None, scan_output_axes: Optional[Iterable[int]] = None, scan_output_directions: Optional[Iterable[int]] = None, ) -> Sequence[Var]: + r""" +Scan can be used to iterate over one or more scan_input tensors, +constructing zero or more scan_output tensors. It combines ideas from +general recurrences, functional programming constructs such as scan, +fold, map, and zip, and is intended to enable generalizations of +RNN-like constructs for sequence-to-sequence processing. Other tensors +(referred to as state_variables here) can be used to carry a state when +iterating from one element to another (similar to hidden-state in RNNs, +also referred to as loop-carried dependences in the context of loops). +Many common usages involve a single scan_input tensor (where +functionality similar to scan, fold and map can be obtained). When more +than one scan_input is used, a behavior similar to zip is obtained. + +The attribute body must be a graph, specifying the computation to be +performed in every iteration. It takes as input the current values of +the state_variables and the current iterated element of the scan_inputs. +It must return the (updated) values of the state_variables and zero or +more scan_output_element tensors. The values of the scan_output_element +tensors are concatenated over all the iterations to produce the +scan_output values of the scan construct (similar to the concatenated +intermediate hidden-state values of RNN-like constructs). All the output +tensors (state_variables as well as scan_output_element tensors) are +required to have the same shape in each iteration of the loop (a +restriction imposed to enable efficient memory allocation). + +Note that the iterated element passed to the body subgraph does not have +a sequence axis. It will have a rank one less than the rank of the +corresponding scan_input. + +The scan operation returns the final values of the state_variables as +well as the scan_outputs. + +The optional attribute scan_input_directions specifies the direction +(forward or backward) for each scan input. If this attribute is omitted, +all sequences are scanned in the forward direction. A bidirectional scan +may be performed by specifying the same tensor input twice in the +scan_inputs, once with a forward direction, and once with a backward +direction. + +The scan_output of the operation is produced by concatenating the +scan_output_element values produced by the body in each iteration. The +optional attribute scan_output_directions specifies the direction in +which scan_output is constructed (by appending or prepending the +scan_output_element to scan_output in each iteration) for each +scan_output. If this attribute is omitted, the scan_output_element is +appended to the scan_output in each iteration. + +The optional attribute scan_input_axes specifies the axis to be scanned +for each scan_input. If omitted, every scan_input will be scanned in +axis 0. For example, if axis 0 is the batch axis and axis 1 is the time +axis (to be scanned), specify an axis value of 1. Note that scanning a +non-zero axis may be less efficient than scanning axis zero. + +The optional attribute scan_output_axes specifies the axis along which +the scan_outputs are accumulated for each scan_output. For example, if +axis 1 is the time axis (to be scanned) for both inputs and outputs, +specify a scan_input axis and scan_output axis value of 1. + +Note that because of the ONNX restriction that only the last parameter +of an operator can be variadic, the initial-states and scan-inputs are +listed together as one input parameter. Similarly, the final-states and +scan-outputs are listed together as one output parameter. The attribute +num_scan_inputs indicates the number M of scan-inputs. + +The behavior of + +:: + + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) + +is equivalent to the following pseudo-code: + +:: + + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + +*Sample usage: Encoding RNN using a Scan* + +The following example shows how a simple RNN over an input tensor %X, +with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi +and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. +Note that the loop-body is a nested graph, and it directly computes %Wi, +%Ri, %Wbi, and %Rbi (typically constants or initializers in the body +graph). If these values are computed in the outer graph, they need to be +passed in as extra state_variables. + +:: + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + +Parameters +========== +initial_state_and_scan_inputs + Type V. + Initial values of the loop's N state variables followed by M scan_inputs +body + Attribute. + The graph run each iteration. It has N+M inputs: (loop state + variables..., scan_input_elts...). It has N+K outputs: (loop state + variables..., scan_output_elts...). Each scan_output is created by + concatenating the value of the specified scan_output_elt value at the + end of each iteration of the loop. It is an error if the dimensions of + these values change across loop iterations. +num_scan_inputs + Attribute. + An attribute specifying the number of scan_inputs M. +scan_input_axes + Attribute. + An optional list of M flags. The i-th element of the list specifies the + axis to be scanned (the sequence axis) for the i-th scan_input. If + omitted, 0 will be used as the scan axis for every scan_input. Negative + value for an axis means counting dimensions from the back. Accepted + range is [-r, r-1] where r = rank(input). +scan_input_directions + Attribute. + An optional list of M flags. The i-th element of the list specifies the + direction to be scanned for the i-th scan_input tensor: 0 indicates + forward direction and 1 indicates reverse direction. If omitted, all + scan_input tensors will be scanned in the forward direction. +scan_output_axes + Attribute. + An optional list of K flags. The i-th element of the list specifies the + axis for the i-th scan_output. The scan outputs are accumulated along + the specified axis. If omitted, 0 will be used as the scan axis for + every scan_output. Negative value for an axis means counting dimensions + from the back. Accepted range is [-r, r-1]. +scan_output_directions + Attribute. + An optional list of K flags, one for each scan_output. The i-th element + of the list specifies whether the i-th scan_output should be constructed + by appending or prepending a new value in each iteration: 0 indicates + appending and 1 indicates prepending. If omitted, all scan_output + tensors will be produced by appending a value in each iteration. + +Returns +======= +final_state_and_scan_outputs : Sequence[Var] + Type V. + Final values of the loop's N state variables followed by K scan_outputs + +Notes +===== +Signature: ``ai.onnx@16::Scan``. + +Type constraints: + - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _BlackmanWindow( - _BlackmanWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), - _BlackmanWindow.Inputs( - size=unwrap_vars(size), - ), - ) - .get_output_vars( - size=get_value(size), - ) - .output - ) + _body_subgraph: Graph = subgraph( + [Tensor(var.unwrap_tensor().dtype, (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape)) for var in initial_state_and_scan_inputs[:num_scan_inputs]] + [Tensor(var.unwrap_tensor().dtype) for var in initial_state_and_scan_inputs[num_scan_inputs:]], + body + ) + return _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), + scan_input_directions=AttrInt64s.maybe(scan_input_directions, name="scan_input_directions"), + scan_output_axes=AttrInt64s.maybe(scan_output_axes, name="scan_output_axes"), + scan_output_directions=AttrInt64s.maybe(scan_output_directions, name="scan_output_directions"), + ), _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), ).final_state_and_scan_outputs + + +def scatter_elements(data: Var, indices: Var, updates: Var, *, axis: int = 0, reduction: str = "none", ) -> Var: + r""" +ScatterElements takes three inputs ``data``, ``updates``, and +``indices`` of the same rank r >= 1 and an optional attribute axis that +identifies an axis of ``data`` (by default, the outer-most axis, that is +axis 0). The output of the operation is produced by creating a copy of +the input ``data``, and then updating its value to values specified by +``updates`` at specific index positions specified by ``indices``. Its +output shape is the same as the shape of ``data``. For each entry in +``updates``, the target index in ``data`` is obtained by combining the +corresponding entry in ``indices`` with the index of the entry itself: +the index-value for dimension = axis is obtained from the value of the +corresponding entry in ``indices`` and the index-value for dimension != +axis is obtained from the index of the entry itself. ``reduction`` +allows specification of an optional reduction operation, which is +applied to all values in ``updates`` tensor into ``output`` at the +specified ``indices``. In cases where ``reduction`` is set to "none", +indices should not have duplicate entries: that is, if idx1 != idx2, +then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, +the update corresponding to the [i][j] entry is performed as below: + +:: + + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + +When ``reduction`` is set to "add", the update corresponding to the +[i][j] entry is performed as below: + +:: + + output[indices[i][j]][j] += updates[i][j] if axis = 0, + output[i][indices[i][j]] += updates[i][j] if axis = 1, + +When ``reduction`` is set to "mul", the update corresponding to the +[i][j] entry is performed as below: + +:: + + output[indices[i][j]][j] *= updates[i][j] if axis = 0, + output[i][indices[i][j]] *= updates[i][j] if axis = 1, + +This operator is the inverse of GatherElements. It is similar to Torch's +Scatter operation. Example 1: + +:: + + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + +Example 2: + +:: + + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + +Parameters +========== +data + Type T. + Tensor of rank r >= 1. +indices + Type Tind. + Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index + values are expected to be within bounds [-s, s-1] along axis of size s. + It is an error if any of the index values are out of bounds. +updates + Type T. + Tensor of rank r >=1 (same rank and shape as indices) +axis + Attribute. + Which axis to scatter on. Negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(data). +reduction + Attribute. + Type of reduction to apply: none (default), add, mul. 'none': no + reduction applied. 'add': reduction using the addition operation. 'mul': + reduction using the multiplication operation. + +Returns +======= +output : Var + Type T. + Tensor of rank r >= 1 (same rank as input). + +Notes +===== +Signature: ``ai.onnx@16::ScatterElements``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return _ScatterElements( + _ScatterElements.Attributes( + axis=AttrInt64(axis, name="axis"), + reduction=AttrString(reduction, name="reduction"), + ), _ScatterElements.Inputs( + data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), ).get_output_vars( + data=get_value(data), indices=get_value(indices), updates=get_value(updates), ).output + + +def scatter_nd(data: Var, indices: Var, updates: Var, *, reduction: str = "none", ) -> Var: + r""" +ScatterND takes three inputs ``data`` tensor of rank r >= 1, ``indices`` +tensor of rank q >= 1, and ``updates`` tensor of rank q + r - +indices.shape[-1] - 1. The output of the operation is produced by +creating a copy of the input ``data``, and then updating its value to +values specified by ``updates`` at specific index positions specified by +``indices``. Its output shape is the same as the shape of ``data``. + +``indices`` is an integer tensor. Let k denote indices.shape[-1], the +last dimension in the shape of ``indices``. ``indices`` is treated as a +(q-1)-dimensional tensor of k-tuples, where each k-tuple is a +partial-index into ``data``. Hence, k can be a value at most the rank of +``data``. When k equals rank(data), each update entry specifies an +update to a single element of the tensor. When k is less than rank(data) +each update entry specifies an update to a slice of the tensor. Index +values are allowed to be negative, as per the usual convention for +counting backwards from the end, but are expected in the valid range. + +``updates`` is treated as a (q-1)-dimensional tensor of +replacement-slice-values. Thus, the first (q-1) dimensions of +updates.shape must match the first (q-1) dimensions of indices.shape. +The remaining dimensions of ``updates`` correspond to the dimensions of +the replacement-slice-values. Each replacement-slice-value is a (r-k) +dimensional tensor, corresponding to the trailing (r-k) dimensions of +``data``. Thus, the shape of ``updates`` must equal indices.shape[0:q-1] +++ data.shape[k:r-1], where ++ denotes the concatenation of shapes. + +The ``output`` is calculated via the following equation: output = +np.copy(data) update_indices = indices.shape[:-1] for idx in +np.ndindex(update_indices): output[indices[idx]] = updates[idx] The +order of iteration in the above loop is not specified. In particular, +indices should not have duplicate entries: that is, if idx1 != idx2, +then indices[idx1] != indices[idx2]. This ensures that the output value +does not depend on the iteration order. + +``reduction`` allows specification of an optional reduction operation, +which is applied to all values in ``updates`` tensor into ``output`` at +the specified ``indices``. In cases where ``reduction`` is set to +"none", indices should not have duplicate entries: that is, if idx1 != +idx2, then indices[idx1] != indices[idx2]. This ensures that the output +value does not depend on the iteration order. When ``reduction`` is set +to "add", ``output`` is calculated as follows: output = np.copy(data) +update_indices = indices.shape[:-1] for idx in +np.ndindex(update_indices): output[indices[idx]] += updates[idx] When +``reduction`` is set to "mul", ``output`` is calculated as follows: +output = np.copy(data) update_indices = indices.shape[:-1] for idx in +np.ndindex(update_indices): output[indices[idx]] \*= updates[idx] This +operator is the inverse of GatherND. Example 1: + +:: + + data = [1, 2, 3, 4, 5, 6, 7, 8] + indices = [[4], [3], [1], [7]] + updates = [9, 10, 11, 12] + output = [1, 11, 3, 10, 9, 6, 7, 12] + +Example 2: + +:: + + data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + indices = [[0], [2]] + updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] + output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + +Parameters +========== +data + Type T. + Tensor of rank r >= 1. +indices + Type tensor(int64). + Tensor of rank q >= 1. +updates + Type T. + Tensor of rank q + r - indices_shape[-1] - 1. +reduction + Attribute. + Type of reduction to apply: none (default), add, mul. 'none': no + reduction applied. 'add': reduction using the addition operation. 'mul': + reduction using the multiplication operation. + +Returns +======= +output : Var + Type T. + Tensor of rank r >= 1. + +Notes +===== +Signature: ``ai.onnx@16::ScatterND``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ScatterND( + _ScatterND.Attributes( + reduction=AttrString(reduction, name="reduction"), + ), _ScatterND.Inputs( + data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), ).get_output_vars( + data=get_value(data), indices=get_value(indices), updates=get_value(updates), ).output + + +def selu(X: Var, *, alpha: float = 1.6732631921768188, gamma: float = 1.0507010221481323, ) -> Var: + r""" +Selu takes one input data (Tensor) and produces one output data +(Tensor) where the scaled exponential linear unit function, +``y = gamma * (alpha * e^x - alpha) for x <= 0``, +``y = gamma * x for x > 0``, is applied to the tensor elementwise. + +Parameters +========== +X + Type T. + Input tensor +alpha + Attribute. + Coefficient of SELU default to 1.67326319217681884765625 (i.e., float32 + approximation of 1.6732632423543772848170429916717). +gamma + Attribute. + Coefficient of SELU default to 1.05070102214813232421875 (i.e., float32 + approximation of 1.0507009873554804934193349852946). + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@6::Selu``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Selu( + _Selu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + gamma=AttrFloat32(gamma, name="gamma"), + ), _Selu.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def sequence_at(input_sequence: Var, position: Var, ) -> Var: + r""" +Outputs a tensor copy from the tensor at 'position' in 'input_sequence'. +Accepted range for 'position' is in ``[-n, n - 1]``, where ``n`` is the +number of tensors in 'input_sequence'. Negative value means counting +positions from the back. + +Parameters +========== +input_sequence + Type S. + Input sequence. +position + Type I. + Position of the tensor in the sequence. Negative value means counting + positions from the back. Accepted range in ``[-n, n - 1]``, where ``n`` + is the number of tensors in 'input_sequence'. It is an error if any of + the index values are out of bounds. It must be a scalar(tensor of empty + shape). + +Returns +======= +tensor : Var + Type T. + Output tensor at the specified position in the input sequence. + +Notes +===== +Signature: ``ai.onnx@11::SequenceAt``. + +Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - I: `tensor(int32)`, `tensor(int64)` + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _SequenceAt( + _SequenceAt.Attributes( + ), _SequenceAt.Inputs( + input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), ), ).get_output_vars( + input_sequence=get_value(input_sequence), position=get_value(position), ).tensor + + +def sequence_construct(inputs: Sequence[Var], ) -> Var: + r""" +Construct a tensor sequence containing 'inputs' tensors. All tensors in +'inputs' must have the same data type. + +Parameters +========== +inputs + Type T. + Tensors. + +Returns +======= +output_sequence : Var + Type S. + Sequence enclosing the input tensors. + +Notes +===== +Signature: ``ai.onnx@11::SequenceConstruct``. + +Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + """ + return _SequenceConstruct( + _SequenceConstruct.Attributes( + ), _SequenceConstruct.Inputs( + inputs=unwrap_vars(inputs), ), ).get_output_vars( + inputs=get_value(inputs), ).output_sequence + + +def sequence_empty(*, dtype: Optional[npt.DTypeLike] = None, ) -> Var: + r""" +Construct an empty tensor sequence, with given data type. + +Parameters +========== +dtype + Attribute. + (Optional) The data type of the tensors in the output sequence. The + default type is 'float'. + +Returns +======= +output : Var + Type S. + Empty sequence. + +Notes +===== +Signature: ``ai.onnx@11::SequenceEmpty``. + +Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + """ + return _SequenceEmpty( + _SequenceEmpty.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + ), _SequenceEmpty.Inputs( + ), ).get_output_vars( + ).output + + +def sequence_erase(input_sequence: Var, position: Optional[Var] = None, ) -> Var: + r""" +Outputs a tensor sequence that removes the tensor at 'position' from +'input_sequence'. Accepted range for 'position' is in ``[-n, n - 1]``, +where ``n`` is the number of tensors in 'input_sequence'. Negative value +means counting positions from the back. 'position' is optional, by +default it erases the last tensor from 'input_sequence'. + +Parameters +========== +input_sequence + Type S. + Input sequence. +position + Type I. + Position of the tensor in the sequence. Negative value means counting + positions from the back. Accepted range in ``[-n, n - 1]``, where ``n`` + is the number of tensors in 'input_sequence'. It is an error if any of + the index values are out of bounds. It must be a scalar(tensor of empty + shape). + +Returns +======= +output_sequence : Var + Type S. + Output sequence that has the tensor at the specified position removed. + +Notes +===== +Signature: ``ai.onnx@11::SequenceErase``. + +Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - I: `tensor(int32)`, `tensor(int64)` + """ + return _SequenceErase( + _SequenceErase.Attributes( + ), _SequenceErase.Inputs( + input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), ), ).get_output_vars( + input_sequence=get_value(input_sequence), position=get_value(position), ).output_sequence + + +def sequence_insert(input_sequence: Var, tensor: Var, position: Optional[Var] = None, ) -> Var: + r""" +Outputs a tensor sequence that inserts 'tensor' into 'input_sequence' at +'position'. 'tensor' must have the same data type as 'input_sequence'. +Accepted range for 'position' is in ``[-n, n]``, where ``n`` is the +number of tensors in 'input_sequence'. Negative value means counting +positions from the back. 'position' is optional, by default it inserts +'tensor' to the back of 'input_sequence'. + +Parameters +========== +input_sequence + Type S. + Input sequence. +tensor + Type T. + Input tensor to be inserted into the input sequence. +position + Type I. + Position in the sequence where the new tensor is inserted. It is + optional and default is to insert to the back of the sequence. Negative + value means counting positions from the back. Accepted range in + ``[-n, n]``, where ``n`` is the number of tensors in 'input_sequence'. + It is an error if any of the index values are out of bounds. It must be + a scalar(tensor of empty shape). + +Returns +======= +output_sequence : Var + Type S. + Output sequence that contains the inserted tensor at given position. + +Notes +===== +Signature: ``ai.onnx@11::SequenceInsert``. + +Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - I: `tensor(int32)`, `tensor(int64)` + """ + return _SequenceInsert( + _SequenceInsert.Attributes( + ), _SequenceInsert.Inputs( + input_sequence=unwrap_vars(input_sequence), tensor=unwrap_vars(tensor), position=unwrap_vars(position), ), ).get_output_vars( + input_sequence=get_value(input_sequence), tensor=get_value(tensor), position=get_value(position), ).output_sequence + + +def sequence_length(input_sequence: Var, ) -> Var: + r""" +Produces a scalar(tensor of empty shape) containing the number of +tensors in 'input_sequence'. + +Parameters +========== +input_sequence + Type S. + Input sequence. + +Returns +======= +length : Var + Type I. + Length of input sequence. It must be a scalar(tensor of empty shape). + +Notes +===== +Signature: ``ai.onnx@11::SequenceLength``. + +Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - I: `tensor(int64)` + """ + return _SequenceLength( + _SequenceLength.Attributes( + ), _SequenceLength.Inputs( + input_sequence=unwrap_vars(input_sequence), ), ).get_output_vars( + input_sequence=get_value(input_sequence), ).length + + +def sequence_map(input_sequence: Var, additional_inputs: Sequence[Var] = (), *, body: Callable[..., Iterable[Var]], ) -> Sequence[Var]: + r""" +Applies a sub-graph to each sample in the input sequence(s). + +Inputs can be either tensors or sequences, with the exception of the +first input which must be a sequence. The length of the first input +sequence will determine the number of samples in the outputs. Any other +sequence inputs should have the same number of samples. The number of +inputs and outputs, should match the one of the subgraph. + +For each i-th element in the output, a sample will be extracted from the +input sequence(s) at the i-th position and the sub-graph will be applied +to it. The outputs will contain the outputs of the sub-graph for each +sample, in the same order as in the input. + +This operator assumes that processing each sample is independent and +could executed in parallel or in any order. Users cannot expect any +specific ordering in which each subgraph is computed. + +Parameters +========== +input_sequence + Type S. + Input sequence. +additional_inputs + Type V. + Additional inputs to the graph +body + Attribute. + The graph to be run for each sample in the sequence(s). It should have + as many inputs and outputs as inputs and outputs to the SequenceMap + function. + +Returns +======= +out_sequence : Sequence[Var] + Type S. + Output sequence(s) + +Notes +===== +Signature: ``ai.onnx@17::SequenceMap``. + +Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + _body_subgraph: Graph = subgraph( + [typing_cast(SpoxSequence, input_sequence.unwrap_type()).elem_type] + [typing_cast(SpoxSequence, var.unwrap_type()).elem_type for var in additional_inputs], + body + ) + return _SequenceMap( + _SequenceMap.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), _SequenceMap.Inputs( + input_sequence=unwrap_vars(input_sequence), additional_inputs=unwrap_vars(additional_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( + input_sequence=get_value(input_sequence), additional_inputs=get_value(additional_inputs), ).out_sequence + + +def shape(data: Var, *, end: Optional[int] = None, start: int = 0, ) -> Var: + r""" +Takes a tensor as input and outputs an 1D int64 tensor containing the +shape of the input tensor. Optional attributes start and end can be used +to compute a slice of the input tensor's shape. If start axis is +omitted, the slice starts from axis 0. The end axis, if specified, is +exclusive (and the returned value will not include the size of that +axis). If the end axis is omitted, the axes upto the last one will be +included. Negative axes indicate counting back from the last axis. Note +that axes will be clamped to the range [0, r-1], where r is the rank of +the input tensor if they are out-of-range (after adding r in the case of +negative axis). Thus, specifying any end value > r is equivalent to +specifying an end value of r, and specifying any start value < -r is +equivalent to specifying a start value of 0. + +Examples: + +:: + + Input tensor with shape: [2, 3, 4] + No attributes specified. + Output: [2, 3, 4] + +:: + + Input tensor with shape: [2, 3, 4] + start: -1 + Output: [4] + +:: + + Input tensor with shape: [2, 3, 4] + end: -1 + Output: [2, 3] + +:: + + Input tensor with shape: [2, 3, 4] + start: 1 + end: 2 + Output: [3] + +Parameters +========== +data + Type T. + An input tensor. +end + Attribute. + (Optional) Ending axis for slicing the shape. Negative value means + counting dimensions from the back. If omitted, sizes of all axes upto + (including) the last one will be included. +start + Attribute. + (Optional) Starting axis for slicing the shape. Default value is + 0.Negative value means counting dimensions from the back. + +Returns +======= +shape : Var + Type T1. + Shape of the input tensor + +Notes +===== +Signature: ``ai.onnx@15::Shape``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` + """ + return _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), _Shape.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).shape + + +def shrink(input: Var, *, bias: float = 0.0, lambd: float = 0.5, ) -> Var: + r""" +Shrink takes one input data (Tensor) and produces one Tensor output, +having same datatype and shape with input. It has two attributes, lambd +and bias. The formula of this operator is: If x < -lambd, y = x + bias; +If x > lambd, y = x - bias; Otherwise, y = 0. + +Parameters +========== +input + Type T. + The input data as Tensor. +bias + Attribute. + The bias value added to output. Default is 0. +lambd + Attribute. + The lambd value for the Shrink formulation. Default is 0.5. + +Returns +======= +output : Var + Type T. + The output. + +Notes +===== +Signature: ``ai.onnx@9::Shrink``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Shrink( + _Shrink.Attributes( + bias=AttrFloat32(bias, name="bias"), + lambd=AttrFloat32(lambd, name="lambd"), + ), _Shrink.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def sigmoid(X: Var, ) -> Var: + r""" +Sigmoid takes one input data (Tensor) and produces one output data +(Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is +applied to the tensor elementwise. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@13::Sigmoid``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Sigmoid( + _Sigmoid.Attributes( + ), _Sigmoid.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def sign(input: Var, ) -> Var: + r""" +Calculate the sign of the given input tensor element-wise. If input > 0, +output 1. if input < 0, output -1. if input == 0, output 0. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The sign of the input tensor computed element-wise. It has the same + shape and type of the input. + +Notes +===== +Signature: ``ai.onnx@13::Sign``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Sign( + _Sign.Attributes( + ), _Sign.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def sin(input: Var, ) -> Var: + r""" +Calculates the sine of the given input tensor, element-wise. + +Parameters +========== +input + Type T. + Input tensor +Returns +======= +output : Var + Type T. + The sine of the input tensor computed element-wise -def cast( - input: Var, - *, - to: npt.DTypeLike, -) -> Var: - r""" - The operator casts the elements of a given input tensor to a data type - specified by the 'to' argument and returns an output tensor of the same - size in the converted type. The 'to' argument must be one of the data - types specified in the 'DataType' enum field in the TensorProto message. - - Casting from string tensor in plain (e.g., "3.14" and "1000") and - scientific numeric representations (e.g., "1e-5" and "1E8") to float - types is supported. For example, converting string "100.5" to an integer - may yield result 100. There are some string literals reserved for - special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are - positive infinity, negative infinity, and not-a-number, respectively. - Any string which can exactly match "+INF" in a case-insensitive way - would be mapped to positive infinite. Similarly, this case-insensitive - rule is applied to "INF" and "NaN". When casting from numeric tensors to - string tensors, plain floating-point representation (such as - "314.15926") would be used. Converting non-numerical-literal string such - as "Hello World!" is an undefined behavior. Cases of converting string - representing floating-point arithmetic value, such as "2.718", to INT is - an undefined behavior. - - Conversion from a numerical type to any numerical type is always - allowed. User must be aware of precision loss and value change caused by - range difference between two types. For example, a 64-bit float - 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, - converting an integer 36 to Boolean may produce 1 because we truncate - bits which can't be stored in the targeted type. - - In more detail, the conversion among numerical types should follow these - rules: - - - Casting from floating point to: - - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. - - - Casting from fixed point to: - - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. - - - Casting from bool to: - - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. - - Parameters - ========== - input - Type T1. - Input tensor to be cast. - to - Attribute. - The data type to which the elements of the input tensor are cast. - Strictly must be one of the types from DataType enum in TensorProto - - Returns - ======= - output : Var - Type T2. - Output tensor with the same shape as input with type specified by the - 'to' argument - - Notes - ===== - Signature: ``ai.onnx@13::Cast``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Notes +===== +Signature: ``ai.onnx@7::Sin``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _Cast( - _Cast.Attributes( - to=AttrDtype(to, name="to"), - ), - _Cast.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Sin( + _Sin.Attributes( + ), _Sin.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def cast_like( - input: Var, - target_type: Var, -) -> Var: +def sinh(input: Var, ) -> Var: r""" - The operator casts the elements of a given input tensor (the first - input) to the same data type as the elements of the second input tensor. - See documentation of the Cast operator for further details. +Calculates the hyperbolic sine of the given input tensor element-wise. - Parameters - ========== - input - Type T1. - Input tensor to be cast. - target_type - Type T2. - The (first) input tensor will be cast to produce a tensor of the same - type as this (second input) tensor. - - Returns - ======= - output : Var - Type T2. - Output tensor produced by casting the first input tensor to have the - same type as the second input tensor. - - Notes - ===== - Signature: ``ai.onnx@15::CastLike``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _CastLike( - _CastLike.Attributes(), - _CastLike.Inputs( - input=unwrap_vars(input), - target_type=unwrap_vars(target_type), - ), - ) - .get_output_vars( - input=get_value(input), - target_type=get_value(target_type), - ) - .output - ) +Parameters +========== +input + Type T. + Input tensor +Returns +======= +output : Var + Type T. + The hyperbolic sine values of the input tensor computed element-wise -def ceil( - X: Var, -) -> Var: - r""" - Ceil takes one input data (Tensor) and produces one output data - (Tensor) where the ceil is, y = ceil(x), is applied to the tensor - elementwise. If x is integral, +0, -0, NaN, or infinite, x itself is - returned. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::Ceil``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` +Notes +===== +Signature: ``ai.onnx@9::Sinh``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _Ceil( - _Ceil.Attributes(), - _Ceil.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) + return _Sinh( + _Sinh.Attributes( + ), _Sinh.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def celu( - X: Var, - *, - alpha: float = 1.0, -) -> Var: +def size(data: Var, ) -> Var: r""" - Continuously Differentiable Exponential Linear Units: Perform the linear - unit element-wise on the input tensor X using formula: - - :: - - max(0,x) + min(0,alpha*(exp(x/alpha)-1)) - - Parameters - ========== - X - Type T. - Input tensor - alpha - Attribute. - The Alpha value in Celu formula which control the shape of the unit. The - default value is 1.0. - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@12::Celu``. - - Type constraints: - - T: `tensor(float)` - """ - return ( - _Celu( - _Celu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), - _Celu.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) +Takes a tensor as input and outputs a int64 scalar that equals to the +total number of elements of the input tensor. +Parameters +========== +data + Type T. + An input tensor. + +Returns +======= +size : Var + Type T1. + Total number of elements of the input tensor + +Notes +===== +Signature: ``ai.onnx@13::Size``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` + """ + return _Size( + _Size.Attributes( + ), _Size.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).size + + +def slice(data: Var, starts: Var, ends: Var, axes: Optional[Var] = None, steps: Optional[Var] = None, ) -> Var: + r""" +Produces a slice of the input tensor along multiple axes. Similar to +numpy: +https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding + +Slice uses the ``starts``, ``ends``, ``axes`` and ``steps`` inputs to +select a sub-tensor of its input ``data`` tensor. + +An effective ``starts[i]``, ``ends[i]``, and ``steps[i]`` must be +computed for each ``i`` in ``[0, ... r-1]`` where ``r = rank(input)`` as +follows: + +If ``axes`` are omitted, they are set to ``[0, ..., r-1]``. If ``steps`` +are omitted, they are set to ``[1, ..., 1]`` of length ``len(starts)`` + +The effective values are initialized as ``start[i] = 0``, +``ends[i] = dims[i]`` where ``dims`` are the dimensions of ``input`` and +``steps[i] = 1``. + +All negative elements of ``axes`` are made non-negative by adding ``r`` +to them, where ``r =rank(input)``. + +All negative values in ``starts[i]`` and ``ends[i]`` have +``dims[axes[i]]`` added to them, where ``dims`` are the dimensions of +``input``. Then ``start[axes[i]]`` is the adjusted ``starts[i]`` is +clamped into the range ``[0, dims[axes[i]]]`` for positive stepping and +``[0, dims[axes[i]]-1]`` for negative stepping. + +The clamping for the adjusted ``ends[i]`` depends on the sign of +``steps[i]`` and must accommodate copying 0 through ``dims[axes[i]]`` +elements, so for positive stepping ``ends[axes[i]]`` is clamped to +``[0, dims[axes[i]]]``, while for negative stepping it is clamped to +``[-1, dims[axes[i]]-1]``. + +Finally, ``steps[axes[i]] = steps[i]``. + +For slicing to the end of a dimension with unknown size, it is +recommended to pass in ``INT_MAX`` when slicing forward and 'INT_MIN' +when slicing backward. + +Example 1: + +:: + + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + axes = [0, 1] + starts = [1, 0] + ends = [2, 3] + steps = [1, 2] + result = [ + [5, 7], + ] + +Example 2: + +:: + + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + starts = [0, 1] + ends = [-1, 1000] + result = [ + [2, 3, 4], + ] + +Parameters +========== +data + Type T. + Tensor of data to extract slices from. +starts + Type Tind. + 1-D tensor of starting indices of corresponding axis in ``axes`` +ends + Type Tind. + 1-D tensor of ending indices (exclusive) of corresponding axis in + ``axes`` +axes + Type Tind. + 1-D tensor of axes that ``starts`` and ``ends`` apply to. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(data). Behavior is undefined if an axis is repeated. +steps + Type Tind. + 1-D tensor of slice step of corresponding axis in ``axes``. Negative + value means slicing backward. 'steps' cannot be 0. Defaults to 1s. + +Returns +======= +output : Var + Type T. + Sliced data tensor. + +Notes +===== +Signature: ``ai.onnx@13::Slice``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return _Slice( + _Slice.Attributes( + ), _Slice.Inputs( + data=unwrap_vars(data), starts=unwrap_vars(starts), ends=unwrap_vars(ends), axes=unwrap_vars(axes), steps=unwrap_vars(steps), ), ).get_output_vars( + data=get_value(data), starts=get_value(starts), ends=get_value(ends), axes=get_value(axes), steps=get_value(steps), ).output + + +def softmax(input: Var, *, axis: int = -1, ) -> Var: + r""" +The operator computes the normalized exponential values for the given +input: + +Softmax(input, axis) = Exp(input) / ReduceSum(Exp(input), axis=axis, +keepdims=1) + +The "axis" attribute indicates the dimension along which Softmax will be +performed. The output tensor has the same shape and contains the Softmax +values of the corresponding input. + +Parameters +========== +input + Type T. + The input tensor of rank >= axis. +axis + Attribute. + Describes the dimension Softmax will be performed on. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(input). + +Returns +======= +output : Var + Type T. + The output values with the same shape as the input tensor. + +Notes +===== +Signature: ``ai.onnx@13::Softmax``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Softmax( + _Softmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _Softmax.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def softmax_cross_entropy_loss(scores: Var, labels: Var, weights: Optional[Var] = None, *, ignore_index: Optional[int] = None, reduction: str = "mean", ) -> tuple[Var, Var]: + r""" +Loss function that measures the softmax cross entropy between 'scores' +and 'labels'. This operator first computes a loss tensor whose shape is +identical to the labels input. If the input is 2-D with shape (N, C), +the loss tensor may be a N-element vector L = (l_1, l_2, ..., l_N). If +the input is N-D tensor with shape (N, C, D1, D2, ..., Dk), the loss +tensor L may have (N, D1, D2, ..., Dk) as its shape and +L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. After L is +available, this operator can optionally do a reduction operator. + +- shape(scores): (N, C) where C is the number of classes, or (N, C, D1, + D2,..., Dk), with K >= 1 in case of K-dimensional loss. +- shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, + D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. + +The loss for one sample, l_i, can calculated as follows: + +:: + + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes. + +or + +:: + + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided. + +loss is zero for the case when label-value equals ignore_index. + +:: + + l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index + +where: + +:: + + p = Softmax(scores) + y = Log(p) + c = labels[i][d1][d2]...[dk] + +Finally, L is optionally reduced: + +- If reduction = 'none', the output is L with shape (N, D1, D2, ..., + Dk). +- If reduction = 'sum', the output is scalar: Sum(L). +- If reduction = 'mean', the output is scalar: ReduceMean(L), or if + weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W + is of shape ``(N, D1, D2, ..., Dk)`` and + ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. + +Parameters +========== +scores + Type T. + The predicted outputs with shape [batch_size, class_size], or + [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of + dimensions. +labels + Type Tind. + The ground truth output tensor, with shape [batch_size], or [batch_size, + D1, D2, ..., Dk], where K is the number of dimensions. Labels element + value shall be in range of [0, C). If ignore_index is specified, it may + have a value outside [0, C) and the label values should either be in the + range [0, C) or have the value ignore_index. +weights + Type T. + A manual rescaling weight given to each class. If given, it has to be a + 1D Tensor assigning weight to each of the classes. Otherwise, it is + treated as if having all ones. +ignore_index + Attribute. + Specifies a target value that is ignored and does not contribute to the + input gradient. It's an optional value. +reduction + Attribute. + Type of reduction to apply to loss: none, sum, mean(default). 'none': no + reduction will be applied, 'sum': the output will be summed. 'mean': the + sum of the output will be divided by the number of elements in the + output. + +Returns +======= +output : Var + Type T. + Weighted loss float Tensor. If reduction is 'none', this has the shape + of [batch_size], or [batch_size, D1, D2, ..., Dk] in case of + K-dimensional loss. Otherwise, it is a scalar. +log_prob : Var + Type T. + Log probability tensor. If the output of softmax is prob, its value is + log(prob). + +Notes +===== +Signature: ``ai.onnx@13::SoftmaxCrossEntropyLoss``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return _SoftmaxCrossEntropyLoss( + _SoftmaxCrossEntropyLoss.Attributes( + ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), + reduction=AttrString(reduction, name="reduction"), + ), _SoftmaxCrossEntropyLoss.Inputs( + scores=unwrap_vars(scores), labels=unwrap_vars(labels), weights=unwrap_vars(weights), ), ).get_output_vars( + scores=get_value(scores), labels=get_value(labels), weights=get_value(weights), )._unpack_to_any() + + +def softplus(X: Var, ) -> Var: + r""" +Softplus takes one input data (Tensor) and produces one output data +(Tensor) where the softplus function, y = ln(exp(x) + 1), is applied +to the tensor elementwise. + +Parameters +========== +X + Type T. + 1D input tensor + +Returns +======= +Y : Var + Type T. + 1D input tensor + +Notes +===== +Signature: ``ai.onnx@1::Softplus``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Softplus( + _Softplus.Attributes( + ), _Softplus.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def softsign(input: Var, ) -> Var: + r""" +Calculates the softsign (x/(1+|x\|)) of the given input tensor +element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The softsign (x/(1+|x\|)) values of the input tensor computed + element-wise + +Notes +===== +Signature: ``ai.onnx@1::Softsign``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Softsign( + _Softsign.Attributes( + ), _Softsign.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def space_to_depth(input: Var, *, blocksize: int, ) -> Var: + r""" +SpaceToDepth rearranges blocks of spatial data into depth. More +specifically, this op outputs a copy of the input tensor where values +from the height and width dimensions are moved to the depth dimension. + +Parameters +========== +input + Type T. + Input tensor of [N,C,H,W], where N is the batch axis, C is the channel + or depth, H is the height and W is the width. +blocksize + Attribute. + Blocks of [blocksize, blocksize] are moved. + +Returns +======= +output : Var + Type T. + Output tensor of [N, C \* blocksize \* blocksize, H/blocksize, + W/blocksize]. + +Notes +===== +Signature: ``ai.onnx@13::SpaceToDepth``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _SpaceToDepth( + _SpaceToDepth.Attributes( + blocksize=AttrInt64(blocksize, name="blocksize"), + ), _SpaceToDepth.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def split(input: Var, split: Optional[Var] = None, *, outputs_count: int, axis: int = 0, ) -> Sequence[Var]: + r""" +Split a tensor into a list of tensors, along the specified 'axis'. +Lengths of the parts can be specified using input 'split'. Otherwise, +the tensor is split to equal sized parts. + +Parameters +========== +input + Type T. + The tensor to split +split + Type tensor(int64). + Optional length of each output. Values should be >= 0.Sum of the values + must be equal to the dim value at 'axis' specified. +axis + Attribute. + Which axis to split on. A negative value means counting dimensions from + the back. Accepted range is [-rank, rank-1] where r = rank(input). +outputs_count + Specifies the number of variadic outputs of this operator. + Non-standard parameter created by the opset generator, as inference (a solution) it was not implemented or is impossible. + +Returns +======= +outputs : Sequence[Var] + Type T. + One or more outputs forming list of tensors after splitting + +Notes +===== +Signature: ``ai.onnx@13::Split``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Split( + _Split.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _Split.Inputs( + input=unwrap_vars(input), split=unwrap_vars(split), ), out_variadic=outputs_count, ).get_output_vars( + input=get_value(input), split=get_value(split), ).outputs + + +def split_to_sequence(input: Var, split: Optional[Var] = None, *, axis: int = 0, keepdims: int = 1, ) -> Var: + r""" +Split a tensor into a sequence of tensors, along the specified 'axis'. +Lengths of the parts can be specified using the optional argument +'split'. If the argument +``split' is not specified, a default scalar value of 1 is used as the value of``\ split'. +'split' must contain only positive numbers. 'split' is either a scalar +(tensor of empty shape), or a 1-D tensor. If 'split' is a scalar, then +'input' will be split into chunks all of size 'split' if possible. The +last chunk alone may be smaller than 'split' if the 'input' size along +the given axis 'axis' is not divisible by 'split'. If 'split' is a +1-dimensional tensor, the input tensor is split into 'size(split)' +chunks, with lengths of the parts on 'axis' specified in 'split'. In +this scenario, the sum of entries in 'split' must be equal to the +dimension size of input tensor on 'axis'. + +Parameters +========== +input + Type T. + The tensor to split +split + Type I. + Length of each output. It can be either a scalar(tensor of empty shape), + or a 1-D tensor. All values must be >= 0. +axis + Attribute. + Which axis to split on. A negative value means counting dimensions from + the back. Accepted range is [-rank, rank-1]. +keepdims + Attribute. + Keep the split dimension or not. Default 1, which means we keep split + dimension. If input 'split' is specified, this attribute is ignored. + +Returns +======= +output_sequence : Var + Type S. + One or more outputs forming a sequence of tensors after splitting + +Notes +===== +Signature: ``ai.onnx@11::SplitToSequence``. + +Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - I: `tensor(int32)`, `tensor(int64)` + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + """ + return _SplitToSequence( + _SplitToSequence.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), _SplitToSequence.Inputs( + input=unwrap_vars(input), split=unwrap_vars(split), ), ).get_output_vars( + input=get_value(input), split=get_value(split), ).output_sequence + + +def sqrt(X: Var, ) -> Var: + r""" +Square root takes one input data (Tensor) and produces one output +data (Tensor) where the square root is, y = x^0.5, is applied to the +tensor elementwise. If x is negative, then it will return NaN. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@13::Sqrt``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Sqrt( + _Sqrt.Attributes( + ), _Sqrt.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def squeeze(data: Var, axes: Optional[Var] = None, ) -> Var: + r""" +Remove single-dimensional entries from the shape of a tensor. Takes an +input ``axes`` with a list of axes to squeeze. If ``axes`` is not +provided, all the single dimensions will be removed from the shape. If +an axis is selected with shape entry not equal to one, an error is +raised. + +Parameters +========== +data + Type T. + Tensors with at least max(dims) dimensions. +axes + Type tensor(int64). + List of integers indicating the dimensions to squeeze. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(data). + +Returns +======= +squeezed : Var + Type T. + Reshaped tensor with same data as input. + +Notes +===== +Signature: ``ai.onnx@13::Squeeze``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Squeeze( + _Squeeze.Attributes( + ), _Squeeze.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).squeezed + + +def string_normalizer(X: Var, *, case_change_action: str = "NONE", is_case_sensitive: int = 0, locale: Optional[str] = None, stopwords: Optional[Iterable[str]] = None, ) -> Var: + r""" +StringNormalization performs string operations for basic cleaning. This +operator has only one input (denoted by X) and only one output (denoted +by Y). This operator first examines the elements in the X, and removes +elements specified in "stopwords" attribute. After removing stop words, +the intermediate result can be further lowercased, uppercased, or just +returned depending the "case_change_action" attribute. This operator +only accepts [C]- and [1, C]-tensor. If all elements in X are dropped, +the output will be the empty value of string tensor with shape [1] if +input shape is [C] and shape [1, 1] if input shape is [1, C]. + +Parameters +========== +X + Type tensor(string). + UTF-8 strings to normalize +case_change_action + Attribute. + string enum that cases output to be lowercased/uppercases/unchanged. + Valid values are "LOWER", "UPPER", "NONE". Default is "NONE" +is_case_sensitive + Attribute. + Boolean. Whether the identification of stop words in X is + case-sensitive. Default is false +locale + Attribute. + Environment dependent string that denotes the locale according to which + output strings needs to be upper/lowercased.Default en_US or platform + specific equivalent as decided by the implementation. +stopwords + Attribute. + List of stop words. If not set, no word would be removed from X. + +Returns +======= +Y : Var + Type tensor(string). + UTF-8 Normalized strings + +Notes +===== +Signature: ``ai.onnx@10::StringNormalizer``. + + """ + return _StringNormalizer( + _StringNormalizer.Attributes( + case_change_action=AttrString(case_change_action, name="case_change_action"), + is_case_sensitive=AttrInt64(is_case_sensitive, name="is_case_sensitive"), + locale=AttrString.maybe(locale, name="locale"), + stopwords=AttrStrings.maybe(stopwords, name="stopwords"), + ), _StringNormalizer.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def sub(A: Var, B: Var, ) -> Var: + r""" +Performs element-wise binary subtraction (with Numpy-style broadcasting +support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +(Opset 14 change): Extend supported types to include uint8, int8, +uint16, and int16. + +Parameters +========== +A + Type T. + First operand. +B + Type T. + Second operand. + +Returns +======= +C : Var + Type T. + Result, has same element type as two inputs + +Notes +===== +Signature: ``ai.onnx@14::Sub``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Sub( + _Sub.Attributes( + ), _Sub.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def sum(data_0: Sequence[Var], ) -> Var: + r""" +Element-wise sum of each of the input tensors (with Numpy-style +broadcasting support). All inputs and outputs must have the same data +type. This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +data_0 + Type T. + List of tensors for sum. + +Returns +======= +sum : Var + Type T. + Output tensor. + +Notes +===== +Signature: ``ai.onnx@13::Sum``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Sum( + _Sum.Attributes( + ), _Sum.Inputs( + data_0=unwrap_vars(data_0), ), ).get_output_vars( + data_0=get_value(data_0), ).sum + + +def tan(input: Var, ) -> Var: + r""" +Calculates the tangent of the given input tensor, element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The tangent of the input tensor computed element-wise + +Notes +===== +Signature: ``ai.onnx@7::Tan``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Tan( + _Tan.Attributes( + ), _Tan.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def tanh(input: Var, ) -> Var: + r""" +Calculates the hyperbolic tangent of the given input tensor +element-wise. + +Parameters +========== +input + Type T. + Input tensor + +Returns +======= +output : Var + Type T. + The hyperbolic tangent values of the input tensor computed element-wise + +Notes +===== +Signature: ``ai.onnx@13::Tanh``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Tanh( + _Tanh.Attributes( + ), _Tanh.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def tf_idf_vectorizer(X: Var, *, max_gram_length: int, max_skip_count: int, min_gram_length: int, mode: str, ngram_counts: Iterable[int], ngram_indexes: Iterable[int], pool_int64s: Optional[Iterable[int]] = None, pool_strings: Optional[Iterable[str]] = None, weights: Optional[Iterable[float]] = None, ) -> Var: + r""" +This transform extracts n-grams from the input sequence and save them as +a vector. Input can be either a 1-D or 2-D tensor. For 1-D input, output +is the n-gram representation of that input. For 2-D input, the output is +also a 2-D tensor whose i-th row is the n-gram representation of the +i-th input row. More specifically, if input shape is [C], the +corresponding output shape would be [max(ngram_indexes) + 1]. If input +shape is [N, C], this operator produces a [N, max(ngram_indexes) + +1]-tensor. + +In contrast to standard n-gram extraction, here, the indexes of +extracting an n-gram from the original sequence are not necessarily +consecutive numbers. The discontinuity between indexes are controlled by +the number of skips. If the number of skips is 2, we should skip two +tokens when scanning through the original sequence. Let's consider an +example. Assume that input sequence is [94, 17, 36, 12, 28] and the +number of skips is 2. The associated 2-grams are [94, 12] and [17, 28] +respectively indexed by [0, 3] and [1, 4]. If the number of skips +becomes 0, the 2-grams generated are [94, 17], [17, 36], [36, 12], [12, +28] indexed by [0, 1], [1, 2], [2, 3], [3, 4], respectively. + +The output vector (denoted by Y) stores the count of each n-gram; +Y[ngram_indexes[i]] indicates the times that the i-th n-gram is found. +The attribute ngram_indexes is used to determine the mapping between +index i and the corresponding n-gram's output coordinate. If pool_int64s +is [94, 17, 17, 36], ngram_indexes is [1, 0], ngram_counts=[0, 0], then +the Y[0] (first element in Y) and Y[1] (second element in Y) are the +counts of [17, 36] and [94, 17], respectively. An n-gram which cannot be +found in pool_strings/pool_int64s should be ignored and has no effect on +the output. Note that we may consider all skips up to S when generating +the n-grams. + +The examples used above are true if mode is "TF". If mode is "IDF", all +the counts larger than 1 would be truncated to 1 and the i-th element in +weights would be used to scale (by multiplication) the count of the i-th +n-gram in pool. If mode is "TFIDF", this operator first computes the +counts of all n-grams and then scale them by the associated values in +the weights attribute. + +Only one of pool_strings and pool_int64s can be set. If pool_int64s is +set, the input should be an integer tensor. If pool_strings is set, the +input must be a string tensor. + +Parameters +========== +X + Type T. + Input for n-gram extraction +max_gram_length + Attribute. + Maximum n-gram length. If this value is 3, 3-grams will be used to + generate the output. +max_skip_count + Attribute. + Maximum number of items (integers/strings) to be skipped when + constructing an n-gram from X. If max_skip_count=1, min_gram_length=2, + max_gram_length=3, this operator may generate 2-grams with skip_count=0 + and skip_count=1, and 3-grams with skip_count=0 and skip_count=1 +min_gram_length + Attribute. + Minimum n-gram length. If this value is 2 and max_gram_length is 3, + output may contain counts of 2-grams and 3-grams. +mode + Attribute. + The weighting criteria. It can be one of "TF" (term frequency), "IDF" + (inverse document frequency), and "TFIDF" (the combination of TF and + IDF) +ngram_counts + Attribute. + The starting indexes of 1-grams, 2-grams, and so on in pool. It is + useful when determining the boundary between two consecutive collections + of n-grams. For example, if ngram_counts is [0, 17, 36], the first index + (zero-based) of 1-gram/2-gram/3-gram in pool are 0/17/36. This format is + essentially identical to CSR (or CSC) sparse matrix format, and we + choose to use this due to its popularity. +ngram_indexes + Attribute. + list of int64s (type: AttributeProto::INTS). This list is parallel to + the specified 'pool\_\*' attribute. The i-th element in ngram_indexes + indicate the coordinate of the i-th n-gram in the output tensor. +pool_int64s + Attribute. + List of int64 n-grams learned from the training set. Either this or + pool_strings attributes must be present but not both. It's an 1-D tensor + starting with the collections of all 1-grams and ending with the + collections of n-grams. The i-th element in pool stores the n-gram that + should be mapped to coordinate ngram_indexes[i] in the output vector. +pool_strings + Attribute. + List of strings n-grams learned from the training set. Either this or + pool_int64s attributes must be present but not both. It's an 1-D tensor + starting with the collections of all 1-grams and ending with the + collections of n-grams. The i-th element in pool stores the n-gram that + should be mapped to coordinate ngram_indexes[i] in the output vector. +weights + Attribute. + list of floats. This attribute stores the weight of each n-gram in pool. + The i-th element in weights is the weight of the i-th n-gram in pool. + Its length equals to the size of ngram_indexes. By default, weights is + an all-one tensor.This attribute is used when mode is "IDF" or "TFIDF" + to scale the associated word counts. + +Returns +======= +Y : Var + Type T1. + Ngram results + +Notes +===== +Signature: ``ai.onnx@9::TfIdfVectorizer``. + +Type constraints: + - T: `tensor(int32)`, `tensor(int64)`, `tensor(string)` + - T1: `tensor(float)` + """ + return _TfIdfVectorizer( + _TfIdfVectorizer.Attributes( + max_gram_length=AttrInt64(max_gram_length, name="max_gram_length"), + max_skip_count=AttrInt64(max_skip_count, name="max_skip_count"), + min_gram_length=AttrInt64(min_gram_length, name="min_gram_length"), + mode=AttrString(mode, name="mode"), + ngram_counts=AttrInt64s(ngram_counts, name="ngram_counts"), + ngram_indexes=AttrInt64s(ngram_indexes, name="ngram_indexes"), + pool_int64s=AttrInt64s.maybe(pool_int64s, name="pool_int64s"), + pool_strings=AttrStrings.maybe(pool_strings, name="pool_strings"), + weights=AttrFloat32s.maybe(weights, name="weights"), + ), _TfIdfVectorizer.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def thresholded_relu(X: Var, *, alpha: float = 1.0, ) -> Var: + r""" +ThresholdedRelu takes one input data (Tensor) and produces one output +data (Tensor) where the rectified linear function, y = x for x > +alpha, y = 0 otherwise, is applied to the tensor elementwise. + +Parameters +========== +X + Type T. + Input tensor +alpha + Attribute. + Threshold value + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@10::ThresholdedRelu``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _ThresholdedRelu( + _ThresholdedRelu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), _ThresholdedRelu.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def tile(input: Var, repeats: Var, ) -> Var: + r""" +Constructs a tensor by tiling a given tensor. This is the same as +function ``tile`` in Numpy, but no broadcast. For example A = [[1, 2], +[3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]] + +Parameters +========== +input + Type T. + Input tensor of any shape. +repeats + Type T1. + 1D int64 tensor of the same length as input's dimension number, includes + numbers of repeated copies along input's dimensions. + +Returns +======= +output : Var + Type T. + Output tensor of the same dimensions and type as tensor input. + output_dim[i] = input_dim[i] \* repeats[i] + +Notes +===== +Signature: ``ai.onnx@13::Tile``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` + """ + return _Tile( + _Tile.Attributes( + ), _Tile.Inputs( + input=unwrap_vars(input), repeats=unwrap_vars(repeats), ), ).get_output_vars( + input=get_value(input), repeats=get_value(repeats), ).output + + +def top_k(X: Var, K: Var, *, axis: int = -1, largest: int = 1, sorted: int = 1, ) -> tuple[Var, Var]: + r""" +Retrieve the top-K largest or smallest elements along a specified axis. +Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer +argument k, return two outputs: + +- Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a\_{n-1}] which contains the values of the top k elements along + the specified axis + +- Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a\_{n-1}] which contains the indices of the top k elements + (original indices from the input tensor). + +- If "largest" is 1 (the default value) then the k largest elements are + returned. + +- If "sorted" is 1 (the default value) then the resulting k elements + will be sorted. + +- If "sorted" is 0, order of returned 'Values' and 'Indices' are + undefined. + +Given two equivalent values, this operator uses the indices along the +axis as a tiebreaker. That is, the element with the lower index will +appear first. + +Parameters +========== +X + Type T. + Tensor of shape [a_0, a_1, ..., a\_{n-1}] +K + Type tensor(int64). + A 1-D tensor containing a single positive value corresponding to the + number of top elements to retrieve +axis + Attribute. + Dimension on which to do the sort. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). +largest + Attribute. + Whether to return the top-K largest or smallest elements. +sorted + Attribute. + Whether to return the elements in sorted order. + +Returns +======= +Values : Var + Type T. + Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] containing top K values from the input tensor +Indices : Var + Type I. + Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] containing the corresponding input tensor indices for the top + K values. + +Notes +===== +Signature: ``ai.onnx@11::TopK``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - I: `tensor(int64)` + """ + return _TopK( + _TopK.Attributes( + axis=AttrInt64(axis, name="axis"), + largest=AttrInt64(largest, name="largest"), + sorted=AttrInt64(sorted, name="sorted"), + ), _TopK.Inputs( + X=unwrap_vars(X), K=unwrap_vars(K), ), ).get_output_vars( + X=get_value(X), K=get_value(K), )._unpack_to_any() + + +def transpose(data: Var, *, perm: Optional[Iterable[int]] = None, ) -> Var: + r""" +Transpose the input tensor similar to numpy.transpose. For example, when +perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output +shape will be (2, 1, 3). + +Parameters +========== +data + Type T. + An input tensor. +perm + Attribute. + A list of integers. By default, reverse the dimensions, otherwise + permute the axes according to the values given. + +Returns +======= +transposed : Var + Type T. + Transposed output. + +Notes +===== +Signature: ``ai.onnx@13::Transpose``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Transpose( + _Transpose.Attributes( + perm=AttrInt64s.maybe(perm, name="perm"), + ), _Transpose.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).transposed + + +def trilu(input: Var, k: Optional[Var] = None, *, upper: int = 1, ) -> Var: + r""" +Given a 2-D matrix or batches of 2-D matrices, returns the upper or +lower triangular part of the tensor(s). The attribute "upper" determines +whether the upper or lower part is retained. If set to true, the upper +triangular matrix is retained. Lower triangular matrix is retained +otherwise. Default value for the "upper" attribute is true. Trilu takes +one input tensor of shape [\*, N, M], where \* is zero or more batch +dimensions. The upper triangular part consists of the elements on and +above the given diagonal (k). The lower triangular part consists of +elements on and below the diagonal. All other elements in the matrix are +set to zero. If k = 0, the triangular part on and above/below the main +diagonal is retained. If upper is set to true, a positive k retains the +upper triangular matrix excluding the main diagonal and (k-1) diagonals +above it. A negative k value retains the main diagonal and \|k\| +diagonals below it. If upper is set to false, a positive k retains the +lower triangular matrix including the main diagonal and k diagonals +above it. A negative k value excludes the main diagonal and (\|k\|-1) +diagonals below it. + +Parameters +========== +input + Type T. + Input tensor of rank 2 or higher. +k + Type tensor(int64). + A 0-D tensor containing a single value corresponding to the number + diagonals above or below the main diagonal to exclude or include. + Default value is 0 if it's not specified. +upper + Attribute. + Boolean. Indicates whether upper or lower part of matrix is retained. + Default is true. + +Returns +======= +output : Var + Type T. + Output tensor of the same type and shape as the input tensor. + +Notes +===== +Signature: ``ai.onnx@14::Trilu``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Trilu( + _Trilu.Attributes( + upper=AttrInt64(upper, name="upper"), + ), _Trilu.Inputs( + input=unwrap_vars(input), k=unwrap_vars(k), ), ).get_output_vars( + input=get_value(input), k=get_value(k), ).output + + +def unique(X: Var, *, axis: Optional[int] = None, sorted: int = 1, ) -> tuple[Var, Var, Var, Var]: + r""" +Find the unique elements of a tensor. When an optional attribute 'axis' +is provided, unique subtensors sliced along the 'axis' are returned. +Otherwise the input tensor is flattened and unique values of the +flattened tensor are returned. -def clip( - input: Var, - min: Optional[Var] = None, - max: Optional[Var] = None, -) -> Var: - r""" - Clip operator limits the given input within an interval. The interval is - specified by the inputs 'min' and 'max'. They default to - numeric_limits::lowest() and numeric_limits::max(), respectively. - - Parameters - ========== - input - Type T. - Input tensor whose elements to be clipped - min - Type T. - Minimum value, under which element is replaced by min. It must be a - scalar(tensor of empty shape). - max - Type T. - Maximum value, above which element is replaced by max. It must be a - scalar(tensor of empty shape). - - Returns - ======= - output : Var - Type T. - Output tensor with clipped input elements - - Notes - ===== - Signature: ``ai.onnx@13::Clip``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Clip( - _Clip.Attributes(), - _Clip.Inputs( - input=unwrap_vars(input), - min=unwrap_vars(min), - max=unwrap_vars(max), - ), - ) - .get_output_vars( - input=get_value(input), - min=get_value(min), - max=get_value(max), - ) - .output - ) - - -def compress( - input: Var, - condition: Var, - *, - axis: Optional[int] = None, -) -> Var: - r""" - Selects slices from an input tensor along a given axis where condition - evaluates to True for each axis index. In case axis is not provided, - input is flattened before elements are selected. Compress behaves like - numpy.compress: - https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html - - Parameters - ========== - input - Type T. - Tensor of rank r >= 1. - condition - Type T1. - Rank 1 tensor of booleans to indicate which slices or data elements to - be selected. Its length can be less than the input length along the axis - or the flattened input size if axis is not specified. In such cases data - slices or elements exceeding the condition length are discarded. - axis - Attribute. - (Optional) Axis along which to take slices. If not specified, input is - flattened before elements being selected. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - - Returns - ======= - output : Var - Type T. - Tensor of rank r if axis is specified. Otherwise output is a Tensor of - rank 1. - - Notes - ===== - Signature: ``ai.onnx@11::Compress``. - - Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return ( - _Compress( - _Compress.Attributes( - axis=AttrInt64.maybe(axis, name="axis"), - ), - _Compress.Inputs( - input=unwrap_vars(input), - condition=unwrap_vars(condition), - ), - ) - .get_output_vars( - input=get_value(input), - condition=get_value(condition), - ) - .output - ) - - -def concat( - inputs: Sequence[Var], - *, - axis: int, -) -> Var: - r""" - Concatenate a list of tensors into a single tensor. All input tensors - must have the same shape, except for the dimension size of the axis to - concatenate on. - - Parameters - ========== - inputs - Type T. - List of tensors for concatenation - axis - Attribute. - Which axis to concat on. A negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(inputs).. - - Returns - ======= - concat_result : Var - Type T. - Concatenated tensor - - Notes - ===== - Signature: ``ai.onnx@13::Concat``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Concat( - _Concat.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Concat.Inputs( - inputs=unwrap_vars(inputs), - ), - ) - .get_output_vars( - inputs=get_value(inputs), - ) - .concat_result - ) - - -def concat_from_sequence( - input_sequence: Var, - *, - axis: int, - new_axis: int = 0, -) -> Var: - r""" - Concatenate a sequence of tensors into a single tensor. All input - tensors must have the same shape, except for the dimension size of the - axis to concatenate on. By default 'new_axis' is 0, the behavior is - similar to numpy.concatenate. When 'new_axis' is 1, the behavior is - similar to numpy.stack. - - Parameters - ========== - input_sequence - Type S. - Sequence of tensors for concatenation - axis - Attribute. - Which axis to concat on. Accepted range in ``[-r, r - 1]``, where ``r`` - is the rank of input tensors. When ``new_axis`` is 1, accepted range is - ``[-r - 1, r]``. - new_axis - Attribute. - Insert and concatenate on a new axis or not, default 0 means do not - insert new axis. - - Returns - ======= - concat_result : Var - Type T. - Concatenated tensor - - Notes - ===== - Signature: ``ai.onnx@11::ConcatFromSequence``. - - Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _ConcatFromSequence( - _ConcatFromSequence.Attributes( - axis=AttrInt64(axis, name="axis"), - new_axis=AttrInt64(new_axis, name="new_axis"), - ), - _ConcatFromSequence.Inputs( - input_sequence=unwrap_vars(input_sequence), - ), - ) - .get_output_vars( - input_sequence=get_value(input_sequence), - ) - .concat_result - ) - - -def constant( - *, - value: Optional[np.ndarray] = None, - value_float: Optional[float] = None, - value_floats: Optional[Iterable[float]] = None, - value_int: Optional[int] = None, - value_ints: Optional[Iterable[int]] = None, - value_string: Optional[str] = None, - value_strings: Optional[Iterable[str]] = None, -) -> Var: - r""" - This operator produces a constant tensor. Exactly one of the provided - attributes, either value, sparse_value, or value\_\* must be specified. - - Parameters - ========== - sparse_value - Attribute. - The value for the elements of the output tensor in sparse format. - value - Attribute. - The value for the elements of the output tensor. - value_float - Attribute. - The value for the sole element for the scalar, float32, output tensor. - value_floats - Attribute. - The values for the elements for the 1D, float32, output tensor. - value_int - Attribute. - The value for the sole element for the scalar, int64, output tensor. - value_ints - Attribute. - The values for the elements for the 1D, int64, output tensor. - value_string - Attribute. - The value for the sole element for the scalar, UTF-8 string, output - tensor. - value_strings - Attribute. - The values for the elements for the 1D, UTF-8 string, output tensor. - - Returns - ======= - output : Var - Type T. - Output tensor containing the same value of the provided tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Constant``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), - _Constant.Inputs(), - ) - .get_output_vars() - .output - ) - - -def constant_of_shape( - input: Var, - *, - value: Optional[np.ndarray] = None, -) -> Var: - r""" - Generate a tensor with given value and shape. - - Parameters - ========== - input - Type T1. - 1D tensor. The shape of the expected output tensor. If empty tensor is - given, the output would be a scalar. All values must be >= 0. - value - Attribute. - (Optional) The value of the output elements.Should be a one-element - tensor. If not specified, it defaults to a tensor of value 0 and - datatype float32 - - Returns - ======= - output : Var - Type T2. - Output tensor of shape specified by 'input'.If attribute 'value' is - specified, the value and datatype of the output tensor is taken from - 'value'.If attribute 'value' is not specified, the value in the output - defaults to 0, and the datatype defaults to float32. - - Notes - ===== - Signature: ``ai.onnx@9::ConstantOfShape``. - - Type constraints: - - T1: `tensor(int64)` - - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), - _ConstantOfShape.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def conv( - X: Var, - W: Var, - B: Optional[Var] = None, - *, - auto_pad: str = "NOTSET", - dilations: Optional[Iterable[int]] = None, - group: int = 1, - kernel_shape: Optional[Iterable[int]] = None, - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: - r""" - The convolution operator consumes an input tensor and a filter, and - computes the output. - - Parameters - ========== - X - Type T. - Input data tensor from previous layer; has size (N x C x H x W), where N - is the batch size, C is the number of channels, and H and W are the - height and width. Note that this is for the 2D image. Otherwise the size - is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in - effect, the operation expects input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. - W - Type T. - The weight tensor that will be used in the convolutions; has size (M x - C/group x kH x kW), where C is the number of channels, and kH and kW are - the height and width of the kernel, and M is the number of feature maps. - For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x - k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. - Optionally, if dimension denotation is in effect, the operation expects - the weight tensor to arrive with the dimension denotation of - [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL - ...]. Assuming zero based indices for the shape array, X.shape[1] == - (W.shape[1] \* group) == C and W.shape[0] mod G == 0. Or in other words - FILTER_IN_CHANNEL multiplied by the number of groups should be equal to - DATA_CHANNEL and the number of feature maps M should be a multiple of - the number of groups G. - B - Type T. - Optional 1D bias to be added to the convolution, has size of M. - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. - dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults is 1 along each spatial axis. - group - Attribute. - number of groups input channels and output channels are divided into. - kernel_shape - Attribute. - The shape of the convolution kernel. If not present, should be inferred - from input W. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults is 1 - along each spatial axis. - - Returns - ======= - Y : Var - Type T. - Output data tensor that contains the result of the convolution. The - output dimensions are functions of the kernel size, stride size, and pad - lengths. - - Notes - ===== - Signature: ``ai.onnx@11::Conv``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Conv( - _Conv.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _Conv.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - X=get_value(X), - W=get_value(W), - B=get_value(B), - ) - .Y - ) - - -def conv_integer( - x: Var, - w: Var, - x_zero_point: Optional[Var] = None, - w_zero_point: Optional[Var] = None, - *, - auto_pad: str = "NOTSET", - dilations: Optional[Iterable[int]] = None, - group: int = 1, - kernel_shape: Optional[Iterable[int]] = None, - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: - r""" - The integer convolution operator consumes an input tensor, its - zero-point, a filter, and its zero-point, and computes the output. The - production MUST never overflow. The accumulation may overflow if and - only if in 32 bits. - - Parameters - ========== - x - Type T1. - Input data tensor from previous layer; has size (N x C x H x W), where N - is the batch size, C is the number of channels, and H and W are the - height and width. Note that this is for the 2D image. Otherwise the size - is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in - effect, the operation expects input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. - w - Type T2. - The weight tensor that will be used in the convolutions; has size (M x - C/group x kH x kW), where C is the number of channels, and kH and kW are - the height and width of the kernel, and M is the number of feature maps. - For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x - k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. - Optionally, if dimension denotation is in effect, the operation expects - the weight tensor to arrive with the dimension denotation of - [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL - ...]. X.shape[1] == (W.shape[1] \* group) == C (assuming zero based - indices for the shape array). Or in other words FILTER_IN_CHANNEL should - be equal to DATA_CHANNEL. - x_zero_point - Type T1. - Zero point tensor for input 'x'. It's optional and default value is 0. - It's a scalar, which means a per-tensor/layer quantization. - w_zero_point - Type T2. - Zero point tensor for input 'w'. It's optional and default value is 0. - It could be a scalar or a 1-D tensor, which means a per-tensor/layer or - per output channel quantization. If it's a 1-D tensor, its number of - elements should be equal to the number of output channels (M) - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. - dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults to 1 along each axis. - group - Attribute. - number of groups input channels and output channels are divided into. - default is 1. - kernel_shape - Attribute. - The shape of the convolution kernel. If not present, should be inferred - from input 'w'. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0.The value represent the number - of pixels added to the beginning and end part of the corresponding - axis.\ ``pads`` format should be as follow [x1_begin, x2_begin...x1_end, - x2_end,...], where xi_begin the number ofpixels added at the beginning - of axis ``i`` and xi_end, the number of pixels added at the end of axis - ``i``.This attribute cannot be used simultaneously with auto_pad - attribute. If not present, the padding defaultsto 0 along start and end - of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each axis. - - Returns - ======= - y : Var - Type T3. - Output data tensor that contains the result of the convolution. The - output dimensions are functions of the kernel size, stride size, and pad - lengths. - - Notes - ===== - Signature: ``ai.onnx@10::ConvInteger``. - - Type constraints: - - T1: `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(int32)` - """ - return ( - _ConvInteger( - _ConvInteger.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _ConvInteger.Inputs( - x=unwrap_vars(x), - w=unwrap_vars(w), - x_zero_point=unwrap_vars(x_zero_point), - w_zero_point=unwrap_vars(w_zero_point), - ), - ) - .get_output_vars( - x=get_value(x), - w=get_value(w), - x_zero_point=get_value(x_zero_point), - w_zero_point=get_value(w_zero_point), - ) - .y - ) - - -def conv_transpose( - X: Var, - W: Var, - B: Optional[Var] = None, - *, - auto_pad: str = "NOTSET", - dilations: Optional[Iterable[int]] = None, - group: int = 1, - kernel_shape: Optional[Iterable[int]] = None, - output_padding: Optional[Iterable[int]] = None, - output_shape: Optional[Iterable[int]] = None, - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: - r""" - The convolution transpose operator consumes an input tensor and a - filter, and computes the output. - - If the pads parameter is provided the shape of the output is calculated - via the following equation: - - output_shape[i] = stride[i] \* (input_size[i] - 1) + output_padding[i] + - ((kernel_shape[i] - 1) \* dilations[i] + 1) - pads[start_i] - - pads[end_i] - - output_shape can also be explicitly specified in which case pads values - are auto generated using these equations: - - total_padding[i] = stride[i] \* (input_size[i] - 1) + output_padding[i] - + ((kernel_shape[i] - 1) \* dilations[i] + 1) - output_shape[i] If - (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; - pads[end_i] = total_padding[i] - (total_padding[i]/2) Else: - pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = - (total_padding[i]/2). - - Parameters - ========== - X - Type T. - Input data tensor from previous layer; has size (N x C x H x W), where N - is the batch size, C is the number of channels, and H and W are the - height and width. Note that this is for the 2D image. Otherwise the size - is (N x C x D1 x D2 ... x Dn) - W - Type T. - The weight tensor that will be used in the convolutions; has size (C x - M/group x kH x kW), where C is the number of channels, and kH and kW are - the height and width of the kernel, and M is the number of feature maps. - For more than 2 dimensions, the weight shape will be (C x M/group x k1 x - k2 x ... x kn), where (k1 x k2 x ... x kn) is the dimension of the - kernel. The number of channels in the output should be equal to - W.shape[1] \* group (assuming zero based indices of the shape array) - B - Type T. - Optional 1D bias to be added to the convolution, has size of M. - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = input_shape[i] * strides[i]`` for each axis ``i``. - The padding is split between the two sides equally or almost equally - (depending on whether it is even or odd). In case the padding is an odd - number, the extra padding is added at the end for SAME_UPPER and at the - beginning for SAME_LOWER. - dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults to 1 along each spatial axis. - group - Attribute. - number of groups input channels and output channels are divided into. - kernel_shape - Attribute. - The shape of the convolution kernel. If not present, should be inferred - from input W. - output_padding - Attribute. - Additional elements added to the side with higher coordinate indices in - the output. Each padding value in "output_padding" must be less than the - corresponding stride/dilation dimension. By default, this attribute is a - zero vector. Note that this attribute doesn't directly affect the - computed output values. It only controls the selection of the computed - values, so changing this attribute only adds or removes output elements. - If "output_shape" is explicitly provided, "output_padding" does not - contribute additional size to "output_shape" but participates in the - computation of the needed padding amount. This is also called adjs or - adjustment in some frameworks. - output_shape - Attribute. - The shape of the output can be explicitly set which will cause pads - values to be auto generated. If output_shape is specified pads values - are ignored. See doc for details for equations to generate pads. Note - that the output_shape attribute value should not include dimensions for - batch size and channels, which are automatically inferred. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - - Returns - ======= - Y : Var - Type T. - Output data tensor that contains the result of the convolution. The - output dimensions are functions of the kernel size, stride size, pad - lengths and group count. The number of channels in the output should be - equal to W.shape[1] \* group (assuming zero based indices of the shape - array) - - Notes - ===== - Signature: ``ai.onnx@11::ConvTranspose``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _ConvTranspose( - _ConvTranspose.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - output_padding=AttrInt64s.maybe(output_padding, name="output_padding"), - output_shape=AttrInt64s.maybe(output_shape, name="output_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _ConvTranspose.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - X=get_value(X), - W=get_value(W), - B=get_value(B), - ) - .Y - ) - - -def cos( - input: Var, -) -> Var: - r""" - Calculates the cosine of the given input tensor, element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The cosine of the input tensor computed element-wise - - Notes - ===== - Signature: ``ai.onnx@7::Cos``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Cos( - _Cos.Attributes(), - _Cos.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def cosh( - input: Var, -) -> Var: - r""" - Calculates the hyperbolic cosine of the given input tensor element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The hyperbolic cosine values of the input tensor computed element-wise - - Notes - ===== - Signature: ``ai.onnx@9::Cosh``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Cosh( - _Cosh.Attributes(), - _Cosh.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def cumsum( - x: Var, - axis: Var, - *, - exclusive: int = 0, - reverse: int = 0, -) -> Var: - r""" - Performs cumulative sum of the input elements along the given axis. By - default, it will do the sum inclusively meaning the first element is - copied as is. Through an ``exclusive`` attribute, this behavior can - change to exclude the first element. It can also perform summation in - the opposite direction of the axis. For that, set ``reverse`` attribute - to 1. - - Example: - - :: - - input_x = [1, 2, 3] - axis=0 - output = [1, 3, 6] - exclusive=1 - output = [0, 1, 3] - exclusive=0 - reverse=1 - output = [6, 5, 3] - exclusive=1 - reverse=1 - output = [5, 3, 0] - - Parameters - ========== - x - Type T. - An input tensor that is to be processed. - axis - Type T2. - A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value - means counting dimensions from the back. - exclusive - Attribute. - If set to 1 will return exclusive sum in which the top element is not - included. In other terms, if set to 1, the j-th output element would be - the sum of the first (j-1) elements. Otherwise, it would be the sum of - the first j elements. - reverse - Attribute. - If set to 1 will perform the sums in reverse direction. - - Returns - ======= - y : Var - Type T. - Output tensor of the same type as 'x' with cumulative sums of the x's - elements - - Notes - ===== - Signature: ``ai.onnx@14::CumSum``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return ( - _CumSum( - _CumSum.Attributes( - exclusive=AttrInt64(exclusive, name="exclusive"), - reverse=AttrInt64(reverse, name="reverse"), - ), - _CumSum.Inputs( - x=unwrap_vars(x), - axis=unwrap_vars(axis), - ), - ) - .get_output_vars( - x=get_value(x), - axis=get_value(axis), - ) - .y - ) - - -def dft( - input: Var, - dft_length: Optional[Var] = None, - *, - axis: int = 1, - inverse: int = 0, - onesided: int = 0, -) -> Var: - r""" - Computes the discrete Fourier transform of input. - - Parameters - ========== - input - Type T1. - For real input, the following shape is expected: - [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][1]. For complex - input, the following shape is expected: - [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][2]. The first - dimension is the batch dimension. The following N dimensions correspond - to the signal's dimensions. The final dimension represents the real and - imaginary parts of the value in that order. - dft_length - Type T2. - The length of the signal as a scalar. If greater than the axis - dimension, the signal will be zero-padded up to dft_length. If less than - the axis dimension, only the first dft_length values will be used as the - signal. It's an optional value. - axis - Attribute. - The axis on which to perform the DFT. By default this value is set to 1, - which corresponds to the first dimension after the batch index. Negative - value means counting dimensions from the back. Accepted range is - :math:`[-r, -2] \cup [0, r-2]` where ``r = rank(input)``. The last - dimension is for representing complex numbers and thus is an invalid - axis. - inverse - Attribute. - Whether to perform the inverse discrete fourier transform. By default - this value is set to 0, which corresponds to false. - onesided - Attribute. - If onesided is 1, only values for w in [0, 1, 2, ..., floor(n_fft/2) + - 1] are returned because the real-to-complex Fourier transform satisfies - the conjugate symmetry, i.e., X[m, w] = X[m, n_fft-w]\*. Note if the - input or window tensors are complex, then onesided output is not - possible. Enabling onesided with real inputs performs a Real-valued fast - Fourier transform (RFFT). When invoked with real or complex valued - input, the default value is 0. Values can be 0 or 1. - - Returns - ======= - output : Var - Type T1. - The Fourier Transform of the input vector. If onesided is 0, the - following shape is expected: - [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][2]. If axis=1 and - onesided is 1, the following shape is expected: - [batch_idx][floor(signal_dim1/2)+1][signal_dim2]...[signal_dimN][2]. If - axis=2 and onesided is 1, the following shape is expected: - [batch_idx][signal_dim1][floor(signal_dim2/2)+1]...[signal_dimN][2]. If - axis=N and onesided is 1, the following shape is expected: - [batch_idx][signal_dim1][signal_dim2]...[floor(signal_dimN/2)+1][2]. The - signal_dim at the specified axis is equal to the dft_length. - - Notes - ===== - Signature: ``ai.onnx@17::DFT``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return ( - _DFT( - _DFT.Attributes( - axis=AttrInt64(axis, name="axis"), - inverse=AttrInt64(inverse, name="inverse"), - onesided=AttrInt64(onesided, name="onesided"), - ), - _DFT.Inputs( - input=unwrap_vars(input), - dft_length=unwrap_vars(dft_length), - ), - ) - .get_output_vars( - input=get_value(input), - dft_length=get_value(dft_length), - ) - .output - ) - - -def depth_to_space( - input: Var, - *, - blocksize: int, - mode: str = "DCR", -) -> Var: - r""" - DepthToSpace rearranges (permutes) data from depth into blocks of - spatial data. This is the reverse transformation of SpaceToDepth. More - specifically, this op outputs a copy of the input tensor where values - from the depth dimension are moved in spatial blocks to the height and - width dimensions. By default, ``mode`` = ``DCR``. In the DCR mode, - elements along the depth dimension from the input tensor are rearranged - in the following order: depth, column, and then row. The output y is - computed from the input x as below: - - :: - - b, c, h, w = x.shape - tmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w]) - tmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2]) - y = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize]) - - In the CRD mode, elements along the depth dimension from the input - tensor are rearranged in the following order: column, row, and the - depth. The output y is computed from the input x as below: - - :: - - b, c, h, w = x.shape - tmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w]) - tmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3]) - y = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize]) - - Parameters - ========== - input - Type T. - Input tensor of [N,C,H,W], where N is the batch axis, C is the channel - or depth, H is the height and W is the width. - blocksize - Attribute. - Blocks of [blocksize, blocksize] are moved. - mode - Attribute. - DCR (default) for depth-column-row order re-arrangement. Use CRD for - column-row-depth order. - - Returns - ======= - output : Var - Type T. - Output tensor of [N, C/(blocksize \* blocksize), H \* blocksize, W \* - blocksize]. - - Notes - ===== - Signature: ``ai.onnx@13::DepthToSpace``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _DepthToSpace( - _DepthToSpace.Attributes( - blocksize=AttrInt64(blocksize, name="blocksize"), - mode=AttrString(mode, name="mode"), - ), - _DepthToSpace.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def dequantize_linear( - x: Var, - x_scale: Var, - x_zero_point: Optional[Var] = None, - *, - axis: int = 1, -) -> Var: - r""" - The linear dequantization operator. It consumes a quantized tensor, a - scale, and a zero point to compute the full precision tensor. The - dequantization formula is ``y = (x - x_zero_point) * x_scale``. - ``x_scale`` and ``x_zero_point`` must have same shape, and can be either - a scalar for per-tensor / per layer quantization, or a 1-D tensor for - per-axis quantization. ``x_zero_point`` and ``x`` must have same type. - ``x`` and ``y`` must have same shape. In the case of dequantizing int32, - there's no zero point (zero point is supposed to be 0). - - Parameters - ========== - x - Type T. - N-D quantized input tensor to be de-quantized. - x_scale - Type tensor(float). - Scale for input 'x'. It can be a scalar, which means a per-tensor/layer - dequantization, or a 1-D tensor for per-axis dequantization. - x_zero_point - Type T. - Zero point for input 'x'. Shape must match x_scale. It's optional. Zero - point is 0 when it's not specified. - axis - Attribute. - (Optional) The axis of the dequantizing dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - - Returns - ======= - y : Var - Type tensor(float). - N-D full precision output tensor. It has same shape as input 'x'. - - Notes - ===== - Signature: ``ai.onnx@13::DequantizeLinear``. - - Type constraints: - - T: `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` - """ - return ( - _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _DequantizeLinear.Inputs( - x=unwrap_vars(x), - x_scale=unwrap_vars(x_scale), - x_zero_point=unwrap_vars(x_zero_point), - ), - ) - .get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - ) - .y - ) - - -def det( - X: Var, -) -> Var: - r""" - Det calculates determinant of a square matrix or batches of square - matrices. Det takes one input tensor of shape ``[*, M, M]``, where ``*`` - is zero or more batch dimensions, and the inner-most 2 dimensions form - square matrices. The output is a tensor of shape ``[*]``, containing the - determinants of all input submatrices. e.g., When the input is 2-D, the - output is a scalar(shape is empty: ``[]``). - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@11::Det``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Det( - _Det.Attributes(), - _Det.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def div( - A: Var, - B: Var, -) -> Var: - r""" - Performs element-wise binary division (with Numpy-style broadcasting - support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - (Opset 14 change): Extend supported types to include uint8, int8, - uint16, and int16. - - Parameters - ========== - A - Type T. - First operand. - B - Type T. - Second operand. - - Returns - ======= - C : Var - Type T. - Result, has same element type as two inputs - - Notes - ===== - Signature: ``ai.onnx@14::Div``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Div( - _Div.Attributes(), - _Div.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def dropout( - data: Var, - ratio: Optional[Var] = None, - training_mode: Optional[Var] = None, - *, - seed: Optional[int] = None, -) -> tuple[Var, Var]: - r""" - Dropout takes an input floating-point tensor, an optional input ratio - (floating-point scalar) and an optional input training_mode (boolean - scalar). It produces two tensor outputs, output (floating-point tensor) - and mask (optional ``Tensor``). If ``training_mode`` is true then - the output Y will be a random dropout; Note that this Dropout scales the - masked input data by the following equation, so to convert the trained - model into inference mode, the user can simply not pass - ``training_mode`` input or set it to false. - - :: - - output = scale * data * mask, - - where - - :: - - scale = 1. / (1. - ratio). - - This operator has **optional** inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty string - may be used in the place of an actual argument's name to indicate a - missing argument. Trailing optional arguments (those not followed by an - argument that is present) may also be simply omitted. - - Parameters - ========== - data - Type T. - The input data as Tensor. - ratio - Type T1. - The ratio of random dropout, with value in [0, 1). If this input was not - set, or if it was set to 0, the output would be a simple copy of the - input. If it's non-zero, output will be a random dropout of the scaled - input, which is typically the case during training. It is an optional - value, if not specified it will default to 0.5. - training_mode - Type T2. - If set to true then it indicates dropout is being used for training. It - is an optional value hence unless specified explicitly, it is false. If - it is false, ratio is ignored and the operation mimics inference mode - where nothing will be dropped from the input data and if mask is - requested as output it will contain all ones. - seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - - Returns - ======= - output : Var - Type T. - The output. - mask : Var - Type T2. - The output mask. - - Notes - ===== - Signature: ``ai.onnx@13::Dropout``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(bool)` - """ - return ( - _Dropout( - _Dropout.Attributes( - seed=AttrInt64.maybe(seed, name="seed"), - ), - _Dropout.Inputs( - data=unwrap_vars(data), - ratio=unwrap_vars(ratio), - training_mode=unwrap_vars(training_mode), - ), - ) - .get_output_vars( - data=get_value(data), - ratio=get_value(ratio), - training_mode=get_value(training_mode), - ) - ._unpack_to_any() - ) - - -def dynamic_quantize_linear( - x: Var, -) -> tuple[Var, Var, Var]: - r""" - A Function to fuse calculation for Scale, Zero Point and FP32->8Bit - conversion of FP32 Input data. Outputs Scale, ZeroPoint and Quantized - Input for a given FP32 Input. Scale is calculated as: - - :: - - y_scale = (maximum(0, max(x)) - minimum(0, min(x))) / (qmax - qmin) - - - where qmax and qmin are max and min values for quantization range - i.e. [0, 255] in case of uint8 - - data range is adjusted to include 0. - - Zero point is calculated as: - - :: - - intermediate_zero_point = qmin - min(x)/y_scale - y_zero_point = cast(round(saturate(itermediate_zero_point))) - - - where qmax and qmin are max and min values for quantization range - .i.e [0, 255] in case of uint8 - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, - 127] if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. - - Data quantization formula is: - - :: - - y = saturate (round (x / y_scale) + y_zero_point) - - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, - 127] if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. - - Parameters - ========== - x - Type T1. - Input tensor - - Returns - ======= - y : Var - Type T2. - Quantized output tensor - y_scale : Var - Type tensor(float). - Output scale. It's a scalar, which means a per-tensor/layer - quantization. - y_zero_point : Var - Type T2. - Output zero point. It's a scalar, which means a per-tensor/layer - quantization. - - Notes - ===== - Signature: ``ai.onnx@11::DynamicQuantizeLinear``. - - Type constraints: - - T1: `tensor(float)` - - T2: `tensor(uint8)` - """ - return ( - _DynamicQuantizeLinear( - _DynamicQuantizeLinear.Attributes(), - _DynamicQuantizeLinear.Inputs( - x=unwrap_vars(x), - ), - ) - .get_output_vars( - x=get_value(x), - ) - ._unpack_to_any() - ) - - -def einsum( - Inputs: Sequence[Var], - *, - equation: str, -) -> Var: - r""" - An einsum of the form ``term1, term2 -> output-term`` produces an output - tensor using the following equation - - :: - - output[output-term] = reduce-sum( input1[term1] * input2[term2] ) - - where the reduce-sum performs a summation over all the indices occurring - in the input terms (term1, term2) that do not occur in the output-term. - - The Einsum operator evaluates algebraic tensor operations on a sequence - of tensors, using the Einstein summation convention. The equation string - contains a comma-separated sequence of lower case letters. Each term - corresponds to an operand tensor, and the characters within the terms - correspond to operands dimensions. - - This sequence may be followed by "->" to separate the left and right - hand side of the equation. If the equation contains "->" followed by the - right-hand side, the explicit (not classical) form of the Einstein - summation is performed, and the right-hand side indices indicate output - tensor dimensions. In other cases, output indices are (implicitly) set - to the alphabetically sorted sequence of indices appearing exactly once - in the equation. - - When a dimension character is repeated in the left-hand side, it - represents summation along the dimension. - - The equation may contain ellipsis ("...") to enable broadcasting. - Ellipsis must indicate a fixed number of dimensions. Specifically, every - occurrence of ellipsis in the equation must represent the same number of - dimensions. The right-hand side may contain exactly one ellipsis. In - implicit mode, the ellipsis dimensions are set to the beginning of the - output. The equation string may contain space (U+0020) character. - - Parameters - ========== - Inputs - Type T. - Operands - equation - Attribute. - Einsum expression string. - - Returns - ======= - Output : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@12::Einsum``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Einsum( - _Einsum.Attributes( - equation=AttrString(equation, name="equation"), - ), - _Einsum.Inputs( - Inputs=unwrap_vars(Inputs), - ), - ) - .get_output_vars( - Inputs=get_value(Inputs), - ) - .Output - ) - - -def elu( - X: Var, - *, - alpha: float = 1.0, -) -> Var: - r""" - Elu takes one input data (Tensor) and produces one output data - (Tensor) where the function - ``f(x) = alpha * (exp(x) - 1.) for x < 0``, ``f(x) = x for x >= 0``., is - applied to the tensor elementwise. - - Parameters - ========== - X - Type T. - 1D input tensor - alpha - Attribute. - Coefficient of ELU. - - Returns - ======= - Y : Var - Type T. - 1D output tensor - - Notes - ===== - Signature: ``ai.onnx@6::Elu``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Elu( - _Elu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), - _Elu.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def equal( - A: Var, - B: Var, -) -> Var: - r""" - Returns the tensor resulted from performing the ``equal`` logical - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Equal``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return ( - _Equal( - _Equal.Attributes(), - _Equal.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def erf( - input: Var, -) -> Var: - r""" - Computes the error function of the given input tensor element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The error function of the input tensor computed element-wise. It has the - same shape and type of the input. - - Notes - ===== - Signature: ``ai.onnx@13::Erf``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Erf( - _Erf.Attributes(), - _Erf.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def exp( - input: Var, -) -> Var: - r""" - Calculates the exponential of the given input tensor, element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The exponential of the input tensor computed element-wise - - Notes - ===== - Signature: ``ai.onnx@13::Exp``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Exp( - _Exp.Attributes(), - _Exp.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def expand( - input: Var, - shape: Var, -) -> Var: - r""" - Broadcast the input tensor following the given shape and the broadcast - rule. The broadcast rule is similar to numpy.array(input) \* - numpy.ones(shape): Dimensions are right alignment; Two corresponding - dimensions must have the same value, or one of them is equal to 1. Also, - this operator is similar to numpy.broadcast_to(input, shape), but the - major difference is numpy.broadcast_to() does not allow shape to be - smaller than input.size(). It is possible that the output.shape is not - equal to shape, when some dimensions in shape is equal to 1, or the - shape.ndim < input.shape.ndim. - - Parameters - ========== - input - Type T. - Input tensor - shape - Type tensor(int64). - A 1-D tensor indicates the shape you want to expand to, following the - broadcast rule - - Returns - ======= - output : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::Expand``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Expand( - _Expand.Attributes(), - _Expand.Inputs( - input=unwrap_vars(input), - shape=unwrap_vars(shape), - ), - ) - .get_output_vars( - input=get_value(input), - shape=get_value(shape), - ) - .output - ) - - -def eye_like( - input: Var, - *, - dtype: Optional[npt.DTypeLike] = None, - k: int = 0, -) -> Var: - r""" - Generate a 2D tensor (matrix) with ones on the diagonal and zeros - everywhere else. Only 2D tensors are supported, i.e. input T1 must be of - rank 2. The shape of the output tensor is the same as the input tensor. - The data type can be specified by the 'dtype' argument. If 'dtype' is - not specified, then the type of input tensor is used. By default, the - main diagonal is populated with ones, but attribute 'k' can be used to - populate upper or lower diagonals. The 'dtype' argument must be one of - the data types specified in the 'DataType' enum field in the TensorProto - message and be valid as an output type. - - Parameters - ========== - input - Type T1. - 2D input tensor to copy shape, and optionally, type information from. - dtype - Attribute. - (Optional) The data type for the elements of the output tensor. If not - specified,the data type of the input tensor T1 is used. If input tensor - T1 is also notspecified, then type defaults to 'float'. - k - Attribute. - (Optional) Index of the diagonal to be populated with ones. Default is - 0. If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the - main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a - lower diagonal. - - Returns - ======= - output : Var - Type T2. - Output tensor, same shape as input tensor T1. - - Notes - ===== - Signature: ``ai.onnx@9::EyeLike``. - - Type constraints: - - T1: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _EyeLike( - _EyeLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - k=AttrInt64(k, name="k"), - ), - _EyeLike.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def flatten( - input: Var, - *, - axis: int = 1, -) -> Var: - r""" - Flattens the input tensor into a 2D matrix. If input tensor has shape - (d_0, d_1, ... d_n) then the output will have shape (d_0 X d_1 ... - d\_(axis-1), d_axis X d\_(axis+1) ... X dn). - - Parameters - ========== - input - Type T. - A tensor of rank >= axis. - axis - Attribute. - Indicate up to which input dimensions (exclusive) should be flattened to - the outer dimension of the output. The value for axis must be in the - range [-r, r], where r is the rank of the input tensor. Negative value - means counting dimensions from the back. When axis = 0, the shape of the - output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input - tensor is (d_0, d_1, ... d_n). - - Returns - ======= - output : Var - Type T. - A 2D tensor with the contents of the input tensor, with input dimensions - up to axis flattened to the outer dimension of the output and remaining - input dimensions flattened into the inner dimension of the output. - - Notes - ===== - Signature: ``ai.onnx@13::Flatten``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Flatten( - _Flatten.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Flatten.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def floor( - X: Var, -) -> Var: - r""" - Floor takes one input data (Tensor) and produces one output data - (Tensor) where the floor is, y = floor(x), is applied to the tensor - elementwise. If x is integral, +0, -0, NaN, or infinite, x itself is - returned. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::Floor``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Floor( - _Floor.Attributes(), - _Floor.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def gru( - X: Var, - W: Var, - R: Var, - B: Optional[Var] = None, - sequence_lens: Optional[Var] = None, - initial_h: Optional[Var] = None, - *, - activation_alpha: Optional[Iterable[float]] = None, - activation_beta: Optional[Iterable[float]] = None, - activations: Optional[Iterable[str]] = None, - clip: Optional[float] = None, - direction: str = "forward", - hidden_size: Optional[int] = None, - layout: int = 0, - linear_before_reset: int = 0, -) -> tuple[Var, Var]: - r""" - Computes an one-layer GRU. This operator is usually supported via some - custom implementation such as CuDNN. - - Notations: - - - ``X`` - input tensor - - ``z`` - update gate - - ``r`` - reset gate - - ``h`` - hidden gate - - ``t`` - time step (t-1 means previous time step) - - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden - gates - - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden - gates - - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates - - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates - - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, - and hidden gates - - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, - and hidden gates - - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden - gates - - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden - gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 - - Activation functions: - - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) - - NOTE: Below are optional - - - Affine(x) - alpha \* x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha \* Tanh(beta \* x) - - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) - - Equations (Default: f=Sigmoid, g=Tanh): - - - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) - - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) - - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when - linear_before_reset = 0 - - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when - linear_before_reset != 0 - - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** - inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. - - Parameters - ========== - X - Type T. - The input sequences packed (and potentially padded) into one 3-D tensor - with the shape of ``[seq_length, batch_size, input_size]``. - W - Type T. - The weight tensor for the gates. Concatenation of ``W[zrh]`` and - ``WB[zrh]`` (if bidirectional) along dimension 0. This tensor has shape - ``[num_directions, 3*hidden_size, input_size]``. - R - Type T. - The recurrence weight tensor. Concatenation of ``R[zrh]`` and - ``RB[zrh]`` (if bidirectional) along dimension 0. This tensor has shape - ``[num_directions, 3*hidden_size, hidden_size]``. - B - Type T. - The bias tensor for the gates. Concatenation of ``[Wb[zrh], Rb[zrh]]`` - and ``[WBb[zrh], RBb[zrh]]`` (if bidirectional) along dimension 0. This - tensor has shape ``[num_directions, 6*hidden_size]``. Optional: If not - specified - assumed to be 0 - sequence_lens - Type T1. - Optional tensor specifying lengths of the sequences in a batch. If not - specified - assumed all sequences in the batch to have length - ``seq_length``. It has shape ``[batch_size]``. - initial_h - Type T. - Optional initial value of the hidden. If not specified - assumed to be - 0. It has shape ``[num_directions, batch_size, hidden_size]``. - activation_alpha - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX - operators.For example with LeakyRelu, the default alpha is 0.01. - activation_beta - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX operators. - activations - Attribute. - A list of 2 (or 4 if bidirectional) activation functions for update, - reset, and hidden gates. The activation functions must be one of the - activation functions specified above. Optional: See the equations for - default if not specified. - clip - Attribute. - Cell clip threshold. Clipping bounds the elements of a tensor in the - range of [-threshold, +threshold] and is applied to the input of - activations. No clip if not specified. - direction - Attribute. - Specify if the RNN is forward, reverse, or bidirectional. Must be one of - forward (default), reverse, or bidirectional. - hidden_size - Attribute. - Number of neurons in the hidden layer - layout - Attribute. - The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the - following shapes are expected: X.shape = [seq_length, batch_size, - input_size], Y.shape = [seq_length, num_directions, batch_size, - hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, - hidden_size]. If 1, the following shapes are expected: X.shape = - [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, - num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, - num_directions, hidden_size]. - linear_before_reset - Attribute. - When computing the output of the hidden gate, apply the linear - transformation before multiplying by the output of the reset gate. - - Returns - ======= - Y : Var - Type T. - A tensor that concats all the intermediate output values of the hidden. - It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. - Y_h : Var - Type T. - The last output value of the hidden. It has shape - ``[num_directions, batch_size, hidden_size]``. - - Notes - ===== - Signature: ``ai.onnx@14::GRU``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(int32)` - """ - return ( - _GRU( - _GRU.Attributes( - activation_alpha=AttrFloat32s.maybe( - activation_alpha, name="activation_alpha" - ), - activation_beta=AttrFloat32s.maybe( - activation_beta, name="activation_beta" - ), - activations=AttrStrings.maybe(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - layout=AttrInt64(layout, name="layout"), - linear_before_reset=AttrInt64( - linear_before_reset, name="linear_before_reset" - ), - ), - _GRU.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - R=unwrap_vars(R), - B=unwrap_vars(B), - sequence_lens=unwrap_vars(sequence_lens), - initial_h=unwrap_vars(initial_h), - ), - ) - .get_output_vars( - X=get_value(X), - W=get_value(W), - R=get_value(R), - B=get_value(B), - sequence_lens=get_value(sequence_lens), - initial_h=get_value(initial_h), - ) - ._unpack_to_any() - ) - - -def gather( - data: Var, - indices: Var, - *, - axis: int = 0, -) -> Var: - r""" - Given ``data`` tensor of rank r >= 1, and ``indices`` tensor of rank q, - gather entries of the axis dimension of ``data`` (by default outer-most - one as axis=0) indexed by ``indices``, and concatenates them in an - output tensor of rank q + (r - 1). - - If ``axis = 0``, let ``k = indices[i_{0}, ..., i_{q-1}]`` then - ``output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]``: - - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - indices = [ - [0, 1], - [1, 2], - ] - output = [ - [ - [1.0, 1.2], - [2.3, 3.4], - ], - [ - [2.3, 3.4], - [4.5, 5.7], - ], - ] - - If ``axis = 1``, let ``k = indices[i_{0}, ..., i_{q-1}]`` then - ``output[j_{0}, i_{0}, ..., i_{q-1}, j_{1}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]``: - - :: - - data = [ - [1.0, 1.2, 1.9], - [2.3, 3.4, 3.9], - [4.5, 5.7, 5.9], - ] - indices = [ - [0, 2], - ] - axis = 1, - output = [ - [[1.0, 1.9]], - [[2.3, 3.9]], - [[4.5, 5.9]], - ] - - Parameters - ========== - data - Type T. - Tensor of rank r >= 1. - indices - Type Tind. - Tensor of int32/int64 indices, of any rank q. All index values are - expected to be within bounds [-s, s-1] along axis of size s. It is an - error if any of the index values are out of bounds. - axis - Attribute. - Which axis to gather on. Negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(data). - - Returns - ======= - output : Var - Type T. - Tensor of rank q + (r - 1). - - Notes - ===== - Signature: ``ai.onnx@13::Gather``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return ( - _Gather( - _Gather.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Gather.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - ), - ) - .get_output_vars( - data=get_value(data), - indices=get_value(indices), - ) - .output - ) - - -def gather_elements( - data: Var, - indices: Var, - *, - axis: int = 0, -) -> Var: - r""" - GatherElements takes two inputs ``data`` and ``indices`` of the same - rank r >= 1 and an optional attribute ``axis`` that identifies an axis - of ``data`` (by default, the outer-most axis, that is axis 0). It is an - indexing operation that produces its output by indexing into the input - data tensor at index positions determined by elements of the ``indices`` - tensor. Its output shape is the same as the shape of ``indices`` and - consists of one value (gathered from the ``data``) for each element in - ``indices``. - - For instance, in the 3-D case (r = 3), the output produced is determined - by the following equations: - - :: - - out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0, - out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1, - out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2, - - This operator is also the inverse of ScatterElements. It is similar to - Torch's gather operation. - - Example 1: - - :: - - data = [ - [1, 2], - [3, 4], - ] - indices = [ - [0, 0], - [1, 0], - ] - axis = 1 - output = [ - [1, 1], - [4, 3], - ] - - Example 2: - - :: - - data = [ - [1, 2, 3], - [4, 5, 6], - [7, 8, 9], - ] - indices = [ - [1, 2, 0], - [2, 0, 0], - ] - axis = 0 - output = [ - [4, 8, 3], - [7, 2, 3], - ] - - Parameters - ========== - data - Type T. - Tensor of rank r >= 1. - indices - Type Tind. - Tensor of int32/int64 indices, with the same rank r as the input. All - index values are expected to be within bounds [-s, s-1] along axis of - size s. It is an error if any of the index values are out of bounds. - axis - Attribute. - Which axis to gather on. Negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(data). - - Returns - ======= - output : Var - Type T. - Tensor of the same shape as indices. - - Notes - ===== - Signature: ``ai.onnx@13::GatherElements``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return ( - _GatherElements( - _GatherElements.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _GatherElements.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - ), - ) - .get_output_vars( - data=get_value(data), - indices=get_value(indices), - ) - .output - ) - - -def gather_nd( - data: Var, - indices: Var, - *, - batch_dims: int = 0, -) -> Var: - r""" - Given ``data`` tensor of rank ``r`` >= 1, ``indices`` tensor of rank - ``q`` >= 1, and ``batch_dims`` integer ``b``, this operator gathers - slices of ``data`` into an output tensor of rank - ``q + r - indices_shape[-1] - 1 - b``. - - ``indices`` is an q-dimensional integer tensor, best thought of as a - ``(q-1)``-dimensional tensor of index-tuples into ``data``, where each - element defines a slice of ``data`` - - ``batch_dims`` (denoted as ``b``) is an integer indicating the number of - batch dimensions, i.e the leading ``b`` number of dimensions of ``data`` - tensor and ``indices`` are representing the batches, and the gather - starts from the ``b+1`` dimension. - - Some salient points about the inputs' rank and shape: - - 1) r >= 1 and q >= 1 are to be honored. There is no dependency condition - to be met between ranks ``r`` and ``q`` - - 2) The first ``b`` dimensions of the shape of ``indices`` tensor and - ``data`` tensor must be equal. - - 3) b < min(q, r) is to be honored. - - 4) The ``indices_shape[-1]`` should have a value between 1 (inclusive) - and rank ``r-b`` (inclusive) - - 5) All values in ``indices`` are expected to be within bounds [-s, s-1] - along axis of size ``s`` (i.e.) - ``-data_shape[i] <= indices[...,i] <= data_shape[i] - 1``. It is an - error if any of the index values are out of bounds. - - The output is computed as follows: - - The output tensor is obtained by mapping each index-tuple in the - ``indices`` tensor to the corresponding slice of the input ``data``. - - 1) If ``indices_shape[-1] > r-b`` => error condition - - 2) If ``indices_shape[-1] == r-b``, since the rank of ``indices`` is - ``q``, ``indices`` can be thought of as ``N`` ``(q-b-1)``-dimensional - tensors containing 1-D tensors of dimension ``r-b``, where ``N`` is - an integer equals to the product of 1 and all the elements in the - batch dimensions of the indices_shape. Let us think of each such - ``r-b`` ranked tensor as ``indices_slice``. Each *scalar value* - corresponding to ``data[0:b-1,indices_slice]`` is filled into the - corresponding location of the ``(q-b-1)``-dimensional tensor to form - the ``output`` tensor (Example 1 below) - - 3) If ``indices_shape[-1] < r-b``, since the rank of ``indices`` is - ``q``, ``indices`` can be thought of as ``N`` ``(q-b-1)``-dimensional - tensor containing 1-D tensors of dimension ``< r-b``. Let us think of - each such tensors as ``indices_slice``. Each *tensor slice* - corresponding to ``data[0:b-1, indices_slice , :]`` is filled into - the corresponding location of the ``(q-b-1)``-dimensional tensor to - form the ``output`` tensor (Examples 2, 3, 4 and 5 below) - - This operator is the inverse of ``ScatterND``. - - **Example 1** - - :: - - batch_dims = 0 - data = [[0,1],[2,3]] # data_shape = [2, 2] - indices = [[0,0],[1,1]] # indices_shape = [2, 2] - output = [0,3] # output_shape = [2] - - **Example 2** - - :: - - batch_dims = 0 - data = [[0,1],[2,3]] # data_shape = [2, 2] - indices = [[1],[0]] # indices_shape = [2, 1] - output = [[2,3],[0,1]] # output_shape = [2, 2] - - **Example 3** - - :: - - batch_dims = 0 - data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] - indices = [[0,1],[1,0]] # indices_shape = [2, 2] - output = [[2,3],[4,5]] # output_shape = [2, 2] - - **Example 4** - - :: - - batch_dims = 0 - data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] - indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2] - output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2] - - **Example 5** - - :: - - batch_dims = 1 - data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] - indices = [[1],[0]] # indices_shape = [2, 1] - output = [[2,3],[4,5]] # output_shape = [2, 2] - - Parameters - ========== - data - Type T. - Tensor of rank r >= 1. - indices - Type tensor(int64). - Tensor of rank q >= 1. All index values are expected to be within bounds - [-s, s-1] along axis of size s. It is an error if any of the index - values are out of bounds. - batch_dims - Attribute. - The number of batch dimensions. The gather of indexing starts from - dimension of data[batch_dims:] - - Returns - ======= - output : Var - Type T. - Tensor of rank q + r - indices_shape[-1] - 1. - - Notes - ===== - Signature: ``ai.onnx@13::GatherND``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _GatherND( - _GatherND.Attributes( - batch_dims=AttrInt64(batch_dims, name="batch_dims"), - ), - _GatherND.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - ), - ) - .get_output_vars( - data=get_value(data), - indices=get_value(indices), - ) - .output - ) - - -def gemm( - A: Var, - B: Var, - C: Optional[Var] = None, - *, - alpha: float = 1.0, - beta: float = 1.0, - transA: int = 0, - transB: int = 0, -) -> Var: - r""" - General Matrix multiplication: - https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 - - - A' = transpose(A) if transA else A - - B' = transpose(B) if transB else B - - Compute Y = alpha \* A' \* B' + beta \* C, where input tensor A has - shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input - tensor C is broadcastable to shape (M, N), and output tensor Y has shape - (M, N). A will be transposed before doing the computation if attribute - transA is non-zero, same for B and transB. This operator supports - **unidirectional broadcasting** (tensor C should be unidirectional - broadcastable to tensor A \* B); for more details please check `the - doc `__. - This operator has **optional** inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty string - may be used in the place of an actual argument's name to indicate a - missing argument. Trailing optional arguments (those not followed by an - argument that is present) may also be simply omitted. - - Parameters - ========== - A - Type T. - Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, - M) if transA is non-zero. - B - Type T. - Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, - K) if transB is non-zero. - C - Type T. - Optional input tensor C. If not specified, the computation is done as if - C is a scalar 0. The shape of C should be unidirectional broadcastable - to (M, N). - alpha - Attribute. - Scalar multiplier for the product of input tensors A \* B. - beta - Attribute. - Scalar multiplier for input tensor C. - transA - Attribute. - Whether A should be transposed - transB - Attribute. - Whether B should be transposed - - Returns - ======= - Y : Var - Type T. - Output tensor of shape (M, N). - - Notes - ===== - Signature: ``ai.onnx@13::Gemm``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _Gemm( - _Gemm.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - transA=AttrInt64(transA, name="transA"), - transB=AttrInt64(transB, name="transB"), - ), - _Gemm.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - C=unwrap_vars(C), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - C=get_value(C), - ) - .Y - ) - - -def global_average_pool( - X: Var, -) -> Var: - r""" - GlobalAveragePool consumes an input tensor X and applies average pooling - across the values in the same channel. This is equivalent to AveragePool - with kernel size equal to the spatial dimension of input tensor. - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. - - Returns - ======= - Y : Var - Type T. - Output data tensor from pooling across the input tensor. The output - tensor has the same rank as the input. The first two dimensions of - output shape are the same as the input (N x C), while the other - dimensions are all 1. - - Notes - ===== - Signature: ``ai.onnx@1::GlobalAveragePool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _GlobalAveragePool( - _GlobalAveragePool.Attributes(), - _GlobalAveragePool.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def global_lp_pool( - X: Var, - *, - p: int = 2, -) -> Var: - r""" - GlobalLpPool consumes an input tensor X and applies lp pool pooling - across the values in the same channel. This is equivalent to LpPool with - kernel size equal to the spatial dimension of input tensor. - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. - p - Attribute. - p value of the Lp norm used to pool over the input data. - - Returns - ======= - Y : Var - Type T. - Output data tensor from pooling across the input tensor. The output - tensor has the same rank as the input. The first two dimensions of - output shape are the same as the input (N x C), while the other - dimensions are all 1. - - Notes - ===== - Signature: ``ai.onnx@2::GlobalLpPool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _GlobalLpPool( - _GlobalLpPool.Attributes( - p=AttrInt64(p, name="p"), - ), - _GlobalLpPool.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def global_max_pool( - X: Var, -) -> Var: - r""" - GlobalMaxPool consumes an input tensor X and applies max pooling across - the values in the same channel. This is equivalent to MaxPool with - kernel size equal to the spatial dimension of input tensor. - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. - - Returns - ======= - Y : Var - Type T. - Output data tensor from pooling across the input tensor. The output - tensor has the same rank as the input. The first two dimensions of - output shape are the same as the input (N x C), while the other - dimensions are all 1. - - Notes - ===== - Signature: ``ai.onnx@1::GlobalMaxPool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _GlobalMaxPool( - _GlobalMaxPool.Attributes(), - _GlobalMaxPool.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def greater( - A: Var, - B: Var, -) -> Var: - r""" - Returns the tensor resulted from performing the ``greater`` logical - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Greater``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return ( - _Greater( - _Greater.Attributes(), - _Greater.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def greater_or_equal( - A: Var, - B: Var, -) -> Var: - r""" - Returns the tensor resulted from performing the ``greater_equal`` - logical operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@16::GreaterOrEqual``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return ( - _GreaterOrEqual( - _GreaterOrEqual.Attributes(), - _GreaterOrEqual.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def grid_sample( - X: Var, - grid: Var, - *, - align_corners: int = 0, - mode: str = "bilinear", - padding_mode: str = "zeros", -) -> Var: - r""" - Given an input ``X`` and a flow-field ``grid``, computes the output - ``Y`` using ``X`` values and pixel locations from ``grid``. Currently, - only spatial (4-D) inputs are supported. For input ``X`` with shape (N, - C, H, W) and ``grid`` with shape (N, H_out, W_out, 2), the output ``Y`` - will have shape (N, C, H_out, W_out). - - The tensor ``X`` contains values at centers of square pixels in a H by W - 2-dimensional image. The tensor ``grid`` describes normalized positions - where the output ``Y`` is to be computed using a specified interpolation - method (the mode) and a padding mode (for grid positions falling outside - the 2-dimensional image). - - Elements in ``grid[N, H_out, W_out]`` are size-2 vectors specifying - positions in the 2-dimensional space of ``X``. They are used to - interpolate output values of ``Y[N, C, H_out, W_out]``. - - The GridSample operator is often used in doing grid generator and - sampler in the `Spatial Transformer - Networks `__. See also in - `torch.nn.functional.grid_sample `__. - - Parameters - ========== - X - Type T1. - 4-D tensor of shape (N, C, H, W), where N is the batch size, C is the - numbers of channels, H and W are the height and width of the input data. - grid - Type T2. - Input offset, 4-D tensor of shape (N, H_out, W_out, 2), where H_out and - W_out are the height and width of grid and output, Grid specifies the - sampling pixel locations normalized by the input spatial dimensions. - Therefore, it should have most values in the range of [-1, 1]. If grid - has values outside the range of [-1, 1], the corresponding outputs will - be handled as defined by padding_mode. - align_corners - Attribute. - If align_corners=1, the extrema (-1 and 1) are considered as referring - to the center points of the input's corner pixels. If align_corners=0, - they are instead considered as referring to the corner points of the - input's corner pixels, making the sampling more resolution agnostic. - mode - Attribute. - Three interpolation modes: bilinear (default), nearest and bicubic. - padding_mode - Attribute. - Support padding modes for outside grid values: ``zeros``\ (default), - ``border``, ``reflection``. zeros: use 0 for out-of-bound grid - locations, border: use border values for out-of-bound grid locations, - reflection: use values at locations reflected by the border for - out-of-bound grid locations. If index 0 represents the margin pixel, the - reflected value at index -1 will be the same as the value at index 1. - For location far away from the border, it will keep being reflected - until becoming in bound. If pixel location x = -3.5 reflects by border - -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = - 0.5. - - Returns - ======= - Y : Var - Type T1. - 4-D tensor of shape (N, C, H_out, W_out) of sampled values. For integer - input types, intermediate values are computed as floating point and cast - to integer at the end. - - Notes - ===== - Signature: ``ai.onnx@16::GridSample``. - - Type constraints: - - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _GridSample( - _GridSample.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - mode=AttrString(mode, name="mode"), - padding_mode=AttrString(padding_mode, name="padding_mode"), - ), - _GridSample.Inputs( - X=unwrap_vars(X), - grid=unwrap_vars(grid), - ), - ) - .get_output_vars( - X=get_value(X), - grid=get_value(grid), - ) - .Y - ) - - -def hamming_window( - size: Var, - *, - output_datatype: int = 1, - periodic: int = 1, -) -> Var: - r""" - Generates a Hamming window as described in the paper - https://ieeexplore.ieee.org/document/1455106. - - Parameters - ========== - size - Type T1. - A scalar value indicating the length of the window. - output_datatype - Attribute. - The data type of the output tensor. Strictly must be one of the values - from DataType enum in TensorProto whose values correspond to T2. The - default value is 1 = FLOAT. - periodic - Attribute. - If 1, returns a window to be used as periodic function. If 0, return a - symmetric window. When 'periodic' is specified, hann computes a window - of length size + 1 and returns the first size points. The default value - is 1. - - Returns - ======= - output : Var - Type T2. - A Hamming window with length: size. The output has the shape: [size]. - - Notes - ===== - Signature: ``ai.onnx@17::HammingWindow``. - - Type constraints: - - T1: `tensor(int32)`, `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _HammingWindow( - _HammingWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), - _HammingWindow.Inputs( - size=unwrap_vars(size), - ), - ) - .get_output_vars( - size=get_value(size), - ) - .output - ) - - -def hann_window( - size: Var, - *, - output_datatype: int = 1, - periodic: int = 1, -) -> Var: - r""" - Generates a Hann window as described in the paper - https://ieeexplore.ieee.org/document/1455106. - - Parameters - ========== - size - Type T1. - A scalar value indicating the length of the window. - output_datatype - Attribute. - The data type of the output tensor. Strictly must be one of the values - from DataType enum in TensorProto whose values correspond to T2. The - default value is 1 = FLOAT. - periodic - Attribute. - If 1, returns a window to be used as periodic function. If 0, return a - symmetric window. When 'periodic' is specified, hann computes a window - of length size + 1 and returns the first size points. The default value - is 1. - - Returns - ======= - output : Var - Type T2. - A Hann window with length: size. The output has the shape: [size]. - - Notes - ===== - Signature: ``ai.onnx@17::HannWindow``. - - Type constraints: - - T1: `tensor(int32)`, `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _HannWindow( - _HannWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), - _HannWindow.Inputs( - size=unwrap_vars(size), - ), - ) - .get_output_vars( - size=get_value(size), - ) - .output - ) - - -def hard_sigmoid( - X: Var, - *, - alpha: float = 0.20000000298023224, - beta: float = 0.5, -) -> Var: - r""" - HardSigmoid takes one input data (Tensor) and produces one output - data (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha - \* x + beta)), is applied to the tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - alpha - Attribute. - Value of alpha. - beta - Attribute. - Value of beta. - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@6::HardSigmoid``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _HardSigmoid( - _HardSigmoid.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - ), - _HardSigmoid.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def hard_swish( - X: Var, -) -> Var: - r""" - HardSwish takes one input data (Tensor) and produces one output data - (Tensor) where the HardSwish function, y = x \* max(0, min(1, alpha - \* x + beta)) = x \* HardSigmoid(x), where alpha = 1/6 and - beta = 0.5, is applied to the tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@14::HardSwish``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _HardSwish( - _HardSwish.Attributes(), - _HardSwish.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def hardmax( - input: Var, - *, - axis: int = -1, -) -> Var: - r""" - The operator computes the hardmax values for the given input: - - Hardmax(element in input, axis) = 1 if the element is the first maximum - value along the specified axis, 0 otherwise - - The "axis" attribute indicates the dimension along which Hardmax will be - performed. The output tensor has the same shape and contains the Hardmax - values of the corresponding input. - - Parameters - ========== - input - Type T. - The input tensor of rank >= axis. - axis - Attribute. - Describes the dimension Hardmax will be performed on. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(input). - - Returns - ======= - output : Var - Type T. - The output values with the same shape as the input tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Hardmax``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Hardmax( - _Hardmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Hardmax.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def identity( - input: Var, -) -> Var: - r""" - Identity operator - - Parameters - ========== - input - Type V. - Input tensor - - Returns - ======= - output : Var - Type V. - Tensor to copy input into. - - Notes - ===== - Signature: ``ai.onnx@16::Identity``. - - Type constraints: - - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Identity( - _Identity.Attributes(), - _Identity.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def if_( - cond: Var, - *, - else_branch: Callable[[], Iterable[Var]], - then_branch: Callable[[], Iterable[Var]], -) -> Sequence[Var]: - r""" - If conditional - - Parameters - ========== - cond - Type B. - Condition for the if. The tensor must contain a single element. - else_branch - Attribute. - Graph to run if condition is false. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the then_branch. - then_branch - Attribute. - Graph to run if condition is true. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the else_branch. - - Returns - ======= - outputs : Sequence[Var] - Type V. - Values that are live-out to the enclosing scope. The return values in - the ``then_branch`` and ``else_branch`` must be of the same data type. - The ``then_branch`` and ``else_branch`` may produce tensors with the - same element type and different shapes. If corresponding outputs from - the then-branch and the else-branch have static shapes S1 and S2, then - the shape of the corresponding output variable of the if-node (if - present) must be compatible with both S1 and S2 as it represents the - union of both possible shapes.For example, if in a model file, the first - output of ``then_branch`` is typed float tensor with shape [2] and the - first output of ``else_branch`` is another float tensor with shape [3], - If's first output should have (a) no shape set, or (b) a shape of rank 1 - with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank - 1 with a unique ``dim_param``. In contrast, the first output cannot have - the shape [2] since [2] and [3] are not compatible. - - Notes - ===== - Signature: ``ai.onnx@16::If``. - - Type constraints: - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _else_branch_subgraph: Graph = subgraph((), else_branch) - _then_branch_subgraph: Graph = subgraph((), then_branch) - return ( - _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), - _If.Inputs( - cond=unwrap_vars(cond), - ), - out_variadic=len(_else_branch_subgraph.requested_results), - ) - .get_output_vars( - cond=get_value(cond), - ) - .outputs - ) - - -def instance_normalization( - input: Var, - scale: Var, - B: Var, - *, - epsilon: float = 9.999999747378752e-06, -) -> Var: - r""" - Carries out instance normalization as described in the paper - https://arxiv.org/abs/1607.08022. - - y = scale \* (x - mean) / sqrt(variance + epsilon) + B, where mean and - variance are computed per instance per channel. - - Parameters - ========== - input - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. - scale - Type T. - The input 1-dimensional scale tensor of size C. - B - Type T. - The input 1-dimensional bias tensor of size C. - epsilon - Attribute. - The epsilon value to use to avoid division by zero. - - Returns - ======= - output : Var - Type T. - The output tensor of the same shape as input. - - Notes - ===== - Signature: ``ai.onnx@6::InstanceNormalization``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _InstanceNormalization( - _InstanceNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - ), - _InstanceNormalization.Inputs( - input=unwrap_vars(input), - scale=unwrap_vars(scale), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - input=get_value(input), - scale=get_value(scale), - B=get_value(B), - ) - .output - ) - - -def isinf( - X: Var, - *, - detect_negative: int = 1, - detect_positive: int = 1, -) -> Var: - r""" - Map infinity to true and other values to false. - - Parameters - ========== - X - Type T1. - input - detect_negative - Attribute. - (Optional) Whether map negative infinity to true. Default to 1 so that - negative infinity induces true. Set this attribute to 0 if negative - infinity should be mapped to false. - detect_positive - Attribute. - (Optional) Whether map positive infinity to true. Default to 1 so that - positive infinity induces true. Set this attribute to 0 if positive - infinity should be mapped to false. - - Returns - ======= - Y : Var - Type T2. - output - - Notes - ===== - Signature: ``ai.onnx@10::IsInf``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)` - - T2: `tensor(bool)` - """ - return ( - _IsInf( - _IsInf.Attributes( - detect_negative=AttrInt64(detect_negative, name="detect_negative"), - detect_positive=AttrInt64(detect_positive, name="detect_positive"), - ), - _IsInf.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def isnan( - X: Var, -) -> Var: - r""" - Returns which elements of the input are NaN. - - Parameters - ========== - X - Type T1. - input - - Returns - ======= - Y : Var - Type T2. - output - - Notes - ===== - Signature: ``ai.onnx@13::IsNaN``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(bool)` - """ - return ( - _IsNaN( - _IsNaN.Attributes(), - _IsNaN.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def lrn( - X: Var, - *, - alpha: float = 9.999999747378752e-05, - beta: float = 0.75, - bias: float = 1.0, - size: int, -) -> Var: - r""" - Local Response Normalization proposed in the `AlexNet - paper `__. - It normalizes over local input regions. The local region is defined - across the channels. For an element ``X[n, c, d1, ..., dk]`` in a tensor - of shape ``(N x C x D1 x D2, ..., Dk)``, its region is - ``{X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}``. - - ``square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2)``, where - ``max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))``. - - ``Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta`` - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. Optionally, if dimension denotation is in - effect, the operation expects the input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. - alpha - Attribute. - Scaling parameter. - beta - Attribute. - The exponent. - bias - Attribute. - - size - Attribute. - The number of channels to sum over - - Returns - ======= - Y : Var - Type T. - Output tensor, which has the shape and type as input tensor - - Notes - ===== - Signature: ``ai.onnx@13::LRN``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _LRN( - _LRN.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - bias=AttrFloat32(bias, name="bias"), - size=AttrInt64(size, name="size"), - ), - _LRN.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def lstm( - X: Var, - W: Var, - R: Var, - B: Optional[Var] = None, - sequence_lens: Optional[Var] = None, - initial_h: Optional[Var] = None, - initial_c: Optional[Var] = None, - P: Optional[Var] = None, - *, - activation_alpha: Optional[Iterable[float]] = None, - activation_beta: Optional[Iterable[float]] = None, - activations: Optional[Iterable[str]] = None, - clip: Optional[float] = None, - direction: str = "forward", - hidden_size: Optional[int] = None, - input_forget: int = 0, - layout: int = 0, -) -> tuple[Var, Var, Var]: - r""" - Computes an one-layer LSTM. This operator is usually supported via some - custom implementation such as CuDNN. - - Notations: - - - ``X`` - input tensor - - ``i`` - input gate - - ``o`` - output gate - - ``f`` - forget gate - - ``c`` - cell gate - - ``t`` - time step (t-1 means previous time step) - - ``W[iofc]`` - W parameter weight matrix for input, output, forget, - and cell gates - - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, - and cell gates - - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell - gates - - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell - gates - - ``P[iof]`` - P peephole weight vector for input, output, and forget - gates - - ``WB[iofc]`` - W parameter weight matrix for backward input, output, - forget, and cell gates - - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, - forget, and cell gates - - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, - and cell gates - - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, - and cell gates - - ``PB[iof]`` - P peephole weight vector for backward input, output, - and forget gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 - - Activation functions: - - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) - - NOTE: Below are optional - - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) - - Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): - - - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) - - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) - - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) - - Ct = ft (.) Ct-1 + it (.) ct - - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) - - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See - `the doc `__ for - more details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. - - Parameters - ========== - X - Type T. - The input sequences packed (and potentially padded) into one 3-D tensor - with the shape of ``[seq_length, batch_size, input_size]``. - W - Type T. - The weight tensor for the gates. Concatenation of ``W[iofc]`` and - ``WB[iofc]`` (if bidirectional) along dimension 0. The tensor has shape - ``[num_directions, 4*hidden_size, input_size]``. - R - Type T. - The recurrence weight tensor. Concatenation of ``R[iofc]`` and - ``RB[iofc]`` (if bidirectional) along dimension 0. This tensor has shape - ``[num_directions, 4*hidden_size, hidden_size]``. - B - Type T. - The bias tensor for input gate. Concatenation of - ``[Wb[iofc], Rb[iofc]]``, and ``[WBb[iofc], RBb[iofc]]`` (if - bidirectional) along dimension 0. This tensor has shape - ``[num_directions, 8*hidden_size]``. Optional: If not specified - - assumed to be 0. - sequence_lens - Type T1. - Optional tensor specifying lengths of the sequences in a batch. If not - specified - assumed all sequences in the batch to have length - ``seq_length``. It has shape ``[batch_size]``. - initial_h - Type T. - Optional initial value of the hidden. If not specified - assumed to be - 0. It has shape ``[num_directions, batch_size, hidden_size]``. - initial_c - Type T. - Optional initial value of the cell. If not specified - assumed to be 0. - It has shape ``[num_directions, batch_size, hidden_size]``. - P - Type T. - The weight tensor for peepholes. Concatenation of ``P[iof]`` and - ``PB[iof]`` (if bidirectional) along dimension 0. It has shape - ``[num_directions, 3*hidde_size]``. Optional: If not specified - assumed - to be 0. - activation_alpha - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX - operators.For example with LeakyRelu, the default alpha is 0.01. - activation_beta - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX operators. - activations - Attribute. - A list of 3 (or 6 if bidirectional) activation functions for input, - output, forget, cell, and hidden. The activation functions must be one - of the activation functions specified above. Optional: See the equations - for default if not specified. - clip - Attribute. - Cell clip threshold. Clipping bounds the elements of a tensor in the - range of [-threshold, +threshold] and is applied to the input of - activations. No clip if not specified. - direction - Attribute. - Specify if the RNN is forward, reverse, or bidirectional. Must be one of - forward (default), reverse, or bidirectional. - hidden_size - Attribute. - Number of neurons in the hidden layer - input_forget - Attribute. - Couple the input and forget gates if 1. - layout - Attribute. - The shape format of inputs X, initial_h, initial_c and outputs Y, Y_h, - Y_c. If 0, the following shapes are expected: X.shape = [seq_length, - batch_size, input_size], Y.shape = [seq_length, num_directions, - batch_size, hidden_size], initial_h.shape = Y_h.shape = initial_c.shape - = Y_c.shape = [num_directions, batch_size, hidden_size]. If 1, the - following shapes are expected: X.shape = [batch_size, seq_length, - input_size], Y.shape = [batch_size, seq_length, num_directions, - hidden_size], initial_h.shape = Y_h.shape = initial_c.shape = Y_c.shape - = [batch_size, num_directions, hidden_size]. - - Returns - ======= - Y : Var - Type T. - A tensor that concats all the intermediate output values of the hidden. - It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. - Y_h : Var - Type T. - The last output value of the hidden. It has shape - ``[num_directions, batch_size, hidden_size]``. - Y_c : Var - Type T. - The last output value of the cell. It has shape - ``[num_directions, batch_size, hidden_size]``. - - Notes - ===== - Signature: ``ai.onnx@14::LSTM``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(int32)` - """ - return ( - _LSTM( - _LSTM.Attributes( - activation_alpha=AttrFloat32s.maybe( - activation_alpha, name="activation_alpha" - ), - activation_beta=AttrFloat32s.maybe( - activation_beta, name="activation_beta" - ), - activations=AttrStrings.maybe(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - input_forget=AttrInt64(input_forget, name="input_forget"), - layout=AttrInt64(layout, name="layout"), - ), - _LSTM.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - R=unwrap_vars(R), - B=unwrap_vars(B), - sequence_lens=unwrap_vars(sequence_lens), - initial_h=unwrap_vars(initial_h), - initial_c=unwrap_vars(initial_c), - P=unwrap_vars(P), - ), - ) - .get_output_vars( - X=get_value(X), - W=get_value(W), - R=get_value(R), - B=get_value(B), - sequence_lens=get_value(sequence_lens), - initial_h=get_value(initial_h), - initial_c=get_value(initial_c), - P=get_value(P), - ) - ._unpack_to_any() - ) - - -def layer_normalization( - X: Var, - Scale: Var, - B: Optional[Var] = None, - *, - axis: int = -1, - epsilon: float = 9.999999747378752e-06, - stash_type: int = 1, -) -> tuple[Var, Var, Var]: - r""" - This is layer normalization defined in ONNX as function. The overall - computation can be split into two stages. The first stage is - standardization, which makes the normalized elements have zero mean and - unit variances. The computation required by standardization can be - described by the following equations. - ``Mean = ReduceMean(X) D = Sub(X, Mean) DD = Mul(D, D) Var = ReduceMean(DD) VarEps = Add(Var, epsilon) StdDev = Sqrt(VarEps) InvStdDev = Reciprocal(StdDev) Normalized = Mul(D, InvStdDev)`` - where ``normalized_axes`` is ``[axis, ..., rank of X - 1]``. The - variables ``Var`` and ``StdDev`` stand for variance and standard - deviation, respectively. The second output is ``Mean`` and the last one - is ``InvStdDev``. Depending on ``stash_type`` attribute, the actual - computation must happen in different floating-point precision. For - example, if ``stash_type`` is 1, this operator casts all input variables - to 32-bit float, perform the computation, and finally cast - ``Normalized`` back to the original type of ``X``. The second stage then - scales and shifts the outcome of the first stage using - ``NormalizedScaled = Mul(Normalized, Scale) Y = Add(NormalizedScaled, B)`` - The second stage doesn't depends on ``stash_type``. All equations are in - `this syntax `__. - The same variable (i.e., input, output, and attribute) uses the same - name in the equations above and this operator's definition. Let ``d[i]`` - indicate the i-th dimension of ``X``. If ``X``'s shape is - ``[d[0], ..., d[axis-1], d[axis], ..., d[rank-1]]``, the shape of - ``Mean`` and ``InvStdDev`` is ``[d[0], ..., d[axis-1], 1, ..., 1]``. - ``Y`` and ``X`` have the same shape. This operator supports - unidirectional broadcasting (tensors ``Scale`` and ``B`` should be - unidirectional broadcastable to tensor ``X``); for more details please - check `the - doc `__. - - Parameters - ========== - X - Type T. - Tensor to be normalized. - Scale - Type T. - Scale tensor. - B - Type T. - Bias tensor. - axis - Attribute. - The first normalization dimension. If rank(X) is r, axis' allowed range - is [-r, r). Negative value means counting dimensions from the back. - epsilon - Attribute. - The epsilon value to use to avoid division by zero. - stash_type - Attribute. - Type of Mean and InvStdDev. This also specifies stage one's computation - precision. - - Returns - ======= - Y : Var - Type T. - Normalized tensor. - Mean : Var - Type U. - Saved mean used during training to speed up gradient computation - InvStdDev : Var - Type U. - Saved inverse standard deviation used during training to speed up - gradient computation. - - Notes - ===== - Signature: ``ai.onnx@17::LayerNormalization``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - U: `tensor(bfloat16)`, `tensor(float)` - """ - return ( - _LayerNormalization( - _LayerNormalization.Attributes( - axis=AttrInt64(axis, name="axis"), - epsilon=AttrFloat32(epsilon, name="epsilon"), - stash_type=AttrInt64(stash_type, name="stash_type"), - ), - _LayerNormalization.Inputs( - X=unwrap_vars(X), - Scale=unwrap_vars(Scale), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - X=get_value(X), - Scale=get_value(Scale), - B=get_value(B), - ) - ._unpack_to_any() - ) - - -def leaky_relu( - X: Var, - *, - alpha: float = 0.009999999776482582, -) -> Var: - r""" - LeakyRelu takes input data (Tensor) and an argument alpha, and - produces one output data (Tensor) where the function - ``f(x) = alpha * x for x < 0``, ``f(x) = x for x >= 0``, is applied to - the data tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - alpha - Attribute. - Coefficient of leakage. - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@16::LeakyRelu``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _LeakyRelu( - _LeakyRelu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), - _LeakyRelu.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def less( - A: Var, - B: Var, -) -> Var: - r""" - Returns the tensor resulted from performing the ``less`` logical - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Less``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return ( - _Less( - _Less.Attributes(), - _Less.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def less_or_equal( - A: Var, - B: Var, -) -> Var: - r""" - Returns the tensor resulted from performing the ``less_equal`` logical - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@16::LessOrEqual``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return ( - _LessOrEqual( - _LessOrEqual.Attributes(), - _LessOrEqual.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def log( - input: Var, -) -> Var: - r""" - Calculates the natural log of the given input tensor, element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The natural log of the input tensor computed element-wise - - Notes - ===== - Signature: ``ai.onnx@13::Log``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Log( - _Log.Attributes(), - _Log.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def log_softmax( - input: Var, - *, - axis: int = -1, -) -> Var: - r""" - The operator computes the log of softmax values for the given input: - - LogSoftmax(input, axis) = Log(Softmax(input, axis=axis)) - - The "axis" attribute indicates the dimension along which LogSoftmax will - be performed. The output tensor has the same shape and contains the - LogSoftmax values of the corresponding input. - - Parameters - ========== - input - Type T. - The input tensor of rank >= axis. - axis - Attribute. - Describes the dimension LogSoftmax will be performed on. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(input). - - Returns - ======= - output : Var - Type T. - The output values with the same shape as the input tensor. - - Notes - ===== - Signature: ``ai.onnx@13::LogSoftmax``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _LogSoftmax( - _LogSoftmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _LogSoftmax.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def loop( - M: Optional[Var] = None, - cond: Optional[Var] = None, - v_initial: Sequence[Var] = (), - *, - body: Callable[..., Iterable[Var]], -) -> Sequence[Var]: - r""" - Generic Looping construct. This loop has multiple termination - conditions: - - 1) Trip count. Iteration count specified at runtime. Set by specifying - the input M. Optional. Set to empty string to omit. Note that a - static trip count (specified at graph construction time) can be - specified by passing in a constant node for input M. - 2) Loop termination condition. This is an input to the op that - determines whether to run the first iteration and also a loop-carried - dependency for the body graph. The body graph must yield a value for - the condition variable, whether this input is provided or not. - - This table summarizes the operating modes of this operator with - equivalent C-style code: - - Operator inputs defined as (max_trip_count, condition_var). - - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } - - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } - - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } - - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } - - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } - - *Sample usage - cond as well as trip count* - - :: - - graph predict-net { - %a = Constant[value = ]() - %b = Constant[value = ]() - %keepgoing = Constant[value = ]() - %max_trip_count = Constant[value = ]() - %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) - return - } - - graph body-net ( - %i[INT32, scalar] // iteration number - %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used - %b_in[INT32, scalar] // incoming value of loop-carried-dependency b - ) { - %my_local = Add(%a, %b_in) - %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b - %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition - %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated - return %keepgoing_out, %b_out, %user_defined_val - } - - *Sample equivalent C code* - - :: - - { - /* User-defined code (enclosing scope) */ - int a = 3, b = 6; - bool keepgoing = true; // Analogous to input cond - /* End user-defined code */ - - /* Implicitly-defined code */ - const int max_trip_count = 10; // Analogous to input M - int user_defined_vals[]; // Imagine this is resizable - /* End implicitly-defined code */ - /* initialize loop-carried variables and scan-output variables */ - bool keepgoing_out = keepgoing - int b_out = b - - for (int i=0; i < max_trip_count && keepgoing_out; ++i) { - /* Implicitly-defined code: bind actual parameter values - to formal parameter variables of loop-body */ - bool keepgoing_in = keepgoing_out; - bool b_in = b_out; - - /* User-defined code (loop body) */ - int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine - b_out = a - b_in; - keepgoing_out = my_local > b_out; - user_defined_val = b_in + b_in; // b_in and b_out are different variables - /* End user-defined code */ - - /* Implicitly defined-code */ - user_defined_vals[i] = user_defined_val // accumulate scan-output values - } - // int t = my_local; // Can't do this. my_local is not accessible here. - - // The values below are bound to the output variables of the loop and therefore accessible - // b_out; user_defined_vals; keepgoing_out; - } - - There are several things of note in this code snippet: - - 1) Values from the enclosing scope (i.e. variable "a" here) are in scope - and can be referenced in the inputs of the loop. - 2) Any values computed in the loop body that needs to be used in a - subsequent iteration or after the loop are modelled using a pair of - variables in the loop-body, consisting of an input variable (eg., - b_in) and an output variable (eg., b_out). These are referred to as - loop-carried dependences. The loop operation node supplies the input - value of the input variable for the first iteration, and returns the - output value of the output variable produced by the final iteration. - 3) Scan_output variables are used to implicitly concatenate values - computed across all the iterations. In the above example, the value - of user_defined_val computed over all iterations are concatenated and - returned as the value of user_defined_vals after the loop. - 4) Values created in the body cannot be accessed in the enclosing scope, - except using the mechanism described above. - - Note that the semantics of this op support "diagonal" or "wavefront" - execution. (See Step 3 here for an example: - https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). - Frontends should emit multi-layer RNNs as a series of While operators - (with time being the inner looping dimension), with each successive - layer consuming the scan_outputs from the previous layer, possibly going - through several point-wise operators (e.g. dropout, residual - connections, linear layer). - - The input/output of subgraph (produced by loop node) matching is based - on order instead of name. The implementation will figure out the names - based on this order. - - Parameters - ========== - M - Type I. - A maximum trip-count for the loop specified at runtime. Optional. Pass - empty string to skip. - cond - Type B. - A boolean termination condition. Optional. Pass empty string to skip. - v_initial - Type V. - The initial values of any loop-carried dependencies (values that change - across loop iterations) - body - Attribute. - The graph run each iteration. It has 2+N inputs: (iteration_num, - condition, loop carried dependencies...). It has 1+N+K outputs: - (condition, loop carried dependencies..., scan_outputs...). Each - scan_output is created by concatenating the value of the specified - output value at the end of each iteration of the loop. It is an error if - the dimensions or data type of these scan_outputs change across loop - iterations. - - Returns - ======= - v_final_and_scan_outputs : Sequence[Var] - Type V. - Final N loop carried dependency values then K scan_outputs. Scan outputs - must be Tensors. - - Notes - ===== - Signature: ``ai.onnx@16::Loop``. - - Type constraints: - - I: `tensor(int64)` - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _body_subgraph: Graph = subgraph( - typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))]) - + [var.unwrap_type() for var in v_initial], - body, - ) - return ( - _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), - _Loop.Inputs( - M=unwrap_vars(M), - cond=unwrap_vars(cond), - v_initial=unwrap_vars(v_initial), - ), - out_variadic=len(_body_subgraph.requested_results) - 1, - ) - .get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), - ) - .v_final_and_scan_outputs - ) - - -def lp_normalization( - input: Var, - *, - axis: int = -1, - p: int = 2, -) -> Var: - r""" - Given a matrix, apply Lp-normalization along the provided axis. - - Parameters - ========== - input - Type T. - Input matrix - axis - Attribute. - The axis on which to apply normalization, -1 mean last axis. - p - Attribute. - The order of the normalization, only 1 or 2 are supported. - - Returns - ======= - output : Var - Type T. - Matrix after normalization - - Notes - ===== - Signature: ``ai.onnx@1::LpNormalization``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _LpNormalization( - _LpNormalization.Attributes( - axis=AttrInt64(axis, name="axis"), - p=AttrInt64(p, name="p"), - ), - _LpNormalization.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def lp_pool( - X: Var, - *, - auto_pad: str = "NOTSET", - kernel_shape: Iterable[int], - p: int = 2, - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: - r""" - LpPool consumes an input tensor X and applies Lp pooling across the - tensor according to kernel sizes, stride sizes, and pad lengths. Lp - pooling consisting of computing the Lp norm on all values of a subset of - the input tensor according to the kernel size and downsampling the data - into the output tensor Y for further processing. - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. - kernel_shape - Attribute. - The size of the kernel along each axis. - p - Attribute. - p value of the Lp norm used to pool over the input data. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - - Returns - ======= - Y : Var - Type T. - Output data tensor from Lp pooling across the input tensor. Dimensions - will vary based on various kernel, stride, and pad sizes. - - Notes - ===== - Signature: ``ai.onnx@11::LpPool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _LpPool( - _LpPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - p=AttrInt64(p, name="p"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _LpPool.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def matmul( - A: Var, - B: Var, -) -> Var: - r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html - - Parameters - ========== - A - Type T. - N-dimensional matrix A - B - Type T. - N-dimensional matrix B - - Returns - ======= - Y : Var - Type T. - Matrix multiply results from A \* B - - Notes - ===== - Signature: ``ai.onnx@13::MatMul``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _MatMul( - _MatMul.Attributes(), - _MatMul.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .Y - ) - - -def matmul_integer( - A: Var, - B: Var, - a_zero_point: Optional[Var] = None, - b_zero_point: Optional[Var] = None, -) -> Var: - r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. - The production MUST never overflow. The accumulation may overflow if and - only if in 32 bits. - - Parameters - ========== - A - Type T1. - N-dimensional matrix A - B - Type T2. - N-dimensional matrix B - a_zero_point - Type T1. - Zero point tensor for input 'A'. It's optional and default value is 0. - It could be a scalar or N-D tensor. Scalar refers to per tensor - quantization whereas N-D refers to per row quantization. If the input is - 2D of shape [M, K] then zero point tensor may be an M element vector - [zp_1, zp_2, ..., zp_M]. If the input is N-D tensor with shape [D1, D2, - M, K] then zero point tensor may have shape [D1, D2, M, 1]. - b_zero_point - Type T2. - Zero point tensor for input 'B'. It's optional and default value is 0. - It could be a scalar or a N-D tensor, Scalar refers to per tensor - quantization whereas N-D refers to per col quantization. If the input is - 2D of shape [K, N] then zero point tensor may be an N element vector - [zp_1, zp_2, ..., zp_N]. If the input is N-D tensor with shape [D1, D2, - K, N] then zero point tensor may have shape [D1, D2, 1, N]. - - Returns - ======= - Y : Var - Type T3. - Matrix multiply results from A \* B - - Notes - ===== - Signature: ``ai.onnx@10::MatMulInteger``. - - Type constraints: - - T1: `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(int32)` - """ - return ( - _MatMulInteger( - _MatMulInteger.Attributes(), - _MatMulInteger.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - a_zero_point=unwrap_vars(a_zero_point), - b_zero_point=unwrap_vars(b_zero_point), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - a_zero_point=get_value(a_zero_point), - b_zero_point=get_value(b_zero_point), - ) - .Y - ) - - -def max( - data_0: Sequence[Var], -) -> Var: - r""" - Element-wise max of each of the input tensors (with Numpy-style - broadcasting support). All inputs and outputs must have the same data - type. This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - data_0 - Type T. - List of tensors for max. - - Returns - ======= - max : Var - Type T. - Output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Max``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Max( - _Max.Attributes(), - _Max.Inputs( - data_0=unwrap_vars(data_0), - ), - ) - .get_output_vars( - data_0=get_value(data_0), - ) - .max - ) - - -def max_pool( - X: Var, - *, - auto_pad: str = "NOTSET", - ceil_mode: int = 0, - dilations: Optional[Iterable[int]] = None, - kernel_shape: Iterable[int], - pads: Optional[Iterable[int]] = None, - storage_order: int = 0, - strides: Optional[Iterable[int]] = None, -) -> tuple[Var, Var]: - r""" - MaxPool consumes an input tensor X and applies max pooling across the - tensor according to kernel sizes, stride sizes, and pad lengths. max - pooling consisting of computing the max on all values of a subset of the - input tensor according to the kernel size and downsampling the data into - the output tensor Y for further processing. The output spatial shape is - calculated differently depending on whether explicit padding is used, - where pads is employed, or auto padding is used, where auto_pad is - utilized. With explicit padding - (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): - - :: - - output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) - - or - - :: - - output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) - - if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. Sliding windows that would start in the right padded region are - ignored. - - ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, - the output spatial shape will be following when ceil_mode is enabled: - - :: - - VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) - - or when ceil_mode is disabled - (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): - - :: - - VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 - - And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: - - :: - - pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] - - The output of each pooling window is maximum number of elements exclude - pad. - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. Optionally, if dimension denotation is in - effect, the operation expects the input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. - ceil_mode - Attribute. - Whether to use ceil or floor (default) to compute the output shape. - dilations - Attribute. - Dilation value along each spatial axis of filter. If not present, the - dilation defaults to 1 along each spatial axis. - kernel_shape - Attribute. - The size of the kernel along each axis. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. - storage_order - Attribute. - The storage order of the tensor. 0 is row major, and 1 is column major. - This attribute is used only to convert an n-tuple index value into a - single integer value for producing the second output. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - - Returns - ======= - Y : Var - Type T. - Output data tensor from average or max pooling across the input tensor. - Dimensions will vary based on various kernel, stride, and pad sizes. - Floor value of the dimension is used - Indices : Var - Type I. - Indices tensor from max pooling across the input tensor. The dimensions - of indices are the same as output tensor. The values in indices of are - the indices of the selected values during pooling. The indices are - computed as flatten 1-D tensor, and the indices do not consider padding. - So the values in indices are in [0, N x C x D1 x ... x Dn). - - Notes - ===== - Signature: ``ai.onnx@12::MaxPool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int8)`, `tensor(uint8)` - - I: `tensor(int64)` - """ - return ( - _MaxPool( - _MaxPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - storage_order=AttrInt64(storage_order, name="storage_order"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _MaxPool.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - ._unpack_to_any() - ) - - -def max_roi_pool( - X: Var, - rois: Var, - *, - pooled_shape: Iterable[int], - spatial_scale: float = 1.0, -) -> Var: - r""" - ROI max pool consumes an input tensor X and region of interests (RoIs) - to apply max pooling across each RoI, to produce output 4-D tensor of - shape (num_rois, channels, pooled_shape[0], pooled_shape[1]). - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. - rois - Type T. - RoIs (Regions of Interest) to pool over. Should be a 2-D tensor of shape - (num_rois, 5) given as [[batch_id, x1, y1, x2, y2], ...]. - pooled_shape - Attribute. - ROI pool output shape (height, width). - spatial_scale - Attribute. - Multiplicative spatial scale factor to translate ROI coordinates from - their input scale to the scale used when pooling. - - Returns - ======= - Y : Var - Type T. - RoI pooled output 4-D tensor of shape (num_rois, channels, - pooled_shape[0], pooled_shape[1]). - - Notes - ===== - Signature: ``ai.onnx@1::MaxRoiPool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _MaxRoiPool( - _MaxRoiPool.Attributes( - pooled_shape=AttrInt64s(pooled_shape, name="pooled_shape"), - spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), - ), - _MaxRoiPool.Inputs( - X=unwrap_vars(X), - rois=unwrap_vars(rois), - ), - ) - .get_output_vars( - X=get_value(X), - rois=get_value(rois), - ) - .Y - ) - - -def max_unpool( - X: Var, - I: Var, - output_shape: Optional[Var] = None, - *, - kernel_shape: Iterable[int], - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: - r""" - MaxUnpool essentially computes the partial inverse of the MaxPool op. - The input information to this op is typically the output information - from a MaxPool op. The first input tensor X is the tensor that needs to - be unpooled, which is typically the pooled tensor (first output) from - MaxPool. The second input tensor, I, contains the indices to the - (locally maximal) elements corresponding to the elements in the first - input tensor X. Input tensor I is typically the second output of the - MaxPool op. The third (optional) input is a tensor that specifies the - output size of the unpooling operation. - - MaxUnpool is intended to do 'partial' inverse of the MaxPool op. - 'Partial' because all the non-maximal values from the original input to - MaxPool are set to zero in the output of the MaxUnpool op. Pooling the - result of an unpooling operation should give back the original input to - the unpooling op. - - MaxUnpool can produce the same output size for several input sizes, - which makes unpooling op ambiguous. The third input argument, - output_size, is meant to disambiguate the op and produce output tensor - of known/predictable size. - - In addition to the inputs, MaxUnpool takes three attributes, namely - kernel_shape, strides, and pads, which define the exact unpooling op. - The attributes typically have the same values as the corresponding - pooling op that the unpooling op is trying to invert. - - Parameters - ========== - X - Type T1. - Input data tensor that has to be unpooled. This tensor is typically the - first output of the MaxPool op.Dimensions for image case are (N x C x H - x W), where N is the batch size, C is the number of channels, and H and - W are the height and the width of the data. For non-image case, the - dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the - batch size. Optionally, if dimension denotation is in effect, the - operation expects the input data tensor to arrive with the dimension - denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE - ...]. - I - Type T2. - Input data tensor containing the indices corresponding to elements in - the first input tensor X.This tensor is typically the second output of - the MaxPool op.Dimensions must be the same as input tensor X. The - indices are linear, i.e. computed considering the tensor as flattened - 1-D tensor, assuming row-major storage. Also, the linear indices should - not consider padding. So the values in indices are in the range [0, N x - C x D1 x ... x Dn). - output_shape - Type T2. - The shape of the output can be explicitly set which will cause pads - values to be auto generated. If 'output_shape' is specified, 'pads' - values are ignored. - kernel_shape - Attribute. - The size of the kernel along each axis. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - - Returns - ======= - output : Var - Type T1. - Output data tensor that contains the result of the unpooling. - - Notes - ===== - Signature: ``ai.onnx@11::MaxUnpool``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int64)` - """ - return ( - _MaxUnpool( - _MaxUnpool.Attributes( - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _MaxUnpool.Inputs( - X=unwrap_vars(X), - I=unwrap_vars(I), - output_shape=unwrap_vars(output_shape), - ), - ) - .get_output_vars( - X=get_value(X), - I=get_value(I), - output_shape=get_value(output_shape), - ) - .output - ) - - -def mean( - data_0: Sequence[Var], -) -> Var: - r""" - Element-wise mean of each of the input tensors (with Numpy-style - broadcasting support). All inputs and outputs must have the same data - type. This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - data_0 - Type T. - List of tensors for mean. - - Returns - ======= - mean : Var - Type T. - Output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Mean``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Mean( - _Mean.Attributes(), - _Mean.Inputs( - data_0=unwrap_vars(data_0), - ), - ) - .get_output_vars( - data_0=get_value(data_0), - ) - .mean - ) - - -def mean_variance_normalization( - X: Var, - *, - axes: Iterable[int] = (0, 2, 3), -) -> Var: - r""" - A MeanVarianceNormalization Function: Perform mean variance - normalization on the input tensor X using formula: - ``(X-EX)/sqrt(E(X-EX)^2)`` - - Parameters - ========== - X - Type T. - Input tensor - axes - Attribute. - A list of integers, along which to reduce. The default is to calculate - along axes [0,2,3] for calculating mean and variance along each channel. - Two variables with the same C-coordinate are associated with the same - mean and variance. - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::MeanVarianceNormalization``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _MeanVarianceNormalization( - _MeanVarianceNormalization.Attributes( - axes=AttrInt64s(axes, name="axes"), - ), - _MeanVarianceNormalization.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def mel_weight_matrix( - num_mel_bins: Var, - dft_length: Var, - sample_rate: Var, - lower_edge_hertz: Var, - upper_edge_hertz: Var, - *, - output_datatype: int = 1, -) -> Var: - r""" - Generate a MelWeightMatrix that can be used to re-weight a Tensor - containing a linearly sampled frequency spectra (from DFT or STFT) into - num_mel_bins frequency information based on the [lower_edge_hertz, - upper_edge_hertz] range on the mel scale. This function defines the mel - scale in terms of a frequency in hertz according to the following - formula: - - :: - - mel(f) = 2595 * log10(1 + f/700) - - In the returned matrix, all the triangles (filterbanks) have a peak - value of 1.0. - - The returned MelWeightMatrix can be used to right-multiply a spectrogram - S of shape [frames, num_spectrogram_bins] of linear scale spectrum - values (e.g. STFT magnitudes) to generate a "mel spectrogram" M of shape - [frames, num_mel_bins]. - - Parameters - ========== - num_mel_bins - Type T1. - The number of bands in the mel spectrum. - dft_length - Type T1. - The size of the original DFT. The size of the original DFT is used to - infer the size of the onesided DFT, which is understood to be - floor(dft_length/2) + 1, i.e. the spectrogram only contains the - nonredundant DFT bins. - sample_rate - Type T1. - Samples per second of the input signal used to create the spectrogram. - Used to figure out the frequencies corresponding to each spectrogram - bin, which dictates how they are mapped into the mel scale. - lower_edge_hertz - Type T2. - Lower bound on the frequencies to be included in the mel spectrum. This - corresponds to the lower edge of the lowest triangular band. - upper_edge_hertz - Type T2. - The desired top edge of the highest frequency band. - output_datatype - Attribute. - The data type of the output tensor. Strictly must be one of the values - from DataType enum in TensorProto whose values correspond to T3. The - default value is 1 = FLOAT. - - Returns - ======= - output : Var - Type T3. - The Mel Weight Matrix. The output has the shape: [floor(dft_length/2) + - 1][num_mel_bins]. - - Notes - ===== - Signature: ``ai.onnx@17::MelWeightMatrix``. - - Type constraints: - - T1: `tensor(int32)`, `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T3: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _MelWeightMatrix( - _MelWeightMatrix.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - ), - _MelWeightMatrix.Inputs( - num_mel_bins=unwrap_vars(num_mel_bins), - dft_length=unwrap_vars(dft_length), - sample_rate=unwrap_vars(sample_rate), - lower_edge_hertz=unwrap_vars(lower_edge_hertz), - upper_edge_hertz=unwrap_vars(upper_edge_hertz), - ), - ) - .get_output_vars( - num_mel_bins=get_value(num_mel_bins), - dft_length=get_value(dft_length), - sample_rate=get_value(sample_rate), - lower_edge_hertz=get_value(lower_edge_hertz), - upper_edge_hertz=get_value(upper_edge_hertz), - ) - .output - ) - - -def min( - data_0: Sequence[Var], -) -> Var: - r""" - Element-wise min of each of the input tensors (with Numpy-style - broadcasting support). All inputs and outputs must have the same data - type. This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - data_0 - Type T. - List of tensors for min. - - Returns - ======= - min : Var - Type T. - Output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Min``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Min( - _Min.Attributes(), - _Min.Inputs( - data_0=unwrap_vars(data_0), - ), - ) - .get_output_vars( - data_0=get_value(data_0), - ) - .min - ) - - -def mod( - A: Var, - B: Var, - *, - fmod: int = 0, -) -> Var: - r""" - Performs element-wise binary modulus (with Numpy-style broadcasting - support). The sign of the remainder is the same as that of the Divisor. - - Mod operator can also behave like C fmod() or numpy.fmod. In this case, - the sign of the remainder however, will be the same as the Dividend (in - contrast to integer mod). To force a behavior like numpy.fmod() an - 'fmod' Attribute is provided. This attribute is set to 0 by default - causing the behavior to be like integer mod. Setting this attribute to 1 - causes the remainder to be calculated similar to that of numpy.fmod(). - - If the input type is floating point, then ``fmod`` attribute must be set - to 1. - - In case of dividend being zero, the results will be platform dependent. - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - Dividend tensor - B - Type T. - Divisor tensor - fmod - Attribute. - Whether the operator should behave like fmod (default=0 meaning it will - do integer mods); Set this to 1 to force fmod treatment - - Returns - ======= - C : Var - Type T. - Remainder tensor - - Notes - ===== - Signature: ``ai.onnx@13::Mod``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Mod( - _Mod.Attributes( - fmod=AttrInt64(fmod, name="fmod"), - ), - _Mod.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def mul( - A: Var, - B: Var, -) -> Var: - r""" - Performs element-wise binary multiplication (with Numpy-style - broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - (Opset 14 change): Extend supported types to include uint8, int8, - uint16, and int16. - - Parameters - ========== - A - Type T. - First operand. - B - Type T. - Second operand. - - Returns - ======= - C : Var - Type T. - Result, has same element type as two inputs - - Notes - ===== - Signature: ``ai.onnx@14::Mul``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Mul( - _Mul.Attributes(), - _Mul.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def multinomial( - input: Var, - *, - dtype: npt.DTypeLike = np.int32, - sample_size: int = 1, - seed: Optional[float] = None, -) -> Var: - r""" - Generate a tensor of samples from a multinomial distribution according - to the probabilities of each of the possible outcomes. - - Parameters - ========== - input - Type T1. - Input tensor with shape [batch_size, class_size], where class_size is - the number of all possible outcomes. Each value along the axis zero - represents the unnormalized log-probability of each corresponding - outcome in a batch. - dtype - Attribute. - (Optional) The data type for the elements of the output tensor, if not - specified, we will use int32. - sample_size - Attribute. - Number of times to sample. - seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - - Returns - ======= - output : Var - Type T2. - Output tensor with shape [batch_size, sample_size], where sample_size is - the number of times to sample. Each value along the axis zero represents - the outcome of the corresponding sample in a batch. - - Notes - ===== - Signature: ``ai.onnx@7::Multinomial``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return ( - _Multinomial( - _Multinomial.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - sample_size=AttrInt64(sample_size, name="sample_size"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), - _Multinomial.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def neg( - X: Var, -) -> Var: - r""" - Neg takes one input data (Tensor) and produces one output data - (Tensor) where each element flipped sign, y = -x, is applied to the - tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::Neg``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` - """ - return ( - _Neg( - _Neg.Attributes(), - _Neg.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def negative_log_likelihood_loss( - input: Var, - target: Var, - weight: Optional[Var] = None, - *, - ignore_index: Optional[int] = None, - reduction: str = "mean", -) -> Var: - r""" - A NegativeLogLikelihoodLoss operator computes (weighted) negative log - likelihood loss. Its "input" tensor has the shape of (N, C, d1, d2, ..., - dk) where k >= 0. The "input" tensor contains log-probabilities for - input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). The - operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). - It encodes class labels (one of C classes) or it may contain a special - value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x - dk samples. The loss value for input[n, :, d_1, d_2,...d_k] being - classified as class c = target[n][d_1][d_2]...[d_k] is computed as: - - :: - - loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. - - When an optional "weight" is provided, the sample loss is calculated as: - - :: - - loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. - - loss is zero for the case when target-value equals ignore_index. - - :: - - loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index - - If "reduction" attribute is set to "none", the operator's output will be - the above loss with shape (N, d1, d2, ..., dk). If "reduction" attribute - is set to "mean" (the default attribute value), the output loss is - (weight) averaged: - - :: - - mean(loss), if "weight" is not provided, - - or if weight is provided, - - :: - - sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. - - If "reduction" attribute is set to "sum", the output is a scalar: - ``sum(loss)``. - - See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. - - Example 1: - - :: - - // negative log likelihood loss, "none" reduction - N, C, d1 = 2, 3, 2 - input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] - target = [[2, 1], [0, 2]] - - loss = np.zeros((N, d1)) - for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] - - // print(loss) - // [[-3. -2.] - // [-0. -2.]] - - Example 2: - - :: - - // weighted negative log likelihood loss, sum reduction - N, C, d1 = 2, 3, 2 - input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] - target = [[2, 1], [0, 2]] - weight = [0.2, 0.3, 0.1] - loss = np.zeros((N, d1)) - for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] * weight[c] - - loss = np.sum(loss) - // print(loss) - // -1.1 - - Example 3: - - :: - - // weighted negative log likelihood loss, mean reduction - N, C, d1 = 2, 3, 2 - input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] - target = [[2, 1], [0, 2]] - weight = [0.2, 0.3, 0.1] - loss = np.zeros((N, d1)) - weight_total = 0 - for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] * weight[c] - weight_total = weight_total + weight[c] - - loss = np.sum(loss) / weight_total - // print(loss) - // -1.57 - - Parameters - ========== - input - Type T. - Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk). - target - Type Tind. - Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value - shall be in range of [0, C). If ignore_index is specified, it may have a - value outside [0, C) and the target values should either be in the range - [0, C) or have the value ignore_index. - weight - Type T. - Optional rescaling weight tensor. If given, it has to be a tensor of - size C. Otherwise, it is treated as if having all ones. - ignore_index - Attribute. - Specifies a target value that is ignored and does not contribute to the - input gradient. It's an optional value. - reduction - Attribute. - Type of reduction to apply to loss: none, sum, mean (default). 'none': - the output is the loss for each sample. 'sum': the output will be - summed. 'mean': the sum of the output will be divided by the sum of - applied weights. - - Returns - ======= - loss : Var - Type T. - The negative log likelihood loss - - Notes - ===== - Signature: ``ai.onnx@13::NegativeLogLikelihoodLoss``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return ( - _NegativeLogLikelihoodLoss( - _NegativeLogLikelihoodLoss.Attributes( - ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), - reduction=AttrString(reduction, name="reduction"), - ), - _NegativeLogLikelihoodLoss.Inputs( - input=unwrap_vars(input), - target=unwrap_vars(target), - weight=unwrap_vars(weight), - ), - ) - .get_output_vars( - input=get_value(input), - target=get_value(target), - weight=get_value(weight), - ) - .loss - ) - - -def non_max_suppression( - boxes: Var, - scores: Var, - max_output_boxes_per_class: Optional[Var] = None, - iou_threshold: Optional[Var] = None, - score_threshold: Optional[Var] = None, - *, - center_point_box: int = 0, -) -> Var: - r""" - Filter out boxes that have high intersection-over-union (IOU) overlap - with previously selected boxes. Bounding boxes with score less than - score_threshold are removed. Bounding box format is indicated by - attribute center_point_box. Note that this algorithm is agnostic to - where the origin is in the coordinate system and more generally is - invariant to orthogonal transformations and translations of the - coordinate system; thus translating or reflections of the coordinate - system result in the same boxes being selected by the algorithm. The - selected_indices output is a set of integers indexing into the input - collection of bounding boxes representing the selected boxes. The - bounding box coordinates corresponding to the selected indices can then - be obtained using the Gather or GatherND operation. - - Parameters - ========== - boxes - Type tensor(float). - An input tensor with shape [num_batches, spatial_dimension, 4]. The - single box data format is indicated by center_point_box. - scores - Type tensor(float). - An input tensor with shape [num_batches, num_classes, spatial_dimension] - max_output_boxes_per_class - Type tensor(int64). - Integer representing the maximum number of boxes to be selected per - batch per class. It is a scalar. Default to 0, which means no output. - iou_threshold - Type tensor(float). - Float representing the threshold for deciding whether boxes overlap too - much with respect to IOU. It is scalar. Value range [0, 1]. Default to - 0. - score_threshold - Type tensor(float). - Float representing the threshold for deciding when to remove boxes based - on score. It is a scalar. - center_point_box - Attribute. - Integer indicate the format of the box data. The default is 0. 0 - the - box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are - the coordinates of any diagonal pair of box corners and the coordinates - can be provided as normalized (i.e., lying in the interval [0, 1]) or - absolute. Mostly used for TF models. 1 - the box data is supplied as - [x_center, y_center, width, height]. Mostly used for Pytorch models. - - Returns - ======= - selected_indices : Var - Type tensor(int64). - selected indices from the boxes tensor. [num_selected_indices, 3], the - selected index format is [batch_index, class_index, box_index]. - - Notes - ===== - Signature: ``ai.onnx@11::NonMaxSuppression``. - - """ - return ( - _NonMaxSuppression( - _NonMaxSuppression.Attributes( - center_point_box=AttrInt64(center_point_box, name="center_point_box"), - ), - _NonMaxSuppression.Inputs( - boxes=unwrap_vars(boxes), - scores=unwrap_vars(scores), - max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), - iou_threshold=unwrap_vars(iou_threshold), - score_threshold=unwrap_vars(score_threshold), - ), - ) - .get_output_vars( - boxes=get_value(boxes), - scores=get_value(scores), - max_output_boxes_per_class=get_value(max_output_boxes_per_class), - iou_threshold=get_value(iou_threshold), - score_threshold=get_value(score_threshold), - ) - .selected_indices - ) - - -def non_zero( - X: Var, -) -> Var: - r""" - Returns the indices of the elements that are non-zero (in row-major - order - by dimension). NonZero behaves similar to numpy.nonzero: - https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html, - but for scalar input, NonZero produces output shape (0, N) instead of - (1, N), which is different from Numpy's behavior. - - Parameters - ========== - X - Type T. - input - - Returns - ======= - Y : Var - Type tensor(int64). - output - - Notes - ===== - Signature: ``ai.onnx@13::NonZero``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _NonZero( - _NonZero.Attributes(), - _NonZero.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def not_( - X: Var, -) -> Var: - r""" - Returns the negation of the input tensor element-wise. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@1::Not``. - - Type constraints: - - T: `tensor(bool)` - """ - return ( - _Not( - _Not.Attributes(), - _Not.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def one_hot( - indices: Var, - depth: Var, - values: Var, - *, - axis: int = -1, -) -> Var: - r""" - Produces a one-hot tensor based on inputs. The locations represented by - the index values in the 'indices' input tensor will have 'on_value' and - the other locations will have 'off_value' in the output tensor, where - 'on_value' and 'off_value' are specified as part of required input - argument 'values', which is a two-element tensor of format [off_value, - on_value]. The rank of the output tensor will be one greater than the - rank of the input tensor. The additional dimension is for one-hot - representation. The additional dimension will be inserted at the - position specified by 'axis'. If 'axis' is not specified then then - additional dimension will be inserted as the innermost dimension, i.e. - axis=-1. The size of the additional dimension is specified by required - scalar input 'depth'. The type of the output tensor is the same as the - type of the 'values' input. Any entries in the 'indices' input tensor - with values outside the range [-depth, depth-1] will result in one-hot - representation with all 'off_value' values in the output tensor. - - :: - - when axis = 0: - output[input[i, j, k], i, j, k] = 1 for all i, j, k and 0 otherwise. - - when axis = -1: - output[i, j, k, input[i, j, k]] = 1 for all i, j, k and 0 otherwise. - - Parameters - ========== - indices - Type T1. - Input tensor containing indices. Any entries in the 'indices' input - tensor with values outside the range [-depth, depth-1] will result in - one-hot representation with all 'off_value' values in the output - tensor.In case 'indices' is of non-integer type, the values will be - casted to int64 before use. - depth - Type T2. - Scalar or Rank 1 tensor containing exactly one element, specifying the - number of classes in one-hot tensor. This is also the size of the - one-hot dimension (specified by 'axis' attribute) added on in the output - tensor. The values in the 'indices' input tensor are expected to be in - the range [-depth, depth-1]. In case 'depth' is of non-integer type, it - will be casted to int64 before use. - values - Type T3. - Rank 1 tensor containing exactly two elements, in the format [off_value, - on_value], where 'on_value' is the value used for filling locations - specified in 'indices' input tensor, and 'off_value' is the value used - for filling locations other than those specified in 'indices' input - tensor. - axis - Attribute. - (Optional) Axis along which one-hot representation in added. Default: - axis=-1. axis=-1 means that the additional dimension will be inserted as - the innermost/last dimension in the output tensor. Negative value means - counting dimensions from the back. Accepted range is [-r-1, r] where r = - rank(indices). - - Returns - ======= - output : Var - Type T3. - Tensor of rank one greater than input tensor 'indices', i.e. - rank(output) = rank(indices) + 1. The data type for the elements of the - output tensor is the same as the type of input 'values' is used. - - Notes - ===== - Signature: ``ai.onnx@11::OneHot``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T3: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _OneHot( - _OneHot.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _OneHot.Inputs( - indices=unwrap_vars(indices), - depth=unwrap_vars(depth), - values=unwrap_vars(values), - ), - ) - .get_output_vars( - indices=get_value(indices), - depth=get_value(depth), - values=get_value(values), - ) - .output - ) - - -def optional( - input: Optional[Var] = None, - *, - type: Optional[Type] = None, -) -> Var: - r""" - Constructs an optional-type value containing either an empty optional of - a certain type specified by the attribute, or a non-empty value - containing the input element. - - Parameters - ========== - input - Type V. - The input element. - type - Attribute. - Type of the element in the optional output - - Returns - ======= - output : Var - Type O. - The optional output enclosing the input element. - - Notes - ===== - Signature: ``ai.onnx@15::Optional``. - - Type constraints: - - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - """ - return ( - _Optional( - _Optional.Attributes( - type=AttrType.maybe(type, name="type"), - ), - _Optional.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def optional_get_element( - input: Var, -) -> Var: - r""" - Outputs the element in the optional-type input. It is an error if the - input value does not have an element and the behavior is undefined in - this case. - - Parameters - ========== - input - Type O. - The optional input. - - Returns - ======= - output : Var - Type V. - Output element in the optional input. - - Notes - ===== - Signature: ``ai.onnx@15::OptionalGetElement``. - - Type constraints: - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _OptionalGetElement( - _OptionalGetElement.Attributes(), - _OptionalGetElement.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def optional_has_element( - input: Var, -) -> Var: - r""" - Returns true if the optional-type input contains an element. If it is an - empty optional-type, this op returns false. - - Parameters - ========== - input - Type O. - The optional input. - - Returns - ======= - output : Var - Type B. - A scalar boolean tensor. If true, it indicates that optional-type input - contains an element. Otherwise, it is empty. - - Notes - ===== - Signature: ``ai.onnx@15::OptionalHasElement``. - - Type constraints: - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - - B: `tensor(bool)` - """ - return ( - _OptionalHasElement( - _OptionalHasElement.Attributes(), - _OptionalHasElement.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def or_( - A: Var, - B: Var, -) -> Var: - r""" - Returns the tensor resulted from performing the ``or`` logical operation - elementwise on the input tensors ``A`` and ``B`` (with Numpy-style - broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@7::Or``. - - Type constraints: - - T: `tensor(bool)` - - T1: `tensor(bool)` - """ - return ( - _Or( - _Or.Attributes(), - _Or.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def prelu( - X: Var, - slope: Var, -) -> Var: - r""" - PRelu takes input data (Tensor) and slope tensor as input, and - produces one output data (Tensor) where the function - ``f(x) = slope * x for x < 0``, ``f(x) = x for x >= 0``., is applied to - the data tensor elementwise. This operator supports **unidirectional - broadcasting** (tensor slope should be unidirectional broadcastable to - input tensor X); for more details please check `the - doc `__. - - Parameters - ========== - X - Type T. - Input tensor - slope - Type T. - Slope tensor. The shape of slope can be smaller than first input X; if - so, its shape must be unidirectional broadcastable to X - - Returns - ======= - Y : Var - Type T. - Output tensor (same size as X) - - Notes - ===== - Signature: ``ai.onnx@16::PRelu``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _PRelu( - _PRelu.Attributes(), - _PRelu.Inputs( - X=unwrap_vars(X), - slope=unwrap_vars(slope), - ), - ) - .get_output_vars( - X=get_value(X), - slope=get_value(slope), - ) - .Y - ) - - -def pad( - data: Var, - pads: Var, - constant_value: Optional[Var] = None, - *, - mode: str = "constant", -) -> Var: - r""" - Given a tensor containing the data to be padded (``data``), a tensor - containing the number of start and end pad values for axis (``pads``), - (optionally) a ``mode``, and (optionally) ``constant_value``, a padded - tensor (``output``) is generated. - - The three supported ``modes`` are (similar to corresponding modes - supported by ``numpy.pad``): - - 1) ``constant``\ (default) - pads with a given constant value as - specified by ``constant_value`` (which defaults to 0, empty string, - or False) - - 2) ``reflect`` - pads with the reflection of the vector mirrored on the - first and last values of the vector along each axis - - 3) ``edge`` - pads with the edge values of array - - Example 1 (``constant`` mode): Insert 0 pads to the beginning of the - second dimension. - - data = [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], ] - - pads = [0, 2, 0, 0] - - mode = 'constant' - - constant_value = 0.0 - - output = [ [0.0, 0.0, 1.0, 1.2], [0.0, 0.0, 2.3, 3.4], [0.0, 0.0, 4.5, - 5.7], ] - - Example 2 (``reflect`` mode): data = [ [1.0, 1.2], [2.3, 3.4], [4.5, - 5.7], ] - - pads = [0, 2, 0, 0] - - mode = 'reflect' - - output = [ [1.0, 1.2, 1.0, 1.2], [2.3, 3.4, 2.3, 3.4], [4.5, 5.7, 4.5, - 5.7], ] - - Example 3 (``edge`` mode): data = [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'edge' - - output = [ [1.0, 1.0, 1.0, 1.2], [2.3, 2.3, 2.3, 3.4], [4.5, 4.5, 4.5, - 5.7], ] - - Parameters - ========== - data - Type T. - Input tensor. - pads - Type tensor(int64). - Tensor of integers indicating the number of padding elements to add or - remove (if negative) at the beginning and end of each axis. For 2D input - tensor, it is the number of pixels. ``pads`` should be a 1D tensor of - shape [2 \* input_rank]. ``pads`` format should be: [x1_begin, - x2_begin,...,x1_end, x2_end,...], where xi_begin is the number of pad - values added at the beginning of axis ``i`` and xi_end, the number of - pad values added at the end of axis ``i``. - constant_value - Type T. - (Optional) A scalar value to be used if the mode chosen is ``constant`` - (by default it is 0, empty string or False). - mode - Attribute. - Supported modes: ``constant``\ (default), ``reflect``, ``edge`` - - Returns - ======= - output : Var - Type T. - Tensor after padding. - - Notes - ===== - Signature: ``ai.onnx@13::Pad``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), - _Pad.Inputs( - data=unwrap_vars(data), - pads=unwrap_vars(pads), - constant_value=unwrap_vars(constant_value), - ), - ) - .get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - ) - .output - ) - - -def pow( - X: Var, - Y: Var, -) -> Var: - r""" - Pow takes input data (Tensor) and exponent Tensor, and produces one - output data (Tensor) where the function ``f(x) = x^exponent``, is - applied to the data tensor elementwise. This operator supports - **multidirectional (i.e., Numpy-style) broadcasting**; for more details - please check `the - doc `__. - - Parameters - ========== - X - Type T. - First operand, base of the exponent. - Y - Type T1. - Second operand, power of the exponent. - - Returns - ======= - Z : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@15::Pow``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)` - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Pow( - _Pow.Attributes(), - _Pow.Inputs( - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ) - .get_output_vars( - X=get_value(X), - Y=get_value(Y), - ) - .Z - ) - - -def qlinear_conv( - x: Var, - x_scale: Var, - x_zero_point: Var, - w: Var, - w_scale: Var, - w_zero_point: Var, - y_scale: Var, - y_zero_point: Var, - B: Optional[Var] = None, - *, - auto_pad: str = "NOTSET", - dilations: Optional[Iterable[int]] = None, - group: int = 1, - kernel_shape: Optional[Iterable[int]] = None, - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: - r""" - The convolution operator consumes a quantized input tensor, its scale - and zero point, a quantized filter, its scale and zero point, and - output's scale and zero point, and computes the quantized output. Each - scale and zero-point pair must have same shape. It means they must be - either scalars (per tensor) or 1-D tensors (per output channel). Each - input or output and its related zero point must have same type. When - bias is present it must be quantized using scale = input scale \* weight - scale and zero point as 0. - - Parameters - ========== - x - Type T1. - Input data tensor from previous layer; has size (N x C x H x W), where N - is the batch size, C is the number of channels, and H and W are the - height and width. Note that this is for the 2D image. Otherwise the size - is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in - effect, the operation expects input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. - x_scale - Type tensor(float). - Scale tensor for input 'x'. It's a scalar, which means a - per-tensor/layer quantization. - x_zero_point - Type T1. - Zero point tensor for input 'x'. It's a scalar, which means a - per-tensor/layer quantization. - w - Type T2. - The weight tensor that will be used in the convolutions; has size (M x - C/group x kH x kW), where C is the number of channels, and kH and kW are - the height and width of the kernel, and M is the number of feature maps. - For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x - k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. - Optionally, if dimension denotation is in effect, the operation expects - the weight tensor to arrive with the dimension denotation of - [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL - ...]. X.shape[1] == (W.shape[1] \* group) == C (assuming zero based - indices for the shape array). Or in other words FILTER_IN_CHANNEL should - be equal to DATA_CHANNEL. - w_scale - Type tensor(float). - Scale tensor for input 'w'. It could be a scalar or a 1-D tensor, which - means a per-tensor/layer or per output channel quantization. If it's a - 1-D tensor, its number of elements should be equal to the number of - output channels (M). - w_zero_point - Type T2. - Zero point tensor for input 'w'. It could be a scalar or a 1-D tensor, - which means a per-tensor/layer or per output channel quantization. If - it's a 1-D tensor, its number of elements should be equal to the number - of output channels (M). - y_scale - Type tensor(float). - Scale tensor for output 'y'. It's a scalar, which means a - per-tensor/layer quantization. - y_zero_point - Type T3. - Zero point tensor for output 'y'. It's a scalar, which means a - per-tensor/layer quantization. - B - Type T4. - Optional 1D bias to be added to the convolution, has size of M. Bias - must be quantized using scale = x_scale \* w_scale and zero_point = 0 - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. - dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults to 1 along each spatial axis. - group - Attribute. - number of groups input channels and output channels are divided into. - default is 1. - kernel_shape - Attribute. - The shape of the convolution kernel. If not present, should be inferred - from input 'w'. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0.The value represent the number - of pixels added to the beginning and end part of the corresponding - axis.\ ``pads`` format should be as follow [x1_begin, x2_begin...x1_end, - x2_end,...], where xi_begin the number ofpixels added at the beginning - of axis ``i`` and xi_end, the number of pixels added at the end of axis - ``i``.This attribute cannot be used simultaneously with auto_pad - attribute. If not present, the padding defaultsto 0 along start and end - of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - - Returns - ======= - y : Var - Type T3. - Output data tensor that contains the result of the convolution. The - output dimensions are functions of the kernel size, stride size, and pad - lengths. - - Notes - ===== - Signature: ``ai.onnx@10::QLinearConv``. - - Type constraints: - - T1: `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(int8)`, `tensor(uint8)` - - T4: `tensor(int32)` - """ - return ( - _QLinearConv( - _QLinearConv.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _QLinearConv.Inputs( - x=unwrap_vars(x), - x_scale=unwrap_vars(x_scale), - x_zero_point=unwrap_vars(x_zero_point), - w=unwrap_vars(w), - w_scale=unwrap_vars(w_scale), - w_zero_point=unwrap_vars(w_zero_point), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - w=get_value(w), - w_scale=get_value(w_scale), - w_zero_point=get_value(w_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - B=get_value(B), - ) - .y - ) - - -def qlinear_matmul( - a: Var, - a_scale: Var, - a_zero_point: Var, - b: Var, - b_scale: Var, - b_zero_point: Var, - y_scale: Var, - y_zero_point: Var, -) -> Var: - r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. - It consumes two quantized input tensors, their scales and zero points, - scale and zero point of output, and computes the quantized output. The - quantization formula is y = saturate((x / y_scale) + y_zero_point). For - (x / y_scale), it is rounding to nearest ties to even. Refer to - https://en.wikipedia.org/wiki/Rounding for details. Scale and zero point - must have same shape. They must be either scalar (per tensor) or N-D - tensor (per row for 'a' and per column for 'b'). Scalar refers to per - tensor quantization whereas N-D refers to per row or per column - quantization. If the input is 2D of shape [M, K] then zero point and - scale tensor may be an M element vector [v_1, v_2, ..., v_M] for per row - quantization and K element vector of shape [v_1, v_2, ..., v_K] for per - column quantization. If the input is N-D tensor with shape [D1, D2, M, - K] then zero point and scale tensor may have shape [D1, D2, M, 1] for - per row quantization and shape [D1, D2, 1, K] for per column - quantization. Production must never overflow, and accumulation may - overflow if and only if in 32 bits. - - Parameters - ========== - a - Type T1. - N-dimensional quantized matrix a - a_scale - Type tensor(float). - scale of quantized input a - a_zero_point - Type T1. - zero point of quantized input a - b - Type T2. - N-dimensional quantized matrix b - b_scale - Type tensor(float). - scale of quantized input b - b_zero_point - Type T2. - zero point of quantized input b - y_scale - Type tensor(float). - scale of quantized output y - y_zero_point - Type T3. - zero point of quantized output y - - Returns - ======= - y : Var - Type T3. - Quantized matrix multiply results from a \* b - - Notes - ===== - Signature: ``ai.onnx@10::QLinearMatMul``. - - Type constraints: - - T1: `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(int8)`, `tensor(uint8)` - """ - return ( - _QLinearMatMul( - _QLinearMatMul.Attributes(), - _QLinearMatMul.Inputs( - a=unwrap_vars(a), - a_scale=unwrap_vars(a_scale), - a_zero_point=unwrap_vars(a_zero_point), - b=unwrap_vars(b), - b_scale=unwrap_vars(b_scale), - b_zero_point=unwrap_vars(b_zero_point), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ) - .get_output_vars( - a=get_value(a), - a_scale=get_value(a_scale), - a_zero_point=get_value(a_zero_point), - b=get_value(b), - b_scale=get_value(b_scale), - b_zero_point=get_value(b_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - ) - .y - ) - - -def quantize_linear( - x: Var, - y_scale: Var, - y_zero_point: Optional[Var] = None, - *, - axis: int = 1, -) -> Var: - r""" - The linear quantization operator. It consumes a high precision tensor, a - scale, and a zero point to compute the low precision / quantized tensor. - The scale factor and zero point must have same shape, and can be either - a scalar for per-tensor / per layer quantization, or a 1-D tensor for - per-axis quantization. The quantization formula is y = saturate ((x / - y_scale) + y_zero_point). For saturation, it saturates to [0, 255] if - it's uint8, or [-128, 127] if it's int8. For (x / y_scale), it's - rounding to the nearest even. Refer to - https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and - 'y' must have same type. - - Parameters - ========== - x - Type T1. - N-D full precision Input tensor to be quantized. - y_scale - Type tensor(float). - Scale for doing quantization to get 'y'. It can be a scalar, which means - per-tensor/layer quantization, or a 1-D Tensor for per-axis - quantization. - y_zero_point - Type T2. - Zero point for doing quantization to get 'y'. Shape must match y_scale. - Default is uint8 with zero point of 0 if it's not specified. - axis - Attribute. - (Optional) The axis of the quantization dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - - Returns - ======= - y : Var - Type T2. - N-D quantized output tensor. It has same shape as input 'x'. - - Notes - ===== - Signature: ``ai.onnx@13::QuantizeLinear``. - - Type constraints: - - T1: `tensor(float)`, `tensor(int32)` - - T2: `tensor(int8)`, `tensor(uint8)` - """ - return ( - _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _QuantizeLinear.Inputs( - x=unwrap_vars(x), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ) - .get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - ) - .y - ) - - -def rnn( - X: Var, - W: Var, - R: Var, - B: Optional[Var] = None, - sequence_lens: Optional[Var] = None, - initial_h: Optional[Var] = None, - *, - activation_alpha: Optional[Iterable[float]] = None, - activation_beta: Optional[Iterable[float]] = None, - activations: Iterable[str] = ("Tanh", "Tanh"), - clip: Optional[float] = None, - direction: str = "forward", - hidden_size: Optional[int] = None, - layout: int = 0, -) -> tuple[Var, Var]: - r""" - Computes an one-layer simple RNN. This operator is usually supported via - some custom implementation such as CuDNN. - - Notations: - - - ``X`` - input tensor - - ``i`` - input gate - - ``t`` - time step (t-1 means previous time step) - - ``Wi`` - W parameter weight matrix for input gate - - ``Ri`` - R recurrence weight matrix for input gate - - ``Wbi`` - W parameter bias vector for input gate - - ``Rbi`` - R parameter bias vector for input gate - - ``WBi`` - W parameter weight matrix for backward input gate - - ``RBi`` - R recurrence weight matrix for backward input gate - - ``WBbi`` - WR bias vectors for backward input gate - - ``RBbi`` - RR bias vectors for backward input gate - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 - - Activation functions: - - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) - - NOTE: Below are optional - - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) - - Equations (Default: f=Tanh): - - - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has - **optional** inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. - - Parameters - ========== - X - Type T. - The input sequences packed (and potentially padded) into one 3-D tensor - with the shape of ``[seq_length, batch_size, input_size]``. - W - Type T. - The weight tensor for input gate. Concatenation of ``Wi`` and ``WBi`` - (if bidirectional). The tensor has shape - ``[num_directions, hidden_size, input_size]``. - R - Type T. - The recurrence weight tensor. Concatenation of ``Ri`` and ``RBi`` (if - bidirectional). The tensor has shape - ``[num_directions, hidden_size, hidden_size]``. - B - Type T. - The bias tensor for input gate. Concatenation of ``[Wbi, Rbi]`` and - ``[WBbi, RBbi]`` (if bidirectional). The tensor has shape - ``[num_directions, 2*hidden_size]``. Optional: If not specified - - assumed to be 0. - sequence_lens - Type T1. - Optional tensor specifying lengths of the sequences in a batch. If not - specified - assumed all sequences in the batch to have length - ``seq_length``. It has shape ``[batch_size]``. - initial_h - Type T. - Optional initial value of the hidden. If not specified - assumed to be - 0. It has shape ``[num_directions, batch_size, hidden_size]``. - activation_alpha - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX - operators.For example with LeakyRelu, the default alpha is 0.01. - activation_beta - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX operators. - activations - Attribute. - One (or two if bidirectional) activation function for input gate. The - activation function must be one of the activation functions specified - above. Optional: Default ``Tanh`` if not specified. - clip - Attribute. - Cell clip threshold. Clipping bounds the elements of a tensor in the - range of [-threshold, +threshold] and is applied to the input of - activations. No clip if not specified. - direction - Attribute. - Specify if the RNN is forward, reverse, or bidirectional. Must be one of - forward (default), reverse, or bidirectional. - hidden_size - Attribute. - Number of neurons in the hidden layer - layout - Attribute. - The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the - following shapes are expected: X.shape = [seq_length, batch_size, - input_size], Y.shape = [seq_length, num_directions, batch_size, - hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, - hidden_size]. If 1, the following shapes are expected: X.shape = - [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, - num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, - num_directions, hidden_size]. - - Returns - ======= - Y : Var - Type T. - A tensor that concats all the intermediate output values of the hidden. - It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. - Y_h : Var - Type T. - The last output value of the hidden. It has shape - ``[num_directions, batch_size, hidden_size]``. - - Notes - ===== - Signature: ``ai.onnx@14::RNN``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(int32)` - """ - return ( - _RNN( - _RNN.Attributes( - activation_alpha=AttrFloat32s.maybe( - activation_alpha, name="activation_alpha" - ), - activation_beta=AttrFloat32s.maybe( - activation_beta, name="activation_beta" - ), - activations=AttrStrings(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - layout=AttrInt64(layout, name="layout"), - ), - _RNN.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - R=unwrap_vars(R), - B=unwrap_vars(B), - sequence_lens=unwrap_vars(sequence_lens), - initial_h=unwrap_vars(initial_h), - ), - ) - .get_output_vars( - X=get_value(X), - W=get_value(W), - R=get_value(R), - B=get_value(B), - sequence_lens=get_value(sequence_lens), - initial_h=get_value(initial_h), - ) - ._unpack_to_any() - ) - - -def random_normal( - *, - dtype: npt.DTypeLike = np.float32, - mean: float = 0.0, - scale: float = 1.0, - seed: Optional[float] = None, - shape: Iterable[int], -) -> Var: - r""" - Generate a tensor with random values drawn from a normal distribution. - The shape of the tensor is specified by the ``shape`` argument and the - parameter of the normal distribution specified by ``mean`` and - ``scale``. - - The data type is specified by the 'dtype' argument. The 'dtype' argument - must be one of the data types specified in the 'DataType' enum field in - the TensorProto message. - - Parameters - ========== - dtype - Attribute. - The data type for the elements of the output tensor. Default is - TensorProto::FLOAT. - mean - Attribute. - The mean of the normal distribution. - scale - Attribute. - The standard deviation of the normal distribution. - seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - shape - Attribute. - The shape of the output tensor. - - Returns - ======= - output : Var - Type T. - Output tensor of random values drawn from normal distribution - - Notes - ===== - Signature: ``ai.onnx@1::RandomNormal``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _RandomNormal( - _RandomNormal.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - mean=AttrFloat32(mean, name="mean"), - scale=AttrFloat32(scale, name="scale"), - seed=AttrFloat32.maybe(seed, name="seed"), - shape=AttrInt64s(shape, name="shape"), - ), - _RandomNormal.Inputs(), - ) - .get_output_vars() - .output - ) - - -def random_normal_like( - input: Var, - *, - dtype: Optional[npt.DTypeLike] = None, - mean: float = 0.0, - scale: float = 1.0, - seed: Optional[float] = None, -) -> Var: - r""" - Generate a tensor with random values drawn from a normal distribution. - The shape of the output tensor is copied from the shape of the input - tensor, and the parameters of the normal distribution are specified by - ``mean`` and ``scale``. - - The data type is specified by the 'dtype' argument, or copied from the - input tensor if not provided. The 'dtype' argument must be one of the - data types specified in the 'DataType' enum field in the TensorProto - message, and be valid as an output type. - - Parameters - ========== - input - Type T1. - Input tensor to copy shape and optionally type information from. - dtype - Attribute. - (Optional) The data type for the elements of the output tensor, if not - specified, we will use the data type of the input tensor. - mean - Attribute. - The mean of the normal distribution. - scale - Attribute. - The standard deviation of the normal distribution. - seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - - Returns - ======= - output : Var - Type T2. - Output tensor of random values drawn from normal distribution - - Notes - ===== - Signature: ``ai.onnx@1::RandomNormalLike``. - - Type constraints: - - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _RandomNormalLike( - _RandomNormalLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - mean=AttrFloat32(mean, name="mean"), - scale=AttrFloat32(scale, name="scale"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), - _RandomNormalLike.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def random_uniform( - *, - dtype: npt.DTypeLike = np.float32, - high: float = 1.0, - low: float = 0.0, - seed: Optional[float] = None, - shape: Iterable[int], -) -> Var: - r""" - Generate a tensor with random values drawn from a uniform distribution. - The shape of the tensor is specified by the ``shape`` argument and the - range by ``low`` and ``high``. - - The data type is specified by the 'dtype' argument. The 'dtype' argument - must be one of the data types specified in the 'DataType' enum field in - the TensorProto message. - - Parameters - ========== - dtype - Attribute. - The data type for the elements of the output tensor. If not specified, - default is TensorProto::FLOAT. - high - Attribute. - Upper boundary of the output values. - low - Attribute. - Lower boundary of the output values. - seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - shape - Attribute. - The shape of the output tensor. - - Returns - ======= - output : Var - Type T. - Output tensor of random values drawn from uniform distribution - - Notes - ===== - Signature: ``ai.onnx@1::RandomUniform``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _RandomUniform( - _RandomUniform.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - high=AttrFloat32(high, name="high"), - low=AttrFloat32(low, name="low"), - seed=AttrFloat32.maybe(seed, name="seed"), - shape=AttrInt64s(shape, name="shape"), - ), - _RandomUniform.Inputs(), - ) - .get_output_vars() - .output - ) - - -def random_uniform_like( - input: Var, - *, - dtype: Optional[npt.DTypeLike] = None, - high: float = 1.0, - low: float = 0.0, - seed: Optional[float] = None, -) -> Var: - r""" - Generate a tensor with random values drawn from a uniform distribution. - The shape of the output tensor is copied from the shape of the input - tensor, and the parameters of the uniform distribution are specified by - ``low`` and ``high``. - - The data type is specified by the 'dtype' argument, or copied from the - input tensor if not provided. The 'dtype' argument must be one of the - data types specified in the 'DataType' enum field in the TensorProto - message and be valid as an output type. - - Parameters - ========== - input - Type T1. - Input tensor to copy shape and optionally type information from. - dtype - Attribute. - (Optional) The data type for the elements of the output tensor, if not - specified, we will use the data type of the input tensor. - high - Attribute. - Upper boundary of the output values. - low - Attribute. - Lower boundary of the output values. - seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - - Returns - ======= - output : Var - Type T2. - Output tensor of random values drawn from uniform distribution - - Notes - ===== - Signature: ``ai.onnx@1::RandomUniformLike``. - - Type constraints: - - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _RandomUniformLike( - _RandomUniformLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - high=AttrFloat32(high, name="high"), - low=AttrFloat32(low, name="low"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), - _RandomUniformLike.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def range( - start: Var, - limit: Var, - delta: Var, -) -> Var: - r""" - Generate a tensor containing a sequence of numbers that begin at - ``start`` and extends by increments of ``delta`` up to ``limit`` - (exclusive). - - The number of elements in the output of range is computed as below: - - :: - - number_of_elements = max( ceil( (limit - start) / delta ) , 0 ) - - The pseudocode determining the contents of the output is shown below: - - :: - - for(int i=0; i Var: - r""" - Reciprocal takes one input data (Tensor) and produces one output data - (Tensor) where the reciprocal is, y = 1/x, is applied to the tensor - elementwise. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::Reciprocal``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Reciprocal( - _Reciprocal.Attributes(), - _Reciprocal.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def reduce_l1( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the L1 norm of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields 0. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceL1``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _ReduceL1( - _ReduceL1.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceL1.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def reduce_l2( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the L2 norm of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields 0. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceL2``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _ReduceL2( - _ReduceL2.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceL2.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def reduce_log_sum( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the log sum of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields minus infinity (if - supported by the datatype) or undefined otherwise. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceLogSum``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _ReduceLogSum( - _ReduceLogSum.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceLogSum.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def reduce_log_sum_exp( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the log sum exponent of the input tensor's elements along the - provided axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields minus infinity (if - supported by the datatype) or undefined otherwise. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceLogSumExp``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _ReduceLogSumExp( - _ReduceLogSumExp.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceLogSumExp.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def reduce_max( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the max of the input tensor's elements along the provided axes. - The resulting tensor has the same rank as the input if ``keepdims`` - equals 1. If ``keepdims`` equals 0, then the resulting tensor has the - reduced dimension pruned. Input tensors of rank zero are valid. - Reduction over an empty set of values yields minus infinity (if - supported by the datatype) or the minimum value of the data type - otherwise. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceMax``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _ReduceMax( - _ReduceMax.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceMax.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def reduce_mean( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the mean of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields undefined. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceMean``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _ReduceMean( - _ReduceMean.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceMean.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def reduce_min( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the min of the input tensor's elements along the provided axes. - The resulting tensor has the same rank as the input if ``keepdims`` - equals 1. If ``keepdims`` equals 0, then the resulting tensor has the - reduced dimension pruned. Input tensors of rank zero are valid. - Reduction over an empty set of values yields plus infinity (if supported - by the datatype) or the maximum value of the data type otherwise. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceMin``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _ReduceMin( - _ReduceMin.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceMin.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def reduce_prod( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the product of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields 1. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceProd``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _ReduceProd( - _ReduceProd.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceProd.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def reduce_sum( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: - r""" - Computes the sum of the input tensor's elements along the provided axes. - The resulting tensor has the same rank as the input if ``keepdims`` - equals 1. If ``keepdims`` equals 0, then the resulting tensor has the - reduced dimension pruned. Input tensors of rank zero are valid. - Reduction over an empty set of values yields 0. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceSum``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _ReduceSum( - _ReduceSum.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceSum.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_sum_square( - data: Var, - *, - axes: Optional[Iterable[int]] = None, - keepdims: int = 1, -) -> Var: - r""" - Computes the sum square of the input tensor's elements along the - provided axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields 0. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::ReduceSumSquare``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return ( - _ReduceSumSquare( - _ReduceSumSquare.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _ReduceSumSquare.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .reduced - ) - - -def relu( - X: Var, -) -> Var: - r""" - Relu takes one input data (Tensor) and produces one output data - (Tensor) where the rectified linear function, y = max(0, x), is - applied to the tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@14::Relu``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` - """ - return ( - _Relu( - _Relu.Attributes(), - _Relu.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def reshape( - data: Var, - shape: Var, - *, - allowzero: int = 0, -) -> Var: - r""" - Reshape the input tensor similar to numpy.reshape. First input is the - data tensor, second input is a shape tensor which specifies the output - shape. It outputs the reshaped tensor. At most one dimension of the new - shape can be -1. In this case, the value is inferred from the size of - the tensor and the remaining dimensions. A dimension could also be 0, in - which case the actual dimension value is unchanged (i.e. taken from the - input tensor). If 'allowzero' is set, and the new shape includes 0, the - dimension will be set explicitly to zero (i.e. not taken from input - tensor). Shape (second input) could be an empty shape, which means - converting to a scalar. The input tensor's shape and the output tensor's - shape are required to have the same number of elements. - - If the attribute 'allowzero' is set, it is invalid for the specified - shape to contain both a zero value and -1, as the value of the dimension - corresponding to -1 cannot be determined uniquely. - - Parameters - ========== - data - Type T. - An input tensor. - shape - Type tensor(int64). - Specified shape for output. - allowzero - Attribute. - (Optional) By default, when any value in the 'shape' input is equal to - zero the corresponding dimension value is copied from the input tensor - dynamically. allowzero=1 indicates that if any value in the 'shape' - input is set to zero, the zero value is honored, similar to NumPy. - - Returns - ======= - reshaped : Var - Type T. - Reshaped data. - - Notes - ===== - Signature: ``ai.onnx@14::Reshape``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), - _Reshape.Inputs( - data=unwrap_vars(data), - shape=unwrap_vars(shape), - ), - ) - .get_output_vars( - data=get_value(data), - shape=get_value(shape), - ) - .reshaped - ) - - -def resize( - X: Var, - roi: Optional[Var] = None, - scales: Optional[Var] = None, - sizes: Optional[Var] = None, - *, - coordinate_transformation_mode: str = "half_pixel", - cubic_coeff_a: float = -0.75, - exclude_outside: int = 0, - extrapolation_value: float = 0.0, - mode: str = "nearest", - nearest_mode: str = "round_prefer_floor", -) -> Var: - r""" - Resize the input tensor. In general, it calculates every value in the - output tensor as a weighted average of neighborhood (a.k.a. sampling - locations) in the input tensor. Each dimension value of the output - tensor is: output_dimension = floor(input_dimension \* (roi_end - - roi_start) \* scale) if input "sizes" is not specified. - - Parameters - ========== - X - Type T1. - N-D tensor - roi - Type T2. - 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is - the rank of X. The RoIs' coordinates are normalized in the coordinate - system of the input image. It only takes effect when - coordinate_transformation_mode is "tf_crop_and_resize" - scales - Type tensor(float). - The scale array along each dimension. It takes value greater than 0. If - it's less than 1, it's sampling down, otherwise, it's upsampling. The - number of elements of 'scales' should be the same as the rank of input - 'X'. One of 'scales' and 'sizes' MUST be specified and it is an error if - both are specified. If 'sizes' is needed, the user can use an empty - string as the name of 'scales' in this operator's input list. - sizes - Type tensor(int64). - The size of the output tensor. The number of elements of 'sizes' should - be the same as the rank of input 'X'. Only one of 'scales' and 'sizes' - can be specified. - coordinate_transformation_mode - Attribute. - This attribute describes how to transform the coordinate in the resized - tensor to the coordinate in the original tensor. - - The coordinate of each dimension is transformed individually. Let's - describe a case using axis x as an example. Denote x_resized as the - coordinate of axis x in the resized tensor, x_original as the coordinate - of axis x in the original tensor, length_original as the length of the - original tensor in axis x, length_resized as the length of the resized - tensor in axis x, roi_x = (start_x, end_x) of the axis x in input "roi", - scale = length_resized / length_original, - - if coordinate_transformation_mode is "half_pixel", x_original = - (x_resized + 0.5) / scale - 0.5, - - if coordinate_transformation_mode is "pytorch_half_pixel", x_original = - length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0, - - if coordinate_transformation_mode is "align_corners", x_original = - x_resized \* (length_original - 1) / (length_resized - 1), - - if coordinate_transformation_mode is "asymmetric", x_original = - x_resized / scale, - - if coordinate_transformation_mode is "tf_crop_and_resize", x_original = - length_resized > 1 ? start_x \* (length_original - 1) + x_resized \* - (end_x - start_x) \* (length_original - 1) / (length_resized - 1) : 0.5 - \* (start_x + end_x) \* (length_original - 1). - cubic_coeff_a - Attribute. - The coefficient 'a' used in cubic interpolation. Two common choice are - -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out - Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the - details. This attribute is valid only if "mode" is "cubic". - exclude_outside - Attribute. - If set to 1, the weight of sampling locations outside the tensor will be - set to 0 and the weight will be renormalized so that their sum is 1.0. - The default value is 0. - extrapolation_value - Attribute. - When coordinate_transformation_mode is "tf_crop_and_resize" and - x_original is outside the range [0, length_original - 1], this value is - used as the corresponding output value. Default is 0.0f. - mode - Attribute. - Three interpolation modes: nearest (default), linear and cubic. The - "linear" mode includes linear interpolation for 1D tensor and N-linear - interpolation for N-D tensor (for example, bilinear interpolation for 2D - tensor). The "cubic" mode includes cubic interpolation for 1D tensor and - N-cubic interpolation for N-D tensor (for example, bicubic interpolation - for 2D tensor). - nearest_mode - Attribute. - Four modes: round_prefer_floor (default, as known as round half down), - round_prefer_ceil (as known as round half up), floor, ceil. Only used by - nearest interpolation. It indicates how to get "nearest" pixel in input - tensor from x_original, so this attribute is valid only if "mode" is - "nearest". - - Returns - ======= - Y : Var - Type T1. - N-D tensor after resizing - - Notes - ===== - Signature: ``ai.onnx@13::Resize``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Resize( - _Resize.Attributes( - coordinate_transformation_mode=AttrString( - coordinate_transformation_mode, - name="coordinate_transformation_mode", - ), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32( - extrapolation_value, name="extrapolation_value" - ), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), - _Resize.Inputs( - X=unwrap_vars(X), - roi=unwrap_vars(roi), - scales=unwrap_vars(scales), - sizes=unwrap_vars(sizes), - ), - ) - .get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), - ) - .Y - ) - - -def reverse_sequence( - input: Var, - sequence_lens: Var, - *, - batch_axis: int = 1, - time_axis: int = 0, -) -> Var: - r""" - Reverse batch of sequences having different lengths specified by - ``sequence_lens``. - - For each slice i iterating on batch axis, the operator reverses the - first sequence_lens[i] elements on time axis, and copies elements whose - index's beyond sequence_lens[i] to the output. So the output slice i - contains reversed sequences on the first sequence_lens[i] elements, then - have original values copied for the other elements. - - Example 1: input = [[0.0, 4.0, 8.0, 12.0], [1.0, 5.0, 9.0, 13.0], [2.0, - 6.0, 10.0, 14.0], [3.0, 7.0, 11.0, 15.0]] sequence_lens = [4, 3, 2, 1] - time_axis = 0 batch_axis = 1 - - output = [[3.0, 6.0, 9.0, 12.0], [2.0, 5.0, 8.0, 13.0], [1.0, 4.0, 10.0, - 14.0], [0.0, 7.0, 11.0, 15.0]] - - Example 2: input = [[0.0, 1.0, 2.0, 3.0 ], [4.0, 5.0, 6.0, 7.0 ], [8.0, - 9.0, 10.0, 11.0], [12.0, 13.0, 14.0, 15.0]] sequence_lens = [1, 2, 3, 4] - time_axis = 1 batch_axis = 0 - - output = [[0.0, 1.0, 2.0, 3.0 ], [5.0, 4.0, 6.0, 7.0 ], [10.0, 9.0, 8.0, - 11.0], [15.0, 14.0, 13.0, 12.0]] - - Parameters - ========== - input - Type T. - Tensor of rank r >= 2. - sequence_lens - Type tensor(int64). - Tensor specifying lengths of the sequences in a batch. It has shape - ``[batch_size]``. - batch_axis - Attribute. - (Optional) Specify which axis is batch axis. Must be one of 1 (default), - or 0. - time_axis - Attribute. - (Optional) Specify which axis is time axis. Must be one of 0 (default), - or 1. - - Returns - ======= - Y : Var - Type T. - Tensor with same shape of input. - - Notes - ===== - Signature: ``ai.onnx@10::ReverseSequence``. - - Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _ReverseSequence( - _ReverseSequence.Attributes( - batch_axis=AttrInt64(batch_axis, name="batch_axis"), - time_axis=AttrInt64(time_axis, name="time_axis"), - ), - _ReverseSequence.Inputs( - input=unwrap_vars(input), - sequence_lens=unwrap_vars(sequence_lens), - ), - ) - .get_output_vars( - input=get_value(input), - sequence_lens=get_value(sequence_lens), - ) - .Y - ) - - -def roi_align( - X: Var, - rois: Var, - batch_indices: Var, - *, - coordinate_transformation_mode: str = "half_pixel", - mode: str = "avg", - output_height: int = 1, - output_width: int = 1, - sampling_ratio: int = 0, - spatial_scale: float = 1.0, -) -> Var: - r""" - Region of Interest (RoI) align operation described in the `Mask R-CNN - paper `__. RoiAlign consumes an input - tensor X and region of interests (rois) to apply pooling across each - RoI; it produces a 4-D tensor of shape (num_rois, C, output_height, - output_width). - - RoiAlign is proposed to avoid the misalignment by removing quantizations - while converting from original image into feature map and from feature - map into RoI feature; in each ROI bin, the value of the sampled - locations are computed directly through bilinear interpolation. - - Parameters - ========== - X - Type T1. - Input data tensor from the previous operator; 4-D feature map of shape - (N, C, H, W), where N is the batch size, C is the number of channels, - and H and W are the height and the width of the data. - rois - Type T1. - RoIs (Regions of Interest) to pool over; rois is 2-D input of shape - (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates - are in the coordinate system of the input image. Each coordinate set has - a 1:1 correspondence with the 'batch_indices' input. - batch_indices - Type T2. - 1-D tensor of shape (num_rois,) with each element denoting the index of - the corresponding image in the batch. - coordinate_transformation_mode - Attribute. - Allowed values are 'half_pixel' and 'output_half_pixel'. Use the value - 'half_pixel' to pixel shift the input coordinates by -0.5 (the - recommended behavior). Use the value 'output_half_pixel' to omit the - pixel shift for the input (use this for a backward-compatible behavior). - mode - Attribute. - The pooling method. Two modes are supported: 'avg' and 'max'. Default is - 'avg'. - output_height - Attribute. - default 1; Pooled output Y's height. - output_width - Attribute. - default 1; Pooled output Y's width. - sampling_ratio - Attribute. - Number of sampling points in the interpolation grid used to compute the - output value of each pooled output bin. If > 0, then exactly - sampling_ratio x sampling_ratio grid points are used. If == 0, then an - adaptive number of grid points are used (computed as ceil(roi_width / - output_width), and likewise for height). Default is 0. - spatial_scale - Attribute. - Multiplicative spatial scale factor to translate ROI coordinates from - their input spatial scale to the scale used when pooling, i.e., spatial - scale of the input feature map X relative to the input image. E.g.; - default is 1.0f. - - Returns - ======= - Y : Var - Type T1. - RoI pooled output, 4-D tensor of shape (num_rois, C, output_height, - output_width). The r-th batch element Y[r-1] is a pooled feature map - corresponding to the r-th RoI X[r-1]. - - Notes - ===== - Signature: ``ai.onnx@16::RoiAlign``. - - Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int64)` - """ - return ( - _RoiAlign( - _RoiAlign.Attributes( - coordinate_transformation_mode=AttrString( - coordinate_transformation_mode, - name="coordinate_transformation_mode", - ), - mode=AttrString(mode, name="mode"), - output_height=AttrInt64(output_height, name="output_height"), - output_width=AttrInt64(output_width, name="output_width"), - sampling_ratio=AttrInt64(sampling_ratio, name="sampling_ratio"), - spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), - ), - _RoiAlign.Inputs( - X=unwrap_vars(X), - rois=unwrap_vars(rois), - batch_indices=unwrap_vars(batch_indices), - ), - ) - .get_output_vars( - X=get_value(X), - rois=get_value(rois), - batch_indices=get_value(batch_indices), - ) - .Y - ) - - -def round( - X: Var, -) -> Var: - r""" - Round takes one input Tensor and rounds the values, element-wise, - meaning it finds the nearest integer for each value. In case of halves, - the rule is to round them to the nearest even integer. If input x is - integral, +0, -0, NaN, or infinite, x itself is returned. The output - tensor has the same shape and type as the input. - - Examples: - - :: - - round([0.9]) = [1.0] - round([2.5]) = [2.0] - round([2.3]) = [2.0] - round([1.5]) = [2.0] - round([-4.5]) = [-4.0] - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@11::Round``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Round( - _Round.Attributes(), - _Round.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def stft( - signal: Var, - frame_step: Var, - window: Optional[Var] = None, - frame_length: Optional[Var] = None, - *, - onesided: int = 1, -) -> Var: - r""" - Computes the Short-time Fourier Transform of the signal. - - Parameters - ========== - signal - Type T1. - Input tensor representing a real or complex valued signal. For real - input, the following shape is expected: [batch_size][signal_length][1]. - For complex input, the following shape is expected: - [batch_size][signal_length][2], where [batch_size][signal_length][0] - represents the real component and [batch_size][signal_length][1] - represents the imaginary component of the signal. - frame_step - Type T2. - The number of samples to step between successive DFTs. - window - Type T1. - A tensor representing the window that will be slid over the signal.The - window must have rank 1 with shape: [window_shape]. It's an optional - value. - frame_length - Type T2. - A scalar representing the size of the DFT. It's an optional value. - onesided - Attribute. - If onesided is 1, only values for w in [0, 1, 2, ..., floor(n_fft/2) + - 1] are returned because the real-to-complex Fourier transform satisfies - the conjugate symmetry, i.e., X[m, w] = X[m,w]=X[m,n_fft-w]\*. Note if - the input or window tensors are complex, then onesided output is not - possible. Enabling onesided with real inputs performs a Real-valued fast - Fourier transform (RFFT).When invoked with real or complex valued input, - the default value is 1. Values can be 0 or 1. - - Returns - ======= - output : Var - Type T1. - The Short-time Fourier Transform of the signals.If onesided is 1, the - output has the shape: [batch_size][frames][dft_unique_bins][2], where - dft_unique_bins is frame_length // 2 + 1 (the unique components of the - DFT) If onesided is 0, the output has the shape: - [batch_size][frames][frame_length][2], where frame_length is the length - of the DFT. - - Notes - ===== - Signature: ``ai.onnx@17::STFT``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return ( - _STFT( - _STFT.Attributes( - onesided=AttrInt64(onesided, name="onesided"), - ), - _STFT.Inputs( - signal=unwrap_vars(signal), - frame_step=unwrap_vars(frame_step), - window=unwrap_vars(window), - frame_length=unwrap_vars(frame_length), - ), - ) - .get_output_vars( - signal=get_value(signal), - frame_step=get_value(frame_step), - window=get_value(window), - frame_length=get_value(frame_length), - ) - .output - ) - - -def scan( - initial_state_and_scan_inputs: Sequence[Var], - *, - body: Callable[..., Iterable[Var]], - num_scan_inputs: int, - scan_input_axes: Optional[Iterable[int]] = None, - scan_input_directions: Optional[Iterable[int]] = None, - scan_output_axes: Optional[Iterable[int]] = None, - scan_output_directions: Optional[Iterable[int]] = None, -) -> Sequence[Var]: - r""" - Scan can be used to iterate over one or more scan_input tensors, - constructing zero or more scan_output tensors. It combines ideas from - general recurrences, functional programming constructs such as scan, - fold, map, and zip, and is intended to enable generalizations of - RNN-like constructs for sequence-to-sequence processing. Other tensors - (referred to as state_variables here) can be used to carry a state when - iterating from one element to another (similar to hidden-state in RNNs, - also referred to as loop-carried dependences in the context of loops). - Many common usages involve a single scan_input tensor (where - functionality similar to scan, fold and map can be obtained). When more - than one scan_input is used, a behavior similar to zip is obtained. - - The attribute body must be a graph, specifying the computation to be - performed in every iteration. It takes as input the current values of - the state_variables and the current iterated element of the scan_inputs. - It must return the (updated) values of the state_variables and zero or - more scan_output_element tensors. The values of the scan_output_element - tensors are concatenated over all the iterations to produce the - scan_output values of the scan construct (similar to the concatenated - intermediate hidden-state values of RNN-like constructs). All the output - tensors (state_variables as well as scan_output_element tensors) are - required to have the same shape in each iteration of the loop (a - restriction imposed to enable efficient memory allocation). - - Note that the iterated element passed to the body subgraph does not have - a sequence axis. It will have a rank one less than the rank of the - corresponding scan_input. - - The scan operation returns the final values of the state_variables as - well as the scan_outputs. - - The optional attribute scan_input_directions specifies the direction - (forward or backward) for each scan input. If this attribute is omitted, - all sequences are scanned in the forward direction. A bidirectional scan - may be performed by specifying the same tensor input twice in the - scan_inputs, once with a forward direction, and once with a backward - direction. - - The scan_output of the operation is produced by concatenating the - scan_output_element values produced by the body in each iteration. The - optional attribute scan_output_directions specifies the direction in - which scan_output is constructed (by appending or prepending the - scan_output_element to scan_output in each iteration) for each - scan_output. If this attribute is omitted, the scan_output_element is - appended to the scan_output in each iteration. - - The optional attribute scan_input_axes specifies the axis to be scanned - for each scan_input. If omitted, every scan_input will be scanned in - axis 0. For example, if axis 0 is the batch axis and axis 1 is the time - axis (to be scanned), specify an axis value of 1. Note that scanning a - non-zero axis may be less efficient than scanning axis zero. - - The optional attribute scan_output_axes specifies the axis along which - the scan_outputs are accumulated for each scan_output. For example, if - axis 1 is the time axis (to be scanned) for both inputs and outputs, - specify a scan_input axis and scan_output axis value of 1. - - Note that because of the ONNX restriction that only the last parameter - of an operator can be variadic, the initial-states and scan-inputs are - listed together as one input parameter. Similarly, the final-states and - scan-outputs are listed together as one output parameter. The attribute - num_scan_inputs indicates the number M of scan-inputs. - - The behavior of - - :: - - Scan < - num_scan_inputs = m, - body = loop-body, - scan_input_axes = [axis_1, ..., axis_m] - > (init_1, ..., init_n, scan_1, ..., scan_m) - - is equivalent to the following pseudo-code: - - :: - - // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i - // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. - sequence_length = scan_1.shape[axis_1]; - - // initialize state-variables - st_1 = init_1; ... st_n = init_n; - // initialize scan-output variables: [] denotes an empty tensor - scan_out_1 = []; ...; scan_out_k = []; - // identify number of iterations: - - // execute loop - for (int t = 0; t < sequence_length; ++t) { - // generate the scan-input elements: the notation T[t] indicates the sub-tensor - // of rank one less than T obtained by indexing T at position t along axis k. - si_1 = scan_1[t]; - ... ; - si_m = scan_m[t]; - // execute loop-body - st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) - // accumulate the scan-output elements - scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); - } - - return st_1, ..., st_n, scan_out_1, ..., scan_out_k; - - *Sample usage: Encoding RNN using a Scan* - - The following example shows how a simple RNN over an input tensor %X, - with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi - and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. - Note that the loop-body is a nested graph, and it directly computes %Wi, - %Ri, %Wbi, and %Rbi (typically constants or initializers in the body - graph). If these values are computed in the outer graph, they need to be - passed in as extra state_variables. - - :: - - graph rnn-encoding { - %H_0 = ... - %X = ... - %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) - return %Y, %Y_h - } - - graph rnn-cell-1 ( - %H_tminus1[FLOAT, tensor] - %X_t[FLOAT, tensor] - ) { - %Wi = ... - %Ri = ... - %Wbi = ... - %Rbi = ... - %t1 = X_t * (Wi^T) - %t2 = H_tminus1*(Ri^T) - %t3 = Add(%t1, %t2) - %t4 = Add(%t3, %Wbi) - %t5 = Add(%t4, %Rbi) - %Ht = Tanh(%t5) - %Accumulate = Identity(%Ht) - return %Ht, %Accumulate - } - - Parameters - ========== - initial_state_and_scan_inputs - Type V. - Initial values of the loop's N state variables followed by M scan_inputs - body - Attribute. - The graph run each iteration. It has N+M inputs: (loop state - variables..., scan_input_elts...). It has N+K outputs: (loop state - variables..., scan_output_elts...). Each scan_output is created by - concatenating the value of the specified scan_output_elt value at the - end of each iteration of the loop. It is an error if the dimensions of - these values change across loop iterations. - num_scan_inputs - Attribute. - An attribute specifying the number of scan_inputs M. - scan_input_axes - Attribute. - An optional list of M flags. The i-th element of the list specifies the - axis to be scanned (the sequence axis) for the i-th scan_input. If - omitted, 0 will be used as the scan axis for every scan_input. Negative - value for an axis means counting dimensions from the back. Accepted - range is [-r, r-1] where r = rank(input). - scan_input_directions - Attribute. - An optional list of M flags. The i-th element of the list specifies the - direction to be scanned for the i-th scan_input tensor: 0 indicates - forward direction and 1 indicates reverse direction. If omitted, all - scan_input tensors will be scanned in the forward direction. - scan_output_axes - Attribute. - An optional list of K flags. The i-th element of the list specifies the - axis for the i-th scan_output. The scan outputs are accumulated along - the specified axis. If omitted, 0 will be used as the scan axis for - every scan_output. Negative value for an axis means counting dimensions - from the back. Accepted range is [-r, r-1]. - scan_output_directions - Attribute. - An optional list of K flags, one for each scan_output. The i-th element - of the list specifies whether the i-th scan_output should be constructed - by appending or prepending a new value in each iteration: 0 indicates - appending and 1 indicates prepending. If omitted, all scan_output - tensors will be produced by appending a value in each iteration. - - Returns - ======= - final_state_and_scan_outputs : Sequence[Var] - Type V. - Final values of the loop's N state variables followed by K scan_outputs - - Notes - ===== - Signature: ``ai.onnx@16::Scan``. - - Type constraints: - - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _body_subgraph: Graph = subgraph( - [ - Tensor( - var.unwrap_tensor().dtype, - (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape), - ) - for var in initial_state_and_scan_inputs[:num_scan_inputs] - ] - + [ - Tensor(var.unwrap_tensor().dtype) - for var in initial_state_and_scan_inputs[num_scan_inputs:] - ], - body, - ) - return ( - _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe( - scan_input_axes, name="scan_input_axes" - ), - scan_input_directions=AttrInt64s.maybe( - scan_input_directions, name="scan_input_directions" - ), - scan_output_axes=AttrInt64s.maybe( - scan_output_axes, name="scan_output_axes" - ), - scan_output_directions=AttrInt64s.maybe( - scan_output_directions, name="scan_output_directions" - ), - ), - _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars( - initial_state_and_scan_inputs - ), - ), - out_variadic=len(_body_subgraph.requested_results), - ) - .get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), - ) - .final_state_and_scan_outputs - ) - - -def scatter_elements( - data: Var, - indices: Var, - updates: Var, - *, - axis: int = 0, - reduction: str = "none", -) -> Var: - r""" - ScatterElements takes three inputs ``data``, ``updates``, and - ``indices`` of the same rank r >= 1 and an optional attribute axis that - identifies an axis of ``data`` (by default, the outer-most axis, that is - axis 0). The output of the operation is produced by creating a copy of - the input ``data``, and then updating its value to values specified by - ``updates`` at specific index positions specified by ``indices``. Its - output shape is the same as the shape of ``data``. For each entry in - ``updates``, the target index in ``data`` is obtained by combining the - corresponding entry in ``indices`` with the index of the entry itself: - the index-value for dimension = axis is obtained from the value of the - corresponding entry in ``indices`` and the index-value for dimension != - axis is obtained from the index of the entry itself. ``reduction`` - allows specification of an optional reduction operation, which is - applied to all values in ``updates`` tensor into ``output`` at the - specified ``indices``. In cases where ``reduction`` is set to "none", - indices should not have duplicate entries: that is, if idx1 != idx2, - then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, - the update corresponding to the [i][j] entry is performed as below: - - :: - - output[indices[i][j]][j] = updates[i][j] if axis = 0, - output[i][indices[i][j]] = updates[i][j] if axis = 1, - - When ``reduction`` is set to "add", the update corresponding to the - [i][j] entry is performed as below: - - :: - - output[indices[i][j]][j] += updates[i][j] if axis = 0, - output[i][indices[i][j]] += updates[i][j] if axis = 1, - - When ``reduction`` is set to "mul", the update corresponding to the - [i][j] entry is performed as below: - - :: - - output[indices[i][j]][j] *= updates[i][j] if axis = 0, - output[i][indices[i][j]] *= updates[i][j] if axis = 1, - - This operator is the inverse of GatherElements. It is similar to Torch's - Scatter operation. Example 1: - - :: - - data = [ - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - ] - indices = [ - [1, 0, 2], - [0, 2, 1], - ] - updates = [ - [1.0, 1.1, 1.2], - [2.0, 2.1, 2.2], - ] - output = [ - [2.0, 1.1, 0.0] - [1.0, 0.0, 2.2] - [0.0, 2.1, 1.2] - ] - - Example 2: - - :: - - data = [[1.0, 2.0, 3.0, 4.0, 5.0]] - indices = [[1, 3]] - updates = [[1.1, 2.1]] - axis = 1 - output = [[1.0, 1.1, 3.0, 2.1, 5.0]] - - Parameters - ========== - data - Type T. - Tensor of rank r >= 1. - indices - Type Tind. - Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index - values are expected to be within bounds [-s, s-1] along axis of size s. - It is an error if any of the index values are out of bounds. - updates - Type T. - Tensor of rank r >=1 (same rank and shape as indices) - axis - Attribute. - Which axis to scatter on. Negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(data). - reduction - Attribute. - Type of reduction to apply: none (default), add, mul. 'none': no - reduction applied. 'add': reduction using the addition operation. 'mul': - reduction using the multiplication operation. - - Returns - ======= - output : Var - Type T. - Tensor of rank r >= 1 (same rank as input). - - Notes - ===== - Signature: ``ai.onnx@16::ScatterElements``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return ( - _ScatterElements( - _ScatterElements.Attributes( - axis=AttrInt64(axis, name="axis"), - reduction=AttrString(reduction, name="reduction"), - ), - _ScatterElements.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - updates=unwrap_vars(updates), - ), - ) - .get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), - ) - .output - ) - - -def scatter_nd( - data: Var, - indices: Var, - updates: Var, - *, - reduction: str = "none", -) -> Var: - r""" - ScatterND takes three inputs ``data`` tensor of rank r >= 1, ``indices`` - tensor of rank q >= 1, and ``updates`` tensor of rank q + r - - indices.shape[-1] - 1. The output of the operation is produced by - creating a copy of the input ``data``, and then updating its value to - values specified by ``updates`` at specific index positions specified by - ``indices``. Its output shape is the same as the shape of ``data``. - - ``indices`` is an integer tensor. Let k denote indices.shape[-1], the - last dimension in the shape of ``indices``. ``indices`` is treated as a - (q-1)-dimensional tensor of k-tuples, where each k-tuple is a - partial-index into ``data``. Hence, k can be a value at most the rank of - ``data``. When k equals rank(data), each update entry specifies an - update to a single element of the tensor. When k is less than rank(data) - each update entry specifies an update to a slice of the tensor. Index - values are allowed to be negative, as per the usual convention for - counting backwards from the end, but are expected in the valid range. - - ``updates`` is treated as a (q-1)-dimensional tensor of - replacement-slice-values. Thus, the first (q-1) dimensions of - updates.shape must match the first (q-1) dimensions of indices.shape. - The remaining dimensions of ``updates`` correspond to the dimensions of - the replacement-slice-values. Each replacement-slice-value is a (r-k) - dimensional tensor, corresponding to the trailing (r-k) dimensions of - ``data``. Thus, the shape of ``updates`` must equal indices.shape[0:q-1] - ++ data.shape[k:r-1], where ++ denotes the concatenation of shapes. - - The ``output`` is calculated via the following equation: output = - np.copy(data) update_indices = indices.shape[:-1] for idx in - np.ndindex(update_indices): output[indices[idx]] = updates[idx] The - order of iteration in the above loop is not specified. In particular, - indices should not have duplicate entries: that is, if idx1 != idx2, - then indices[idx1] != indices[idx2]. This ensures that the output value - does not depend on the iteration order. - - ``reduction`` allows specification of an optional reduction operation, - which is applied to all values in ``updates`` tensor into ``output`` at - the specified ``indices``. In cases where ``reduction`` is set to - "none", indices should not have duplicate entries: that is, if idx1 != - idx2, then indices[idx1] != indices[idx2]. This ensures that the output - value does not depend on the iteration order. When ``reduction`` is set - to "add", ``output`` is calculated as follows: output = np.copy(data) - update_indices = indices.shape[:-1] for idx in - np.ndindex(update_indices): output[indices[idx]] += updates[idx] When - ``reduction`` is set to "mul", ``output`` is calculated as follows: - output = np.copy(data) update_indices = indices.shape[:-1] for idx in - np.ndindex(update_indices): output[indices[idx]] \*= updates[idx] This - operator is the inverse of GatherND. Example 1: - - :: - - data = [1, 2, 3, 4, 5, 6, 7, 8] - indices = [[4], [3], [1], [7]] - updates = [9, 10, 11, 12] - output = [1, 11, 3, 10, 9, 6, 7, 12] - - Example 2: - - :: - - data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] - indices = [[0], [2]] - updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], - [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] - output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], - [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] - - Parameters - ========== - data - Type T. - Tensor of rank r >= 1. - indices - Type tensor(int64). - Tensor of rank q >= 1. - updates - Type T. - Tensor of rank q + r - indices_shape[-1] - 1. - reduction - Attribute. - Type of reduction to apply: none (default), add, mul. 'none': no - reduction applied. 'add': reduction using the addition operation. 'mul': - reduction using the multiplication operation. - - Returns - ======= - output : Var - Type T. - Tensor of rank r >= 1. - - Notes - ===== - Signature: ``ai.onnx@16::ScatterND``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _ScatterND( - _ScatterND.Attributes( - reduction=AttrString(reduction, name="reduction"), - ), - _ScatterND.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - updates=unwrap_vars(updates), - ), - ) - .get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), - ) - .output - ) - - -def selu( - X: Var, - *, - alpha: float = 1.6732631921768188, - gamma: float = 1.0507010221481323, -) -> Var: - r""" - Selu takes one input data (Tensor) and produces one output data - (Tensor) where the scaled exponential linear unit function, - ``y = gamma * (alpha * e^x - alpha) for x <= 0``, - ``y = gamma * x for x > 0``, is applied to the tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - alpha - Attribute. - Coefficient of SELU default to 1.67326319217681884765625 (i.e., float32 - approximation of 1.6732632423543772848170429916717). - gamma - Attribute. - Coefficient of SELU default to 1.05070102214813232421875 (i.e., float32 - approximation of 1.0507009873554804934193349852946). - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@6::Selu``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Selu( - _Selu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - gamma=AttrFloat32(gamma, name="gamma"), - ), - _Selu.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def sequence_at( - input_sequence: Var, - position: Var, -) -> Var: - r""" - Outputs a tensor copy from the tensor at 'position' in 'input_sequence'. - Accepted range for 'position' is in ``[-n, n - 1]``, where ``n`` is the - number of tensors in 'input_sequence'. Negative value means counting - positions from the back. - - Parameters - ========== - input_sequence - Type S. - Input sequence. - position - Type I. - Position of the tensor in the sequence. Negative value means counting - positions from the back. Accepted range in ``[-n, n - 1]``, where ``n`` - is the number of tensors in 'input_sequence'. It is an error if any of - the index values are out of bounds. It must be a scalar(tensor of empty - shape). - - Returns - ======= - tensor : Var - Type T. - Output tensor at the specified position in the input sequence. - - Notes - ===== - Signature: ``ai.onnx@11::SequenceAt``. - - Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - I: `tensor(int32)`, `tensor(int64)` - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _SequenceAt( - _SequenceAt.Attributes(), - _SequenceAt.Inputs( - input_sequence=unwrap_vars(input_sequence), - position=unwrap_vars(position), - ), - ) - .get_output_vars( - input_sequence=get_value(input_sequence), - position=get_value(position), - ) - .tensor - ) - - -def sequence_construct( - inputs: Sequence[Var], -) -> Var: - r""" - Construct a tensor sequence containing 'inputs' tensors. All tensors in - 'inputs' must have the same data type. - - Parameters - ========== - inputs - Type T. - Tensors. - - Returns - ======= - output_sequence : Var - Type S. - Sequence enclosing the input tensors. - - Notes - ===== - Signature: ``ai.onnx@11::SequenceConstruct``. - - Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - """ - return ( - _SequenceConstruct( - _SequenceConstruct.Attributes(), - _SequenceConstruct.Inputs( - inputs=unwrap_vars(inputs), - ), - ) - .get_output_vars( - inputs=get_value(inputs), - ) - .output_sequence - ) - - -def sequence_empty( - *, - dtype: Optional[npt.DTypeLike] = None, -) -> Var: - r""" - Construct an empty tensor sequence, with given data type. - - Parameters - ========== - dtype - Attribute. - (Optional) The data type of the tensors in the output sequence. The - default type is 'float'. - - Returns - ======= - output : Var - Type S. - Empty sequence. - - Notes - ===== - Signature: ``ai.onnx@11::SequenceEmpty``. - - Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - """ - return ( - _SequenceEmpty( - _SequenceEmpty.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - ), - _SequenceEmpty.Inputs(), - ) - .get_output_vars() - .output - ) - - -def sequence_erase( - input_sequence: Var, - position: Optional[Var] = None, -) -> Var: - r""" - Outputs a tensor sequence that removes the tensor at 'position' from - 'input_sequence'. Accepted range for 'position' is in ``[-n, n - 1]``, - where ``n`` is the number of tensors in 'input_sequence'. Negative value - means counting positions from the back. 'position' is optional, by - default it erases the last tensor from 'input_sequence'. - - Parameters - ========== - input_sequence - Type S. - Input sequence. - position - Type I. - Position of the tensor in the sequence. Negative value means counting - positions from the back. Accepted range in ``[-n, n - 1]``, where ``n`` - is the number of tensors in 'input_sequence'. It is an error if any of - the index values are out of bounds. It must be a scalar(tensor of empty - shape). - - Returns - ======= - output_sequence : Var - Type S. - Output sequence that has the tensor at the specified position removed. - - Notes - ===== - Signature: ``ai.onnx@11::SequenceErase``. - - Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - I: `tensor(int32)`, `tensor(int64)` - """ - return ( - _SequenceErase( - _SequenceErase.Attributes(), - _SequenceErase.Inputs( - input_sequence=unwrap_vars(input_sequence), - position=unwrap_vars(position), - ), - ) - .get_output_vars( - input_sequence=get_value(input_sequence), - position=get_value(position), - ) - .output_sequence - ) - - -def sequence_insert( - input_sequence: Var, - tensor: Var, - position: Optional[Var] = None, -) -> Var: - r""" - Outputs a tensor sequence that inserts 'tensor' into 'input_sequence' at - 'position'. 'tensor' must have the same data type as 'input_sequence'. - Accepted range for 'position' is in ``[-n, n]``, where ``n`` is the - number of tensors in 'input_sequence'. Negative value means counting - positions from the back. 'position' is optional, by default it inserts - 'tensor' to the back of 'input_sequence'. - - Parameters - ========== - input_sequence - Type S. - Input sequence. - tensor - Type T. - Input tensor to be inserted into the input sequence. - position - Type I. - Position in the sequence where the new tensor is inserted. It is - optional and default is to insert to the back of the sequence. Negative - value means counting positions from the back. Accepted range in - ``[-n, n]``, where ``n`` is the number of tensors in 'input_sequence'. - It is an error if any of the index values are out of bounds. It must be - a scalar(tensor of empty shape). - - Returns - ======= - output_sequence : Var - Type S. - Output sequence that contains the inserted tensor at given position. - - Notes - ===== - Signature: ``ai.onnx@11::SequenceInsert``. - - Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - I: `tensor(int32)`, `tensor(int64)` - """ - return ( - _SequenceInsert( - _SequenceInsert.Attributes(), - _SequenceInsert.Inputs( - input_sequence=unwrap_vars(input_sequence), - tensor=unwrap_vars(tensor), - position=unwrap_vars(position), - ), - ) - .get_output_vars( - input_sequence=get_value(input_sequence), - tensor=get_value(tensor), - position=get_value(position), - ) - .output_sequence - ) - - -def sequence_length( - input_sequence: Var, -) -> Var: - r""" - Produces a scalar(tensor of empty shape) containing the number of - tensors in 'input_sequence'. - - Parameters - ========== - input_sequence - Type S. - Input sequence. - - Returns - ======= - length : Var - Type I. - Length of input sequence. It must be a scalar(tensor of empty shape). - - Notes - ===== - Signature: ``ai.onnx@11::SequenceLength``. - - Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - I: `tensor(int64)` - """ - return ( - _SequenceLength( - _SequenceLength.Attributes(), - _SequenceLength.Inputs( - input_sequence=unwrap_vars(input_sequence), - ), - ) - .get_output_vars( - input_sequence=get_value(input_sequence), - ) - .length - ) - - -def sequence_map( - input_sequence: Var, - additional_inputs: Sequence[Var] = (), - *, - body: Callable[..., Iterable[Var]], -) -> Sequence[Var]: - r""" - Applies a sub-graph to each sample in the input sequence(s). - - Inputs can be either tensors or sequences, with the exception of the - first input which must be a sequence. The length of the first input - sequence will determine the number of samples in the outputs. Any other - sequence inputs should have the same number of samples. The number of - inputs and outputs, should match the one of the subgraph. - - For each i-th element in the output, a sample will be extracted from the - input sequence(s) at the i-th position and the sub-graph will be applied - to it. The outputs will contain the outputs of the sub-graph for each - sample, in the same order as in the input. - - This operator assumes that processing each sample is independent and - could executed in parallel or in any order. Users cannot expect any - specific ordering in which each subgraph is computed. - - Parameters - ========== - input_sequence - Type S. - Input sequence. - additional_inputs - Type V. - Additional inputs to the graph - body - Attribute. - The graph to be run for each sample in the sequence(s). It should have - as many inputs and outputs as inputs and outputs to the SequenceMap - function. - - Returns - ======= - out_sequence : Sequence[Var] - Type S. - Output sequence(s) - - Notes - ===== - Signature: ``ai.onnx@17::SequenceMap``. - - Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _body_subgraph: Graph = subgraph( - [typing_cast(SpoxSequence, input_sequence.unwrap_type()).elem_type] - + [ - typing_cast(SpoxSequence, var.unwrap_type()).elem_type - for var in additional_inputs - ], - body, - ) - return ( - _SequenceMap( - _SequenceMap.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), - _SequenceMap.Inputs( - input_sequence=unwrap_vars(input_sequence), - additional_inputs=unwrap_vars(additional_inputs), - ), - out_variadic=len(_body_subgraph.requested_results), - ) - .get_output_vars( - input_sequence=get_value(input_sequence), - additional_inputs=get_value(additional_inputs), - ) - .out_sequence - ) - - -def shape( - data: Var, - *, - end: Optional[int] = None, - start: int = 0, -) -> Var: - r""" - Takes a tensor as input and outputs an 1D int64 tensor containing the - shape of the input tensor. Optional attributes start and end can be used - to compute a slice of the input tensor's shape. If start axis is - omitted, the slice starts from axis 0. The end axis, if specified, is - exclusive (and the returned value will not include the size of that - axis). If the end axis is omitted, the axes upto the last one will be - included. Negative axes indicate counting back from the last axis. Note - that axes will be clamped to the range [0, r-1], where r is the rank of - the input tensor if they are out-of-range (after adding r in the case of - negative axis). Thus, specifying any end value > r is equivalent to - specifying an end value of r, and specifying any start value < -r is - equivalent to specifying a start value of 0. - - Examples: - - :: - - Input tensor with shape: [2, 3, 4] - No attributes specified. - Output: [2, 3, 4] - - :: - - Input tensor with shape: [2, 3, 4] - start: -1 - Output: [4] - - :: - - Input tensor with shape: [2, 3, 4] - end: -1 - Output: [2, 3] - - :: - - Input tensor with shape: [2, 3, 4] - start: 1 - end: 2 - Output: [3] - - Parameters - ========== - data - Type T. - An input tensor. - end - Attribute. - (Optional) Ending axis for slicing the shape. Negative value means - counting dimensions from the back. If omitted, sizes of all axes upto - (including) the last one will be included. - start - Attribute. - (Optional) Starting axis for slicing the shape. Default value is - 0.Negative value means counting dimensions from the back. - - Returns - ======= - shape : Var - Type T1. - Shape of the input tensor - - Notes - ===== - Signature: ``ai.onnx@15::Shape``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` - """ - return ( - _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), - _Shape.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .shape - ) - - -def shrink( - input: Var, - *, - bias: float = 0.0, - lambd: float = 0.5, -) -> Var: - r""" - Shrink takes one input data (Tensor) and produces one Tensor output, - having same datatype and shape with input. It has two attributes, lambd - and bias. The formula of this operator is: If x < -lambd, y = x + bias; - If x > lambd, y = x - bias; Otherwise, y = 0. - - Parameters - ========== - input - Type T. - The input data as Tensor. - bias - Attribute. - The bias value added to output. Default is 0. - lambd - Attribute. - The lambd value for the Shrink formulation. Default is 0.5. - - Returns - ======= - output : Var - Type T. - The output. - - Notes - ===== - Signature: ``ai.onnx@9::Shrink``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Shrink( - _Shrink.Attributes( - bias=AttrFloat32(bias, name="bias"), - lambd=AttrFloat32(lambd, name="lambd"), - ), - _Shrink.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def sigmoid( - X: Var, -) -> Var: - r""" - Sigmoid takes one input data (Tensor) and produces one output data - (Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is - applied to the tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::Sigmoid``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Sigmoid( - _Sigmoid.Attributes(), - _Sigmoid.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def sign( - input: Var, -) -> Var: - r""" - Calculate the sign of the given input tensor element-wise. If input > 0, - output 1. if input < 0, output -1. if input == 0, output 0. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The sign of the input tensor computed element-wise. It has the same - shape and type of the input. - - Notes - ===== - Signature: ``ai.onnx@13::Sign``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Sign( - _Sign.Attributes(), - _Sign.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def sin( - input: Var, -) -> Var: - r""" - Calculates the sine of the given input tensor, element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The sine of the input tensor computed element-wise - - Notes - ===== - Signature: ``ai.onnx@7::Sin``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Sin( - _Sin.Attributes(), - _Sin.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def sinh( - input: Var, -) -> Var: - r""" - Calculates the hyperbolic sine of the given input tensor element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The hyperbolic sine values of the input tensor computed element-wise - - Notes - ===== - Signature: ``ai.onnx@9::Sinh``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Sinh( - _Sinh.Attributes(), - _Sinh.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def size( - data: Var, -) -> Var: - r""" - Takes a tensor as input and outputs a int64 scalar that equals to the - total number of elements of the input tensor. - - Parameters - ========== - data - Type T. - An input tensor. - - Returns - ======= - size : Var - Type T1. - Total number of elements of the input tensor - - Notes - ===== - Signature: ``ai.onnx@13::Size``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` - """ - return ( - _Size( - _Size.Attributes(), - _Size.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .size - ) - - -def slice( - data: Var, - starts: Var, - ends: Var, - axes: Optional[Var] = None, - steps: Optional[Var] = None, -) -> Var: - r""" - Produces a slice of the input tensor along multiple axes. Similar to - numpy: - https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding - - Slice uses the ``starts``, ``ends``, ``axes`` and ``steps`` inputs to - select a sub-tensor of its input ``data`` tensor. - - An effective ``starts[i]``, ``ends[i]``, and ``steps[i]`` must be - computed for each ``i`` in ``[0, ... r-1]`` where ``r = rank(input)`` as - follows: - - If ``axes`` are omitted, they are set to ``[0, ..., r-1]``. If ``steps`` - are omitted, they are set to ``[1, ..., 1]`` of length ``len(starts)`` - - The effective values are initialized as ``start[i] = 0``, - ``ends[i] = dims[i]`` where ``dims`` are the dimensions of ``input`` and - ``steps[i] = 1``. - - All negative elements of ``axes`` are made non-negative by adding ``r`` - to them, where ``r =rank(input)``. - - All negative values in ``starts[i]`` and ``ends[i]`` have - ``dims[axes[i]]`` added to them, where ``dims`` are the dimensions of - ``input``. Then ``start[axes[i]]`` is the adjusted ``starts[i]`` is - clamped into the range ``[0, dims[axes[i]]]`` for positive stepping and - ``[0, dims[axes[i]]-1]`` for negative stepping. - - The clamping for the adjusted ``ends[i]`` depends on the sign of - ``steps[i]`` and must accommodate copying 0 through ``dims[axes[i]]`` - elements, so for positive stepping ``ends[axes[i]]`` is clamped to - ``[0, dims[axes[i]]]``, while for negative stepping it is clamped to - ``[-1, dims[axes[i]]-1]``. - - Finally, ``steps[axes[i]] = steps[i]``. - - For slicing to the end of a dimension with unknown size, it is - recommended to pass in ``INT_MAX`` when slicing forward and 'INT_MIN' - when slicing backward. - - Example 1: - - :: - - data = [ - [1, 2, 3, 4], - [5, 6, 7, 8], - ] - axes = [0, 1] - starts = [1, 0] - ends = [2, 3] - steps = [1, 2] - result = [ - [5, 7], - ] - - Example 2: - - :: - - data = [ - [1, 2, 3, 4], - [5, 6, 7, 8], - ] - starts = [0, 1] - ends = [-1, 1000] - result = [ - [2, 3, 4], - ] - - Parameters - ========== - data - Type T. - Tensor of data to extract slices from. - starts - Type Tind. - 1-D tensor of starting indices of corresponding axis in ``axes`` - ends - Type Tind. - 1-D tensor of ending indices (exclusive) of corresponding axis in - ``axes`` - axes - Type Tind. - 1-D tensor of axes that ``starts`` and ``ends`` apply to. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(data). Behavior is undefined if an axis is repeated. - steps - Type Tind. - 1-D tensor of slice step of corresponding axis in ``axes``. Negative - value means slicing backward. 'steps' cannot be 0. Defaults to 1s. - - Returns - ======= - output : Var - Type T. - Sliced data tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Slice``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return ( - _Slice( - _Slice.Attributes(), - _Slice.Inputs( - data=unwrap_vars(data), - starts=unwrap_vars(starts), - ends=unwrap_vars(ends), - axes=unwrap_vars(axes), - steps=unwrap_vars(steps), - ), - ) - .get_output_vars( - data=get_value(data), - starts=get_value(starts), - ends=get_value(ends), - axes=get_value(axes), - steps=get_value(steps), - ) - .output - ) - - -def softmax( - input: Var, - *, - axis: int = -1, -) -> Var: - r""" - The operator computes the normalized exponential values for the given - input: - - Softmax(input, axis) = Exp(input) / ReduceSum(Exp(input), axis=axis, - keepdims=1) - - The "axis" attribute indicates the dimension along which Softmax will be - performed. The output tensor has the same shape and contains the Softmax - values of the corresponding input. - - Parameters - ========== - input - Type T. - The input tensor of rank >= axis. - axis - Attribute. - Describes the dimension Softmax will be performed on. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(input). - - Returns - ======= - output : Var - Type T. - The output values with the same shape as the input tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Softmax``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Softmax( - _Softmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Softmax.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def softmax_cross_entropy_loss( - scores: Var, - labels: Var, - weights: Optional[Var] = None, - *, - ignore_index: Optional[int] = None, - reduction: str = "mean", -) -> tuple[Var, Var]: - r""" - Loss function that measures the softmax cross entropy between 'scores' - and 'labels'. This operator first computes a loss tensor whose shape is - identical to the labels input. If the input is 2-D with shape (N, C), - the loss tensor may be a N-element vector L = (l_1, l_2, ..., l_N). If - the input is N-D tensor with shape (N, C, D1, D2, ..., Dk), the loss - tensor L may have (N, D1, D2, ..., Dk) as its shape and - L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. After L is - available, this operator can optionally do a reduction operator. - - - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, - D2,..., Dk), with K >= 1 in case of K-dimensional loss. - - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, - D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. - - The loss for one sample, l_i, can calculated as follows: - - :: - - l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes. - - or - - :: - - l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided. - - loss is zero for the case when label-value equals ignore_index. - - :: - - l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index - - where: - - :: - - p = Softmax(scores) - y = Log(p) - c = labels[i][d1][d2]...[dk] - - Finally, L is optionally reduced: - - - If reduction = 'none', the output is L with shape (N, D1, D2, ..., - Dk). - - If reduction = 'sum', the output is scalar: Sum(L). - - If reduction = 'mean', the output is scalar: ReduceMean(L), or if - weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W - is of shape ``(N, D1, D2, ..., Dk)`` and - ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. - - Parameters - ========== - scores - Type T. - The predicted outputs with shape [batch_size, class_size], or - [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of - dimensions. - labels - Type Tind. - The ground truth output tensor, with shape [batch_size], or [batch_size, - D1, D2, ..., Dk], where K is the number of dimensions. Labels element - value shall be in range of [0, C). If ignore_index is specified, it may - have a value outside [0, C) and the label values should either be in the - range [0, C) or have the value ignore_index. - weights - Type T. - A manual rescaling weight given to each class. If given, it has to be a - 1D Tensor assigning weight to each of the classes. Otherwise, it is - treated as if having all ones. - ignore_index - Attribute. - Specifies a target value that is ignored and does not contribute to the - input gradient. It's an optional value. - reduction - Attribute. - Type of reduction to apply to loss: none, sum, mean(default). 'none': no - reduction will be applied, 'sum': the output will be summed. 'mean': the - sum of the output will be divided by the number of elements in the - output. - - Returns - ======= - output : Var - Type T. - Weighted loss float Tensor. If reduction is 'none', this has the shape - of [batch_size], or [batch_size, D1, D2, ..., Dk] in case of - K-dimensional loss. Otherwise, it is a scalar. - log_prob : Var - Type T. - Log probability tensor. If the output of softmax is prob, its value is - log(prob). - - Notes - ===== - Signature: ``ai.onnx@13::SoftmaxCrossEntropyLoss``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return ( - _SoftmaxCrossEntropyLoss( - _SoftmaxCrossEntropyLoss.Attributes( - ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), - reduction=AttrString(reduction, name="reduction"), - ), - _SoftmaxCrossEntropyLoss.Inputs( - scores=unwrap_vars(scores), - labels=unwrap_vars(labels), - weights=unwrap_vars(weights), - ), - ) - .get_output_vars( - scores=get_value(scores), - labels=get_value(labels), - weights=get_value(weights), - ) - ._unpack_to_any() - ) - - -def softplus( - X: Var, -) -> Var: - r""" - Softplus takes one input data (Tensor) and produces one output data - (Tensor) where the softplus function, y = ln(exp(x) + 1), is applied - to the tensor elementwise. - - Parameters - ========== - X - Type T. - 1D input tensor - - Returns - ======= - Y : Var - Type T. - 1D input tensor - - Notes - ===== - Signature: ``ai.onnx@1::Softplus``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Softplus( - _Softplus.Attributes(), - _Softplus.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def softsign( - input: Var, -) -> Var: - r""" - Calculates the softsign (x/(1+|x\|)) of the given input tensor - element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The softsign (x/(1+|x\|)) values of the input tensor computed - element-wise - - Notes - ===== - Signature: ``ai.onnx@1::Softsign``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Softsign( - _Softsign.Attributes(), - _Softsign.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def space_to_depth( - input: Var, - *, - blocksize: int, -) -> Var: - r""" - SpaceToDepth rearranges blocks of spatial data into depth. More - specifically, this op outputs a copy of the input tensor where values - from the height and width dimensions are moved to the depth dimension. - - Parameters - ========== - input - Type T. - Input tensor of [N,C,H,W], where N is the batch axis, C is the channel - or depth, H is the height and W is the width. - blocksize - Attribute. - Blocks of [blocksize, blocksize] are moved. - - Returns - ======= - output : Var - Type T. - Output tensor of [N, C \* blocksize \* blocksize, H/blocksize, - W/blocksize]. - - Notes - ===== - Signature: ``ai.onnx@13::SpaceToDepth``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _SpaceToDepth( - _SpaceToDepth.Attributes( - blocksize=AttrInt64(blocksize, name="blocksize"), - ), - _SpaceToDepth.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def split( - input: Var, - split: Optional[Var] = None, - *, - outputs_count: int, - axis: int = 0, -) -> Sequence[Var]: - r""" - Split a tensor into a list of tensors, along the specified 'axis'. - Lengths of the parts can be specified using input 'split'. Otherwise, - the tensor is split to equal sized parts. - - Parameters - ========== - input - Type T. - The tensor to split - split - Type tensor(int64). - Optional length of each output. Values should be >= 0.Sum of the values - must be equal to the dim value at 'axis' specified. - axis - Attribute. - Which axis to split on. A negative value means counting dimensions from - the back. Accepted range is [-rank, rank-1] where r = rank(input). - outputs_count - Specifies the number of variadic outputs of this operator. - Non-standard parameter created by the opset generator, as inference (a solution) it was not implemented or is impossible. - - Returns - ======= - outputs : Sequence[Var] - Type T. - One or more outputs forming list of tensors after splitting - - Notes - ===== - Signature: ``ai.onnx@13::Split``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Split( - _Split.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Split.Inputs( - input=unwrap_vars(input), - split=unwrap_vars(split), - ), - out_variadic=outputs_count, - ) - .get_output_vars( - input=get_value(input), - split=get_value(split), - ) - .outputs - ) - - -def split_to_sequence( - input: Var, - split: Optional[Var] = None, - *, - axis: int = 0, - keepdims: int = 1, -) -> Var: - r""" - Split a tensor into a sequence of tensors, along the specified 'axis'. - Lengths of the parts can be specified using the optional argument - 'split'. If the argument - ``split' is not specified, a default scalar value of 1 is used as the value of``\ split'. - 'split' must contain only positive numbers. 'split' is either a scalar - (tensor of empty shape), or a 1-D tensor. If 'split' is a scalar, then - 'input' will be split into chunks all of size 'split' if possible. The - last chunk alone may be smaller than 'split' if the 'input' size along - the given axis 'axis' is not divisible by 'split'. If 'split' is a - 1-dimensional tensor, the input tensor is split into 'size(split)' - chunks, with lengths of the parts on 'axis' specified in 'split'. In - this scenario, the sum of entries in 'split' must be equal to the - dimension size of input tensor on 'axis'. - - Parameters - ========== - input - Type T. - The tensor to split - split - Type I. - Length of each output. It can be either a scalar(tensor of empty shape), - or a 1-D tensor. All values must be >= 0. - axis - Attribute. - Which axis to split on. A negative value means counting dimensions from - the back. Accepted range is [-rank, rank-1]. - keepdims - Attribute. - Keep the split dimension or not. Default 1, which means we keep split - dimension. If input 'split' is specified, this attribute is ignored. - - Returns - ======= - output_sequence : Var - Type S. - One or more outputs forming a sequence of tensors after splitting - - Notes - ===== - Signature: ``ai.onnx@11::SplitToSequence``. - - Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - I: `tensor(int32)`, `tensor(int64)` - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - """ - return ( - _SplitToSequence( - _SplitToSequence.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), - _SplitToSequence.Inputs( - input=unwrap_vars(input), - split=unwrap_vars(split), - ), - ) - .get_output_vars( - input=get_value(input), - split=get_value(split), - ) - .output_sequence - ) - - -def sqrt( - X: Var, -) -> Var: - r""" - Square root takes one input data (Tensor) and produces one output - data (Tensor) where the square root is, y = x^0.5, is applied to the - tensor elementwise. If x is negative, then it will return NaN. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@13::Sqrt``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Sqrt( - _Sqrt.Attributes(), - _Sqrt.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def squeeze( - data: Var, - axes: Optional[Var] = None, -) -> Var: - r""" - Remove single-dimensional entries from the shape of a tensor. Takes an - input ``axes`` with a list of axes to squeeze. If ``axes`` is not - provided, all the single dimensions will be removed from the shape. If - an axis is selected with shape entry not equal to one, an error is - raised. - - Parameters - ========== - data - Type T. - Tensors with at least max(dims) dimensions. - axes - Type tensor(int64). - List of integers indicating the dimensions to squeeze. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(data). - - Returns - ======= - squeezed : Var - Type T. - Reshaped tensor with same data as input. - - Notes - ===== - Signature: ``ai.onnx@13::Squeeze``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Squeeze( - _Squeeze.Attributes(), - _Squeeze.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .squeezed - ) - - -def string_normalizer( - X: Var, - *, - case_change_action: str = "NONE", - is_case_sensitive: int = 0, - locale: Optional[str] = None, - stopwords: Optional[Iterable[str]] = None, -) -> Var: - r""" - StringNormalization performs string operations for basic cleaning. This - operator has only one input (denoted by X) and only one output (denoted - by Y). This operator first examines the elements in the X, and removes - elements specified in "stopwords" attribute. After removing stop words, - the intermediate result can be further lowercased, uppercased, or just - returned depending the "case_change_action" attribute. This operator - only accepts [C]- and [1, C]-tensor. If all elements in X are dropped, - the output will be the empty value of string tensor with shape [1] if - input shape is [C] and shape [1, 1] if input shape is [1, C]. - - Parameters - ========== - X - Type tensor(string). - UTF-8 strings to normalize - case_change_action - Attribute. - string enum that cases output to be lowercased/uppercases/unchanged. - Valid values are "LOWER", "UPPER", "NONE". Default is "NONE" - is_case_sensitive - Attribute. - Boolean. Whether the identification of stop words in X is - case-sensitive. Default is false - locale - Attribute. - Environment dependent string that denotes the locale according to which - output strings needs to be upper/lowercased.Default en_US or platform - specific equivalent as decided by the implementation. - stopwords - Attribute. - List of stop words. If not set, no word would be removed from X. - - Returns - ======= - Y : Var - Type tensor(string). - UTF-8 Normalized strings - - Notes - ===== - Signature: ``ai.onnx@10::StringNormalizer``. - - """ - return ( - _StringNormalizer( - _StringNormalizer.Attributes( - case_change_action=AttrString( - case_change_action, name="case_change_action" - ), - is_case_sensitive=AttrInt64( - is_case_sensitive, name="is_case_sensitive" - ), - locale=AttrString.maybe(locale, name="locale"), - stopwords=AttrStrings.maybe(stopwords, name="stopwords"), - ), - _StringNormalizer.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def sub( - A: Var, - B: Var, -) -> Var: - r""" - Performs element-wise binary subtraction (with Numpy-style broadcasting - support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - (Opset 14 change): Extend supported types to include uint8, int8, - uint16, and int16. - - Parameters - ========== - A - Type T. - First operand. - B - Type T. - Second operand. - - Returns - ======= - C : Var - Type T. - Result, has same element type as two inputs - - Notes - ===== - Signature: ``ai.onnx@14::Sub``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Sub( - _Sub.Attributes(), - _Sub.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def sum( - data_0: Sequence[Var], -) -> Var: - r""" - Element-wise sum of each of the input tensors (with Numpy-style - broadcasting support). All inputs and outputs must have the same data - type. This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - data_0 - Type T. - List of tensors for sum. - - Returns - ======= - sum : Var - Type T. - Output tensor. - - Notes - ===== - Signature: ``ai.onnx@13::Sum``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Sum( - _Sum.Attributes(), - _Sum.Inputs( - data_0=unwrap_vars(data_0), - ), - ) - .get_output_vars( - data_0=get_value(data_0), - ) - .sum - ) - - -def tan( - input: Var, -) -> Var: - r""" - Calculates the tangent of the given input tensor, element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The tangent of the input tensor computed element-wise - - Notes - ===== - Signature: ``ai.onnx@7::Tan``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Tan( - _Tan.Attributes(), - _Tan.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def tanh( - input: Var, -) -> Var: - r""" - Calculates the hyperbolic tangent of the given input tensor - element-wise. - - Parameters - ========== - input - Type T. - Input tensor - - Returns - ======= - output : Var - Type T. - The hyperbolic tangent values of the input tensor computed element-wise - - Notes - ===== - Signature: ``ai.onnx@13::Tanh``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Tanh( - _Tanh.Attributes(), - _Tanh.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def tf_idf_vectorizer( - X: Var, - *, - max_gram_length: int, - max_skip_count: int, - min_gram_length: int, - mode: str, - ngram_counts: Iterable[int], - ngram_indexes: Iterable[int], - pool_int64s: Optional[Iterable[int]] = None, - pool_strings: Optional[Iterable[str]] = None, - weights: Optional[Iterable[float]] = None, -) -> Var: - r""" - This transform extracts n-grams from the input sequence and save them as - a vector. Input can be either a 1-D or 2-D tensor. For 1-D input, output - is the n-gram representation of that input. For 2-D input, the output is - also a 2-D tensor whose i-th row is the n-gram representation of the - i-th input row. More specifically, if input shape is [C], the - corresponding output shape would be [max(ngram_indexes) + 1]. If input - shape is [N, C], this operator produces a [N, max(ngram_indexes) + - 1]-tensor. - - In contrast to standard n-gram extraction, here, the indexes of - extracting an n-gram from the original sequence are not necessarily - consecutive numbers. The discontinuity between indexes are controlled by - the number of skips. If the number of skips is 2, we should skip two - tokens when scanning through the original sequence. Let's consider an - example. Assume that input sequence is [94, 17, 36, 12, 28] and the - number of skips is 2. The associated 2-grams are [94, 12] and [17, 28] - respectively indexed by [0, 3] and [1, 4]. If the number of skips - becomes 0, the 2-grams generated are [94, 17], [17, 36], [36, 12], [12, - 28] indexed by [0, 1], [1, 2], [2, 3], [3, 4], respectively. - - The output vector (denoted by Y) stores the count of each n-gram; - Y[ngram_indexes[i]] indicates the times that the i-th n-gram is found. - The attribute ngram_indexes is used to determine the mapping between - index i and the corresponding n-gram's output coordinate. If pool_int64s - is [94, 17, 17, 36], ngram_indexes is [1, 0], ngram_counts=[0, 0], then - the Y[0] (first element in Y) and Y[1] (second element in Y) are the - counts of [17, 36] and [94, 17], respectively. An n-gram which cannot be - found in pool_strings/pool_int64s should be ignored and has no effect on - the output. Note that we may consider all skips up to S when generating - the n-grams. - - The examples used above are true if mode is "TF". If mode is "IDF", all - the counts larger than 1 would be truncated to 1 and the i-th element in - weights would be used to scale (by multiplication) the count of the i-th - n-gram in pool. If mode is "TFIDF", this operator first computes the - counts of all n-grams and then scale them by the associated values in - the weights attribute. - - Only one of pool_strings and pool_int64s can be set. If pool_int64s is - set, the input should be an integer tensor. If pool_strings is set, the - input must be a string tensor. - - Parameters - ========== - X - Type T. - Input for n-gram extraction - max_gram_length - Attribute. - Maximum n-gram length. If this value is 3, 3-grams will be used to - generate the output. - max_skip_count - Attribute. - Maximum number of items (integers/strings) to be skipped when - constructing an n-gram from X. If max_skip_count=1, min_gram_length=2, - max_gram_length=3, this operator may generate 2-grams with skip_count=0 - and skip_count=1, and 3-grams with skip_count=0 and skip_count=1 - min_gram_length - Attribute. - Minimum n-gram length. If this value is 2 and max_gram_length is 3, - output may contain counts of 2-grams and 3-grams. - mode - Attribute. - The weighting criteria. It can be one of "TF" (term frequency), "IDF" - (inverse document frequency), and "TFIDF" (the combination of TF and - IDF) - ngram_counts - Attribute. - The starting indexes of 1-grams, 2-grams, and so on in pool. It is - useful when determining the boundary between two consecutive collections - of n-grams. For example, if ngram_counts is [0, 17, 36], the first index - (zero-based) of 1-gram/2-gram/3-gram in pool are 0/17/36. This format is - essentially identical to CSR (or CSC) sparse matrix format, and we - choose to use this due to its popularity. - ngram_indexes - Attribute. - list of int64s (type: AttributeProto::INTS). This list is parallel to - the specified 'pool\_\*' attribute. The i-th element in ngram_indexes - indicate the coordinate of the i-th n-gram in the output tensor. - pool_int64s - Attribute. - List of int64 n-grams learned from the training set. Either this or - pool_strings attributes must be present but not both. It's an 1-D tensor - starting with the collections of all 1-grams and ending with the - collections of n-grams. The i-th element in pool stores the n-gram that - should be mapped to coordinate ngram_indexes[i] in the output vector. - pool_strings - Attribute. - List of strings n-grams learned from the training set. Either this or - pool_int64s attributes must be present but not both. It's an 1-D tensor - starting with the collections of all 1-grams and ending with the - collections of n-grams. The i-th element in pool stores the n-gram that - should be mapped to coordinate ngram_indexes[i] in the output vector. - weights - Attribute. - list of floats. This attribute stores the weight of each n-gram in pool. - The i-th element in weights is the weight of the i-th n-gram in pool. - Its length equals to the size of ngram_indexes. By default, weights is - an all-one tensor.This attribute is used when mode is "IDF" or "TFIDF" - to scale the associated word counts. - - Returns - ======= - Y : Var - Type T1. - Ngram results - - Notes - ===== - Signature: ``ai.onnx@9::TfIdfVectorizer``. - - Type constraints: - - T: `tensor(int32)`, `tensor(int64)`, `tensor(string)` - - T1: `tensor(float)` - """ - return ( - _TfIdfVectorizer( - _TfIdfVectorizer.Attributes( - max_gram_length=AttrInt64(max_gram_length, name="max_gram_length"), - max_skip_count=AttrInt64(max_skip_count, name="max_skip_count"), - min_gram_length=AttrInt64(min_gram_length, name="min_gram_length"), - mode=AttrString(mode, name="mode"), - ngram_counts=AttrInt64s(ngram_counts, name="ngram_counts"), - ngram_indexes=AttrInt64s(ngram_indexes, name="ngram_indexes"), - pool_int64s=AttrInt64s.maybe(pool_int64s, name="pool_int64s"), - pool_strings=AttrStrings.maybe(pool_strings, name="pool_strings"), - weights=AttrFloat32s.maybe(weights, name="weights"), - ), - _TfIdfVectorizer.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def thresholded_relu( - X: Var, - *, - alpha: float = 1.0, -) -> Var: - r""" - ThresholdedRelu takes one input data (Tensor) and produces one output - data (Tensor) where the rectified linear function, y = x for x > - alpha, y = 0 otherwise, is applied to the tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - alpha - Attribute. - Threshold value - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@10::ThresholdedRelu``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _ThresholdedRelu( - _ThresholdedRelu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), - _ThresholdedRelu.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) +This operator returns the unique values or sliced unique subtensors of +the input tensor and three optional outputs. The first output tensor 'Y' +contains all unique values or subtensors of the input. The second +optional output tensor 'indices' contains indices of 'Y' elements' first +occurrence in 'X'. The third optional output tensor 'inverse_indices' +contains, for elements of 'X', its corresponding indices in 'Y'. The +fourth optional output tensor 'counts' contains the count of each +element of 'Y' in the input. +Outputs are either sorted in ascending order or optionally in the order +of the first occurrence of the values in the input. -def tile( - input: Var, - repeats: Var, -) -> Var: - r""" - Constructs a tensor by tiling a given tensor. This is the same as - function ``tile`` in Numpy, but no broadcast. For example A = [[1, 2], - [3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]] - - Parameters - ========== - input - Type T. - Input tensor of any shape. - repeats - Type T1. - 1D int64 tensor of the same length as input's dimension number, includes - numbers of repeated copies along input's dimensions. - - Returns - ======= - output : Var - Type T. - Output tensor of the same dimensions and type as tensor input. - output_dim[i] = input_dim[i] \* repeats[i] - - Notes - ===== - Signature: ``ai.onnx@13::Tile``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` - """ - return ( - _Tile( - _Tile.Attributes(), - _Tile.Inputs( - input=unwrap_vars(input), - repeats=unwrap_vars(repeats), - ), - ) - .get_output_vars( - input=get_value(input), - repeats=get_value(repeats), - ) - .output - ) - - -def top_k( - X: Var, - K: Var, - *, - axis: int = -1, - largest: int = 1, - sorted: int = 1, -) -> tuple[Var, Var]: - r""" - Retrieve the top-K largest or smallest elements along a specified axis. - Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer - argument k, return two outputs: - - - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a\_{n-1}] which contains the values of the top k elements along - the specified axis - - - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a\_{n-1}] which contains the indices of the top k elements - (original indices from the input tensor). - - - If "largest" is 1 (the default value) then the k largest elements are - returned. - - - If "sorted" is 1 (the default value) then the resulting k elements - will be sorted. - - - If "sorted" is 0, order of returned 'Values' and 'Indices' are - undefined. - - Given two equivalent values, this operator uses the indices along the - axis as a tiebreaker. That is, the element with the lower index will - appear first. - - Parameters - ========== - X - Type T. - Tensor of shape [a_0, a_1, ..., a\_{n-1}] - K - Type tensor(int64). - A 1-D tensor containing a single positive value corresponding to the - number of top elements to retrieve - axis - Attribute. - Dimension on which to do the sort. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - largest - Attribute. - Whether to return the top-K largest or smallest elements. - sorted - Attribute. - Whether to return the elements in sorted order. - - Returns - ======= - Values : Var - Type T. - Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] containing top K values from the input tensor - Indices : Var - Type I. - Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] containing the corresponding input tensor indices for the top - K values. - - Notes - ===== - Signature: ``ai.onnx@11::TopK``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - I: `tensor(int64)` - """ - return ( - _TopK( - _TopK.Attributes( - axis=AttrInt64(axis, name="axis"), - largest=AttrInt64(largest, name="largest"), - sorted=AttrInt64(sorted, name="sorted"), - ), - _TopK.Inputs( - X=unwrap_vars(X), - K=unwrap_vars(K), - ), - ) - .get_output_vars( - X=get_value(X), - K=get_value(K), - ) - ._unpack_to_any() - ) - - -def transpose( - data: Var, - *, - perm: Optional[Iterable[int]] = None, -) -> Var: - r""" - Transpose the input tensor similar to numpy.transpose. For example, when - perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output - shape will be (2, 1, 3). - - Parameters - ========== - data - Type T. - An input tensor. - perm - Attribute. - A list of integers. By default, reverse the dimensions, otherwise - permute the axes according to the values given. - - Returns - ======= - transposed : Var - Type T. - Transposed output. - - Notes - ===== - Signature: ``ai.onnx@13::Transpose``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Transpose( - _Transpose.Attributes( - perm=AttrInt64s.maybe(perm, name="perm"), - ), - _Transpose.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .transposed - ) - - -def trilu( - input: Var, - k: Optional[Var] = None, - *, - upper: int = 1, -) -> Var: - r""" - Given a 2-D matrix or batches of 2-D matrices, returns the upper or - lower triangular part of the tensor(s). The attribute "upper" determines - whether the upper or lower part is retained. If set to true, the upper - triangular matrix is retained. Lower triangular matrix is retained - otherwise. Default value for the "upper" attribute is true. Trilu takes - one input tensor of shape [\*, N, M], where \* is zero or more batch - dimensions. The upper triangular part consists of the elements on and - above the given diagonal (k). The lower triangular part consists of - elements on and below the diagonal. All other elements in the matrix are - set to zero. If k = 0, the triangular part on and above/below the main - diagonal is retained. If upper is set to true, a positive k retains the - upper triangular matrix excluding the main diagonal and (k-1) diagonals - above it. A negative k value retains the main diagonal and \|k\| - diagonals below it. If upper is set to false, a positive k retains the - lower triangular matrix including the main diagonal and k diagonals - above it. A negative k value excludes the main diagonal and (\|k\|-1) - diagonals below it. - - Parameters - ========== - input - Type T. - Input tensor of rank 2 or higher. - k - Type tensor(int64). - A 0-D tensor containing a single value corresponding to the number - diagonals above or below the main diagonal to exclude or include. - Default value is 0 if it's not specified. - upper - Attribute. - Boolean. Indicates whether upper or lower part of matrix is retained. - Default is true. - - Returns - ======= - output : Var - Type T. - Output tensor of the same type and shape as the input tensor. - - Notes - ===== - Signature: ``ai.onnx@14::Trilu``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Trilu( - _Trilu.Attributes( - upper=AttrInt64(upper, name="upper"), - ), - _Trilu.Inputs( - input=unwrap_vars(input), - k=unwrap_vars(k), - ), - ) - .get_output_vars( - input=get_value(input), - k=get_value(k), - ) - .output - ) - - -def unique( - X: Var, - *, - axis: Optional[int] = None, - sorted: int = 1, -) -> tuple[Var, Var, Var, Var]: - r""" - Find the unique elements of a tensor. When an optional attribute 'axis' - is provided, unique subtensors sliced along the 'axis' are returned. - Otherwise the input tensor is flattened and unique values of the - flattened tensor are returned. - - This operator returns the unique values or sliced unique subtensors of - the input tensor and three optional outputs. The first output tensor 'Y' - contains all unique values or subtensors of the input. The second - optional output tensor 'indices' contains indices of 'Y' elements' first - occurrence in 'X'. The third optional output tensor 'inverse_indices' - contains, for elements of 'X', its corresponding indices in 'Y'. The - fourth optional output tensor 'counts' contains the count of each - element of 'Y' in the input. - - Outputs are either sorted in ascending order or optionally in the order - of the first occurrence of the values in the input. - - https://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html - - Example 1: - - :: - - input_X = [2, 1, 1, 3, 4, 3] - attribute_sorted = 0 - attribute_axis = None - output_Y = [2, 1, 3, 4] - output_indices = [0, 1, 3, 4] - output_inverse_indices = [0, 1, 1, 2, 3, 2] - output_counts = [1, 2, 2, 1] - - Example 2: - - :: +https://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html - input_X = [[1, 3], [2, 3]] - attribute_sorted = 1 - attribute_axis = None - output_Y = [1, 2, 3] - output_indices = [0, 2, 1] - output_inverse_indices = [0, 2, 1, 2] - output_counts = [1, 1, 2] +Example 1: - Example 3: +:: - :: + input_X = [2, 1, 1, 3, 4, 3] + attribute_sorted = 0 + attribute_axis = None + output_Y = [2, 1, 3, 4] + output_indices = [0, 1, 3, 4] + output_inverse_indices = [0, 1, 1, 2, 3, 2] + output_counts = [1, 2, 2, 1] - input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]] - attribute_sorted = 1 - attribute_axis = 0 - output_Y = [[1, 0, 0], [2, 3, 4]] - output_indices = [0, 2] - output_inverse_indices = [0, 0, 1] - output_counts = [2, 1] +Example 2: - Example 4: +:: + + input_X = [[1, 3], [2, 3]] + attribute_sorted = 1 + attribute_axis = None + output_Y = [1, 2, 3] + output_indices = [0, 2, 1] + output_inverse_indices = [0, 2, 1, 2] + output_counts = [1, 1, 2] + +Example 3: + +:: + + input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]] + attribute_sorted = 1 + attribute_axis = 0 + output_Y = [[1, 0, 0], [2, 3, 4]] + output_indices = [0, 2] + output_inverse_indices = [0, 0, 1] + output_counts = [2, 1] + +Example 4: + +:: + + input_x = [[[1., 1.], [0., 1.], [2., 1.], [0., 1.]], + [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]] + attribute_sorted = 1 + attribute_axis = 1 + +intermediate data are presented below for better understanding: there +are 4 subtensors sliced along axis 1 of input_x (shape = (2, 4, 2)): + +:: + + A: [[1, 1], [1, 1]], + [[0, 1], [0, 1]], + [[2, 1], [2, 1]], + [[0, 1], [0, 1]]. - :: +there are 3 unique subtensors: - input_x = [[[1., 1.], [0., 1.], [2., 1.], [0., 1.]], - [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]] - attribute_sorted = 1 - attribute_axis = 1 +:: - intermediate data are presented below for better understanding: there - are 4 subtensors sliced along axis 1 of input_x (shape = (2, 4, 2)): + [[1, 1], [1, 1]], + [[0, 1], [0, 1]], + [[2, 1], [2, 1]]. - :: +sorted unique subtensors: - A: [[1, 1], [1, 1]], - [[0, 1], [0, 1]], - [[2, 1], [2, 1]], - [[0, 1], [0, 1]]. +:: - there are 3 unique subtensors: + B: [[0, 1], [0, 1]], + [[1, 1], [1, 1]], + [[2, 1], [2, 1]]. - :: +output_Y is constructed from B: - [[1, 1], [1, 1]], - [[0, 1], [0, 1]], - [[2, 1], [2, 1]]. +:: - sorted unique subtensors: + [[[0. 1.], [1. 1.], [2. 1.]], + [[0. 1.], [1. 1.], [2. 1.]]] - :: +output_indices is to map from B to A: + +:: + + [1, 0, 2] + +output_inverse_indices is to map from A to B: + +:: + + [1, 0, 2, 0] + +output_counts: + +:: - B: [[0, 1], [0, 1]], - [[1, 1], [1, 1]], - [[2, 1], [2, 1]]. + [2, 1, 1] + +Parameters +========== +X + Type T. + A N-D input tensor that is to be processed. +axis + Attribute. + (Optional) The dimension to apply unique. If not specified, the unique + elements of the flattened input are returned. Negative value means + counting dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). +sorted + Attribute. + (Optional) Whether to sort the unique elements in ascending order before + returning as output. Must be one of 0, or 1 (default). - output_Y is constructed from B: - - :: - - [[[0. 1.], [1. 1.], [2. 1.]], - [[0. 1.], [1. 1.], [2. 1.]]] - - output_indices is to map from B to A: - - :: - - [1, 0, 2] - - output_inverse_indices is to map from A to B: - - :: - - [1, 0, 2, 0] - - output_counts: - - :: - - [2, 1, 1] - - Parameters - ========== - X - Type T. - A N-D input tensor that is to be processed. - axis - Attribute. - (Optional) The dimension to apply unique. If not specified, the unique - elements of the flattened input are returned. Negative value means - counting dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - sorted - Attribute. - (Optional) Whether to sort the unique elements in ascending order before - returning as output. Must be one of 0, or 1 (default). - - Returns - ======= - Y : Var - Type T. - A tensor of the same type as 'X' containing all the unique values or - subtensors sliced along a provided 'axis' in 'X', either sorted or - maintained in the same order they occur in input 'X' - indices : Var - Type tensor(int64). - A 1-D INT64 tensor containing indices of 'Y' elements' first occurrence - in 'X'. When 'axis' is provided, it contains indices to subtensors in - input 'X' on the 'axis'. When 'axis' is not provided, it contains - indices to values in the flattened input tensor. - inverse_indices : Var - Type tensor(int64). - A 1-D INT64 tensor containing, for elements of 'X', its corresponding - indices in 'Y'. When 'axis' is provided, it contains indices to - subtensors in output 'Y' on the 'axis'. When 'axis' is not provided, it - contains indices to values in output 'Y'. - counts : Var - Type tensor(int64). - A 1-D INT64 tensor containing the count of each element of 'Y' in input - 'X' - - Notes - ===== - Signature: ``ai.onnx@11::Unique``. - - Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Unique( - _Unique.Attributes( - axis=AttrInt64.maybe(axis, name="axis"), - sorted=AttrInt64(sorted, name="sorted"), - ), - _Unique.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - ._unpack_to_any() - ) - - -def unsqueeze( - data: Var, - axes: Var, -) -> Var: - r""" - Insert single-dimensional entries to the shape of an input tensor - (``data``). Takes one required input ``axes`` - which contains a list of - dimension indices and this operator will insert a dimension of value - ``1`` into the corresponding index of the output tensor (``expanded``). - - For example, given an input tensor (``data``) of shape [3, 4, 5], then - Unsqueeze(data, axes=[0, 4]) outputs a tensor (``expanded``) containing - same data as ``data`` but with shape [1, 3, 4, 5, 1]. - - The input ``axes`` should not contain any duplicate entries. It is an - error if it contains duplicates. The rank of the output tensor - (``output_rank``) is the rank of the input tensor (``data``) plus the - number of values in ``axes``. Each value in ``axes`` should be within - the (inclusive) range [-output_rank , output_rank - 1]. The order of - values in ``axes`` does not matter and can come in any order. - - Parameters - ========== - data - Type T. - Original tensor - axes - Type tensor(int64). - List of integers indicating the dimensions to be inserted. Negative - value means counting dimensions from the back. Accepted range is [-r, - r-1] where r = rank(expanded). - - Returns - ======= - expanded : Var - Type T. - Reshaped tensor with same data as input. - - Notes - ===== - Signature: ``ai.onnx@13::Unsqueeze``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Unsqueeze( - _Unsqueeze.Attributes(), - _Unsqueeze.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .expanded - ) - - -def where( - condition: Var, - X: Var, - Y: Var, -) -> Var: - r""" - Return elements, either from X or Y, depending on condition. Where - behaves like - `numpy.where `__ - with three parameters. - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - condition - Type B. - When True (nonzero), yield X, otherwise yield Y - X - Type T. - values selected at indices where condition is True - Y - Type T. - values selected at indices where condition is False - - Returns - ======= - output : Var - Type T. - Tensor of shape equal to the broadcasted shape of condition, X, and Y. - - Notes - ===== - Signature: ``ai.onnx@16::Where``. - - Type constraints: - - B: `tensor(bool)` - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return ( - _Where( - _Where.Attributes(), - _Where.Inputs( - condition=unwrap_vars(condition), - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ) - .get_output_vars( - condition=get_value(condition), - X=get_value(X), - Y=get_value(Y), - ) - .output - ) - - -def xor( - A: Var, - B: Var, -) -> Var: - r""" - Returns the tensor resulted from performing the ``xor`` logical - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@7::Xor``. - - Type constraints: - - T: `tensor(bool)` - - T1: `tensor(bool)` - """ - return ( - _Xor( - _Xor.Attributes(), - _Xor.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) +Returns +======= +Y : Var + Type T. + A tensor of the same type as 'X' containing all the unique values or + subtensors sliced along a provided 'axis' in 'X', either sorted or + maintained in the same order they occur in input 'X' +indices : Var + Type tensor(int64). + A 1-D INT64 tensor containing indices of 'Y' elements' first occurrence + in 'X'. When 'axis' is provided, it contains indices to subtensors in + input 'X' on the 'axis'. When 'axis' is not provided, it contains + indices to values in the flattened input tensor. +inverse_indices : Var + Type tensor(int64). + A 1-D INT64 tensor containing, for elements of 'X', its corresponding + indices in 'Y'. When 'axis' is provided, it contains indices to + subtensors in output 'Y' on the 'axis'. When 'axis' is not provided, it + contains indices to values in output 'Y'. +counts : Var + Type tensor(int64). + A 1-D INT64 tensor containing the count of each element of 'Y' in input + 'X' + +Notes +===== +Signature: ``ai.onnx@11::Unique``. + +Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Unique( + _Unique.Attributes( + axis=AttrInt64.maybe(axis, name="axis"), + sorted=AttrInt64(sorted, name="sorted"), + ), _Unique.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), )._unpack_to_any() + + +def unsqueeze(data: Var, axes: Var, ) -> Var: + r""" +Insert single-dimensional entries to the shape of an input tensor +(``data``). Takes one required input ``axes`` - which contains a list of +dimension indices and this operator will insert a dimension of value +``1`` into the corresponding index of the output tensor (``expanded``). + +For example, given an input tensor (``data``) of shape [3, 4, 5], then +Unsqueeze(data, axes=[0, 4]) outputs a tensor (``expanded``) containing +same data as ``data`` but with shape [1, 3, 4, 5, 1]. + +The input ``axes`` should not contain any duplicate entries. It is an +error if it contains duplicates. The rank of the output tensor +(``output_rank``) is the rank of the input tensor (``data``) plus the +number of values in ``axes``. Each value in ``axes`` should be within +the (inclusive) range [-output_rank , output_rank - 1]. The order of +values in ``axes`` does not matter and can come in any order. + +Parameters +========== +data + Type T. + Original tensor +axes + Type tensor(int64). + List of integers indicating the dimensions to be inserted. Negative + value means counting dimensions from the back. Accepted range is [-r, + r-1] where r = rank(expanded). + +Returns +======= +expanded : Var + Type T. + Reshaped tensor with same data as input. + +Notes +===== +Signature: ``ai.onnx@13::Unsqueeze``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Unsqueeze( + _Unsqueeze.Attributes( + ), _Unsqueeze.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).expanded + + +def where(condition: Var, X: Var, Y: Var, ) -> Var: + r""" +Return elements, either from X or Y, depending on condition. Where +behaves like +`numpy.where `__ +with three parameters. + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +condition + Type B. + When True (nonzero), yield X, otherwise yield Y +X + Type T. + values selected at indices where condition is True +Y + Type T. + values selected at indices where condition is False + +Returns +======= +output : Var + Type T. + Tensor of shape equal to the broadcasted shape of condition, X, and Y. + +Notes +===== +Signature: ``ai.onnx@16::Where``. + +Type constraints: + - B: `tensor(bool)` + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _Where( + _Where.Attributes( + ), _Where.Inputs( + condition=unwrap_vars(condition), X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( + condition=get_value(condition), X=get_value(X), Y=get_value(Y), ).output + + +def xor(A: Var, B: Var, ) -> Var: + r""" +Returns the tensor resulted from performing the ``xor`` logical +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. + +Returns +======= +C : Var + Type T1. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@7::Xor``. + +Type constraints: + - T: `tensor(bool)` + - T1: `tensor(bool)` + """ + return _Xor( + _Xor.Attributes( + ), _Xor.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -17076,4 +14373,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index f8de6f33..318c81f8 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -1,348 +1,200 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: BSD-3-Clause - # ruff: noqa: E741 -- Allow ambiguous variable name -from collections.abc import Iterable, Sequence +import typing +import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( + Any, + Callable, Optional, + Union, ) +from typing import cast as typing_cast import numpy as np import numpy.typing as npt +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( + AttrDtype, AttrFloat32, + AttrFloat32s, + AttrGraph, AttrInt64, AttrInt64s, AttrString, + AttrStrings, + AttrTensor, + AttrType, ) -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs +from spox._graph import Graph, subgraph +from spox._internal_op import intro from spox._node import OpType -from spox._standard import StandardNode -from spox._var import Var, VarInfo, get_value, unwrap_vars -from spox.opset.ai.onnx.v17 import ( - _DFT, - _GRU, - _LRN, - _LSTM, - _RNN, - _STFT, - _Abs, - _Acos, - _Acosh, - _Add, - _And, - _ArgMax, - _ArgMin, - _Asin, - _Asinh, - _Atan, - _Atanh, - _AveragePool, - _BatchNormalization, - _Bernoulli, - _BitShift, - _BlackmanWindow, - _Cast, - _CastLike, - _Ceil, - _Celu, - _Clip, - _Compress, - _Concat, - _ConcatFromSequence, - _Constant, - _ConstantOfShape, - _Conv, - _ConvInteger, - _ConvTranspose, - _Cos, - _Cosh, - _CumSum, - _DepthToSpace, - _DequantizeLinear, - _Det, - _Div, - _Dropout, - _DynamicQuantizeLinear, - _Einsum, - _Elu, - _Equal, - _Erf, - _Exp, - _Expand, - _EyeLike, - _Flatten, - _Floor, - _Gather, - _GatherElements, - _GatherND, - _Gemm, - _GlobalAveragePool, - _GlobalLpPool, - _GlobalMaxPool, - _Greater, - _GreaterOrEqual, - _GridSample, - _HammingWindow, - _HannWindow, - _Hardmax, - _HardSigmoid, - _HardSwish, - _Identity, - _If, - _InstanceNormalization, - _IsInf, - _IsNaN, - _LayerNormalization, - _LeakyRelu, - _Less, - _LessOrEqual, - _Log, - _LogSoftmax, - _Loop, - _LpNormalization, - _MatMul, - _MatMulInteger, - _Max, - _MaxPool, - _MaxRoiPool, - _MaxUnpool, - _Mean, - _MeanVarianceNormalization, - _MelWeightMatrix, - _Min, - _Mod, - _Mul, - _Multinomial, - _Neg, - _NegativeLogLikelihoodLoss, - _NonMaxSuppression, - _NonZero, - _Not, - _OneHot, - _Optional, - _Or, - _Pow, - _PRelu, - _QLinearConv, - _QLinearMatMul, - _QuantizeLinear, - _RandomNormal, - _RandomNormalLike, - _RandomUniform, - _RandomUniformLike, - _Range, - _Reciprocal, - _ReduceSum, - _Relu, - _Reshape, - _ReverseSequence, - _RoiAlign, - _Round, - _Scan, - _Selu, - _SequenceAt, - _SequenceConstruct, - _SequenceEmpty, - _SequenceErase, - _SequenceInsert, - _SequenceLength, - _SequenceMap, - _Shape, - _Shrink, - _Sigmoid, - _Sign, - _Sin, - _Sinh, - _Size, - _Slice, - _Softmax, - _SoftmaxCrossEntropyLoss, - _Softplus, - _Softsign, - _SpaceToDepth, - _SplitToSequence, - _Sqrt, - _Squeeze, - _StringNormalizer, - _Sub, - _Sum, - _Tan, - _Tanh, - _TfIdfVectorizer, - _ThresholdedRelu, - _Tile, - _TopK, - _Transpose, - _Trilu, - _Unique, - _Unsqueeze, - _Where, - _Xor, - abs, - acos, - acosh, - add, - and_, - arg_max, - arg_min, - asin, - asinh, - atan, - atanh, - average_pool, - batch_normalization, - bernoulli, - bit_shift, - blackman_window, - cast, - cast_like, - ceil, - celu, - clip, - compress, - concat, - concat_from_sequence, - constant, - constant_of_shape, - conv, - conv_integer, - conv_transpose, - cos, - cosh, - cumsum, - depth_to_space, - dequantize_linear, - det, - dft, - div, - dropout, - dynamic_quantize_linear, - einsum, - elu, - equal, - erf, - exp, - expand, - eye_like, - flatten, - floor, - gather, - gather_elements, - gather_nd, - gemm, - global_average_pool, - global_lp_pool, - global_max_pool, - greater, - greater_or_equal, - grid_sample, - gru, - hamming_window, - hann_window, - hard_sigmoid, - hard_swish, - hardmax, - identity, - if_, - instance_normalization, - isinf, - isnan, - layer_normalization, - leaky_relu, - less, - less_or_equal, - log, - log_softmax, - loop, - lp_normalization, - lrn, - lstm, - matmul, - matmul_integer, - max, - max_pool, - max_roi_pool, - max_unpool, - mean, - mean_variance_normalization, - mel_weight_matrix, - min, - mod, - mul, - multinomial, - neg, - negative_log_likelihood_loss, - non_max_suppression, - non_zero, - not_, - one_hot, - optional, - or_, - pow, - prelu, - qlinear_conv, - qlinear_matmul, - quantize_linear, - random_normal, - random_normal_like, - random_uniform, - random_uniform_like, - range, - reciprocal, - reduce_sum, - relu, - reshape, - reverse_sequence, - rnn, - roi_align, - round, - scan, - selu, - sequence_at, - sequence_construct, - sequence_empty, - sequence_erase, - sequence_insert, - sequence_length, - sequence_map, - shape, - shrink, - sigmoid, - sign, - sin, - sinh, - size, - slice, - softmax, - softmax_cross_entropy_loss, - softplus, - softsign, - space_to_depth, - split_to_sequence, - sqrt, - squeeze, - stft, - string_normalizer, - sub, - sum, - tan, - tanh, - tf_idf_vectorizer, - thresholded_relu, - tile, - top_k, - transpose, - trilu, - unique, - unsqueeze, - where, - xor, -) - - +from spox._standard import InferenceError, StandardNode +from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._value_prop import PropValueType + + +from spox.opset.ai.onnx.v17 import _Abs, abs +from spox.opset.ai.onnx.v17 import _Acos, acos +from spox.opset.ai.onnx.v17 import _Acosh, acosh +from spox.opset.ai.onnx.v17 import _Add, add +from spox.opset.ai.onnx.v17 import _And, and_ +from spox.opset.ai.onnx.v17 import _ArgMax, arg_max +from spox.opset.ai.onnx.v17 import _ArgMin, arg_min +from spox.opset.ai.onnx.v17 import _Asin, asin +from spox.opset.ai.onnx.v17 import _Asinh, asinh +from spox.opset.ai.onnx.v17 import _Atan, atan +from spox.opset.ai.onnx.v17 import _Atanh, atanh +from spox.opset.ai.onnx.v17 import _AveragePool, average_pool +from spox.opset.ai.onnx.v17 import _BatchNormalization, batch_normalization +from spox.opset.ai.onnx.v17 import _Bernoulli, bernoulli +from spox.opset.ai.onnx.v17 import _BitShift, bit_shift +from spox.opset.ai.onnx.v17 import _BlackmanWindow, blackman_window +from spox.opset.ai.onnx.v17 import _Cast, cast +from spox.opset.ai.onnx.v17 import _CastLike, cast_like +from spox.opset.ai.onnx.v17 import _Ceil, ceil +from spox.opset.ai.onnx.v17 import _Celu, celu +from spox.opset.ai.onnx.v17 import _Clip, clip +from spox.opset.ai.onnx.v17 import _Compress, compress +from spox.opset.ai.onnx.v17 import _Concat, concat +from spox.opset.ai.onnx.v17 import _ConcatFromSequence, concat_from_sequence +from spox.opset.ai.onnx.v17 import _Constant, constant +from spox.opset.ai.onnx.v17 import _ConstantOfShape, constant_of_shape +from spox.opset.ai.onnx.v17 import _Conv, conv +from spox.opset.ai.onnx.v17 import _ConvInteger, conv_integer +from spox.opset.ai.onnx.v17 import _ConvTranspose, conv_transpose +from spox.opset.ai.onnx.v17 import _Cos, cos +from spox.opset.ai.onnx.v17 import _Cosh, cosh +from spox.opset.ai.onnx.v17 import _CumSum, cumsum +from spox.opset.ai.onnx.v17 import _DFT, dft +from spox.opset.ai.onnx.v17 import _DepthToSpace, depth_to_space +from spox.opset.ai.onnx.v17 import _DequantizeLinear, dequantize_linear +from spox.opset.ai.onnx.v17 import _Det, det +from spox.opset.ai.onnx.v17 import _Div, div +from spox.opset.ai.onnx.v17 import _Dropout, dropout +from spox.opset.ai.onnx.v17 import _DynamicQuantizeLinear, dynamic_quantize_linear +from spox.opset.ai.onnx.v17 import _Einsum, einsum +from spox.opset.ai.onnx.v17 import _Elu, elu +from spox.opset.ai.onnx.v17 import _Equal, equal +from spox.opset.ai.onnx.v17 import _Erf, erf +from spox.opset.ai.onnx.v17 import _Exp, exp +from spox.opset.ai.onnx.v17 import _Expand, expand +from spox.opset.ai.onnx.v17 import _EyeLike, eye_like +from spox.opset.ai.onnx.v17 import _Flatten, flatten +from spox.opset.ai.onnx.v17 import _Floor, floor +from spox.opset.ai.onnx.v17 import _GRU, gru +from spox.opset.ai.onnx.v17 import _Gather, gather +from spox.opset.ai.onnx.v17 import _GatherElements, gather_elements +from spox.opset.ai.onnx.v17 import _GatherND, gather_nd +from spox.opset.ai.onnx.v17 import _Gemm, gemm +from spox.opset.ai.onnx.v17 import _GlobalAveragePool, global_average_pool +from spox.opset.ai.onnx.v17 import _GlobalLpPool, global_lp_pool +from spox.opset.ai.onnx.v17 import _GlobalMaxPool, global_max_pool +from spox.opset.ai.onnx.v17 import _Greater, greater +from spox.opset.ai.onnx.v17 import _GreaterOrEqual, greater_or_equal +from spox.opset.ai.onnx.v17 import _GridSample, grid_sample +from spox.opset.ai.onnx.v17 import _HammingWindow, hamming_window +from spox.opset.ai.onnx.v17 import _HannWindow, hann_window +from spox.opset.ai.onnx.v17 import _HardSigmoid, hard_sigmoid +from spox.opset.ai.onnx.v17 import _HardSwish, hard_swish +from spox.opset.ai.onnx.v17 import _Hardmax, hardmax +from spox.opset.ai.onnx.v17 import _Identity, identity +from spox.opset.ai.onnx.v17 import _If, if_ +from spox.opset.ai.onnx.v17 import _InstanceNormalization, instance_normalization +from spox.opset.ai.onnx.v17 import _IsInf, isinf +from spox.opset.ai.onnx.v17 import _IsNaN, isnan +from spox.opset.ai.onnx.v17 import _LRN, lrn +from spox.opset.ai.onnx.v17 import _LSTM, lstm +from spox.opset.ai.onnx.v17 import _LayerNormalization, layer_normalization +from spox.opset.ai.onnx.v17 import _LeakyRelu, leaky_relu +from spox.opset.ai.onnx.v17 import _Less, less +from spox.opset.ai.onnx.v17 import _LessOrEqual, less_or_equal +from spox.opset.ai.onnx.v17 import _Log, log +from spox.opset.ai.onnx.v17 import _LogSoftmax, log_softmax +from spox.opset.ai.onnx.v17 import _Loop, loop +from spox.opset.ai.onnx.v17 import _LpNormalization, lp_normalization +from spox.opset.ai.onnx.v17 import _MatMul, matmul +from spox.opset.ai.onnx.v17 import _MatMulInteger, matmul_integer +from spox.opset.ai.onnx.v17 import _Max, max +from spox.opset.ai.onnx.v17 import _MaxPool, max_pool +from spox.opset.ai.onnx.v17 import _MaxRoiPool, max_roi_pool +from spox.opset.ai.onnx.v17 import _MaxUnpool, max_unpool +from spox.opset.ai.onnx.v17 import _Mean, mean +from spox.opset.ai.onnx.v17 import _MeanVarianceNormalization, mean_variance_normalization +from spox.opset.ai.onnx.v17 import _MelWeightMatrix, mel_weight_matrix +from spox.opset.ai.onnx.v17 import _Min, min +from spox.opset.ai.onnx.v17 import _Mod, mod +from spox.opset.ai.onnx.v17 import _Mul, mul +from spox.opset.ai.onnx.v17 import _Multinomial, multinomial +from spox.opset.ai.onnx.v17 import _Neg, neg +from spox.opset.ai.onnx.v17 import _NegativeLogLikelihoodLoss, negative_log_likelihood_loss +from spox.opset.ai.onnx.v17 import _NonMaxSuppression, non_max_suppression +from spox.opset.ai.onnx.v17 import _NonZero, non_zero +from spox.opset.ai.onnx.v17 import _Not, not_ +from spox.opset.ai.onnx.v17 import _OneHot, one_hot +from spox.opset.ai.onnx.v17 import _Optional, optional +from spox.opset.ai.onnx.v17 import _Or, or_ +from spox.opset.ai.onnx.v17 import _PRelu, prelu +from spox.opset.ai.onnx.v17 import _Pow, pow +from spox.opset.ai.onnx.v17 import _QLinearConv, qlinear_conv +from spox.opset.ai.onnx.v17 import _QLinearMatMul, qlinear_matmul +from spox.opset.ai.onnx.v17 import _QuantizeLinear, quantize_linear +from spox.opset.ai.onnx.v17 import _RNN, rnn +from spox.opset.ai.onnx.v17 import _RandomNormal, random_normal +from spox.opset.ai.onnx.v17 import _RandomNormalLike, random_normal_like +from spox.opset.ai.onnx.v17 import _RandomUniform, random_uniform +from spox.opset.ai.onnx.v17 import _RandomUniformLike, random_uniform_like +from spox.opset.ai.onnx.v17 import _Range, range +from spox.opset.ai.onnx.v17 import _Reciprocal, reciprocal +from spox.opset.ai.onnx.v17 import _ReduceSum, reduce_sum +from spox.opset.ai.onnx.v17 import _Relu, relu +from spox.opset.ai.onnx.v17 import _Reshape, reshape +from spox.opset.ai.onnx.v17 import _ReverseSequence, reverse_sequence +from spox.opset.ai.onnx.v17 import _RoiAlign, roi_align +from spox.opset.ai.onnx.v17 import _Round, round +from spox.opset.ai.onnx.v17 import _STFT, stft +from spox.opset.ai.onnx.v17 import _Scan, scan +from spox.opset.ai.onnx.v17 import _Selu, selu +from spox.opset.ai.onnx.v17 import _SequenceAt, sequence_at +from spox.opset.ai.onnx.v17 import _SequenceConstruct, sequence_construct +from spox.opset.ai.onnx.v17 import _SequenceEmpty, sequence_empty +from spox.opset.ai.onnx.v17 import _SequenceErase, sequence_erase +from spox.opset.ai.onnx.v17 import _SequenceInsert, sequence_insert +from spox.opset.ai.onnx.v17 import _SequenceLength, sequence_length +from spox.opset.ai.onnx.v17 import _SequenceMap, sequence_map +from spox.opset.ai.onnx.v17 import _Shape, shape +from spox.opset.ai.onnx.v17 import _Shrink, shrink +from spox.opset.ai.onnx.v17 import _Sigmoid, sigmoid +from spox.opset.ai.onnx.v17 import _Sign, sign +from spox.opset.ai.onnx.v17 import _Sin, sin +from spox.opset.ai.onnx.v17 import _Sinh, sinh +from spox.opset.ai.onnx.v17 import _Size, size +from spox.opset.ai.onnx.v17 import _Slice, slice +from spox.opset.ai.onnx.v17 import _Softmax, softmax +from spox.opset.ai.onnx.v17 import _SoftmaxCrossEntropyLoss, softmax_cross_entropy_loss +from spox.opset.ai.onnx.v17 import _Softplus, softplus +from spox.opset.ai.onnx.v17 import _Softsign, softsign +from spox.opset.ai.onnx.v17 import _SpaceToDepth, space_to_depth +from spox.opset.ai.onnx.v17 import _SplitToSequence, split_to_sequence +from spox.opset.ai.onnx.v17 import _Sqrt, sqrt +from spox.opset.ai.onnx.v17 import _Squeeze, squeeze +from spox.opset.ai.onnx.v17 import _StringNormalizer, string_normalizer +from spox.opset.ai.onnx.v17 import _Sub, sub +from spox.opset.ai.onnx.v17 import _Sum, sum +from spox.opset.ai.onnx.v17 import _Tan, tan +from spox.opset.ai.onnx.v17 import _Tanh, tanh +from spox.opset.ai.onnx.v17 import _TfIdfVectorizer, tf_idf_vectorizer +from spox.opset.ai.onnx.v17 import _ThresholdedRelu, thresholded_relu +from spox.opset.ai.onnx.v17 import _Tile, tile +from spox.opset.ai.onnx.v17 import _TopK, top_k +from spox.opset.ai.onnx.v17 import _Transpose, transpose +from spox.opset.ai.onnx.v17 import _Trilu, trilu +from spox.opset.ai.onnx.v17 import _Unique, unique +from spox.opset.ai.onnx.v17 import _Unsqueeze, unsqueeze +from spox.opset.ai.onnx.v17 import _Where, where +from spox.opset.ai.onnx.v17 import _Xor, xor class _BitwiseAnd(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -363,7 +215,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _BitwiseNot(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -383,7 +234,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _BitwiseOr(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -404,7 +254,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _BitwiseXor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -425,7 +274,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _CenterCropPad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -446,7 +294,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Col2Im(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -470,7 +317,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GroupNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -493,7 +339,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _LpPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -519,7 +364,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Mish(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -539,7 +383,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _OptionalGetElement(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -559,7 +402,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _OptionalHasElement(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -579,7 +421,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Pad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -602,7 +443,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceL1(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -624,7 +464,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceL2(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -646,7 +485,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceLogSum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -668,7 +506,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceLogSumExp(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -690,7 +527,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceMax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -712,7 +548,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceMean(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -734,7 +569,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceMin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -756,7 +590,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceProd(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -778,7 +611,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceSumSquare(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -800,7 +632,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Resize(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -831,7 +662,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ScatterElements(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -854,7 +684,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ScatterND(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -876,7 +705,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Split(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -898,2102 +726,1684 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - -def bitwise_and( - A: Var, - B: Var, -) -> Var: +def bitwise_and(A: Var, B: Var, ) -> Var: r""" - Returns the tensor resulting from performing the bitwise ``and`` - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the bitwise operator. - B - Type T. - Second input operand for the bitwise operator. - - Returns - ======= - C : Var - Type T. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@18::BitwiseAnd``. - - Type constraints: - - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Returns the tensor resulting from performing the bitwise ``and`` +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the bitwise operator. +B + Type T. + Second input operand for the bitwise operator. + +Returns +======= +C : Var + Type T. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@18::BitwiseAnd``. + +Type constraints: + - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _BitwiseAnd( - _BitwiseAnd.Attributes(), - _BitwiseAnd.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def bitwise_not( - X: Var, -) -> Var: + return _BitwiseAnd( + _BitwiseAnd.Attributes( + ), _BitwiseAnd.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def bitwise_not(X: Var, ) -> Var: r""" - Returns the bitwise not of the input tensor element-wise. - - Parameters - ========== - X - Type T. - Input tensor - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@18::BitwiseNot``. - - Type constraints: - - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Returns the bitwise not of the input tensor element-wise. + +Parameters +========== +X + Type T. + Input tensor + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@18::BitwiseNot``. + +Type constraints: + - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _BitwiseNot( - _BitwiseNot.Attributes(), - _BitwiseNot.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def bitwise_or( - A: Var, - B: Var, -) -> Var: + return _BitwiseNot( + _BitwiseNot.Attributes( + ), _BitwiseNot.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def bitwise_or(A: Var, B: Var, ) -> Var: r""" - Returns the tensor resulting from performing the bitwise ``or`` - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the bitwise operator. - B - Type T. - Second input operand for the bitwise operator. - - Returns - ======= - C : Var - Type T. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@18::BitwiseOr``. - - Type constraints: - - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Returns the tensor resulting from performing the bitwise ``or`` +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the bitwise operator. +B + Type T. + Second input operand for the bitwise operator. + +Returns +======= +C : Var + Type T. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@18::BitwiseOr``. + +Type constraints: + - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _BitwiseOr( - _BitwiseOr.Attributes(), - _BitwiseOr.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def bitwise_xor( - A: Var, - B: Var, -) -> Var: + return _BitwiseOr( + _BitwiseOr.Attributes( + ), _BitwiseOr.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def bitwise_xor(A: Var, B: Var, ) -> Var: r""" - Returns the tensor resulting from performing the bitwise ``xor`` - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the bitwise operator. - B - Type T. - Second input operand for the bitwise operator. - - Returns - ======= - C : Var - Type T. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@18::BitwiseXor``. - - Type constraints: - - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Returns the tensor resulting from performing the bitwise ``xor`` +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the bitwise operator. +B + Type T. + Second input operand for the bitwise operator. + +Returns +======= +C : Var + Type T. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@18::BitwiseXor``. + +Type constraints: + - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _BitwiseXor( - _BitwiseXor.Attributes(), - _BitwiseXor.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) - - -def center_crop_pad( - input_data: Var, - shape: Var, - *, - axes: Optional[Iterable[int]] = None, -) -> Var: + return _BitwiseXor( + _BitwiseXor.Attributes( + ), _BitwiseXor.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C + + +def center_crop_pad(input_data: Var, shape: Var, *, axes: Optional[Iterable[int]] = None, ) -> Var: r""" - Center crop or pad an input to given dimensions. - - The crop/pad dimensions can be specified for a subset of the ``axes``. - Non-specified dimensions will not be cropped or padded. - - If the input dimensions are bigger than the crop shape, a centered - cropping window is extracted from the input. If the input dimensions are - smaller than the crop shape, the input is padded on each side equally, - so that the input is centered in the output. - - Parameters - ========== - input_data - Type T. - Input to extract the centered crop from. - shape - Type Tind. - 1-D tensor representing the cropping window dimensions. - axes - Attribute. - If provided, it specifies a subset of axes that 'shape' refer to. If not - provided, all axes are assumed [0, 1, ..., r-1], where r = rank(data). - Negative value means counting dimensions from the back. Accepted range - is [-r, r-1], where r = rank(data). Behavior is undefined if an axis is - repeated. - - Returns - ======= - output_data : Var - Type T. - Output data. - - Notes - ===== - Signature: ``ai.onnx@18::CenterCropPad``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` +Center crop or pad an input to given dimensions. + +The crop/pad dimensions can be specified for a subset of the ``axes``. +Non-specified dimensions will not be cropped or padded. + +If the input dimensions are bigger than the crop shape, a centered +cropping window is extracted from the input. If the input dimensions are +smaller than the crop shape, the input is padded on each side equally, +so that the input is centered in the output. + +Parameters +========== +input_data + Type T. + Input to extract the centered crop from. +shape + Type Tind. + 1-D tensor representing the cropping window dimensions. +axes + Attribute. + If provided, it specifies a subset of axes that 'shape' refer to. If not + provided, all axes are assumed [0, 1, ..., r-1], where r = rank(data). + Negative value means counting dimensions from the back. Accepted range + is [-r, r-1], where r = rank(data). Behavior is undefined if an axis is + repeated. + +Returns +======= +output_data : Var + Type T. + Output data. + +Notes +===== +Signature: ``ai.onnx@18::CenterCropPad``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return ( - _CenterCropPad( - _CenterCropPad.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - ), - _CenterCropPad.Inputs( - input_data=unwrap_vars(input_data), - shape=unwrap_vars(shape), - ), - ) - .get_output_vars( - input_data=get_value(input_data), - shape=get_value(shape), - ) - .output_data - ) - - -def col2_im( - input: Var, - image_shape: Var, - block_shape: Var, - *, - dilations: Optional[Iterable[int]] = None, - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: + return _CenterCropPad( + _CenterCropPad.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + ), _CenterCropPad.Inputs( + input_data=unwrap_vars(input_data), shape=unwrap_vars(shape), ), ).get_output_vars( + input_data=get_value(input_data), shape=get_value(shape), ).output_data + + +def col2_im(input: Var, image_shape: Var, block_shape: Var, *, dilations: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: r""" - The operator rearranges column blocks back into a multidimensional image - - Col2Im behaves similarly to PyTorch's fold - https://pytorch.org/docs/stable/generated/torch.nn.Fold.html, but it - only supports *batched* multi-dimensional image tensors. Another - implementation in Python with N-dimension support can be found at - https://github.com/f-dangel/unfoldNd/. - - NOTE: Although specifying image_shape looks redundant because it could - be calculated from convolution formulas, it is required as input for - more advanced scenarios as explained at PyTorch's implementation - (https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Col2Im.cpp#L10) - - Parameters - ========== - input - Type T. - Input data tensor to be rearranged from column blocks back into an - image. This is a 3-dimensional tensor containing [N, C \* - n-ary-product(block_shape), L], where N is batch dimension, C is image - channel dimension and L is number of blocks.The blocks are enumerated in - increasing lexicographic-order of their indices.For example, with an - image-size 10\ *20 and block-size 9*\ 18, there would be 2*3 blocks, - enumerated in the order block(0, 0), block(0, 1), block(0, 2), block(1, - 0), block(1, 1), block(1, 2). - image_shape - Type tensor(int64). - The shape of the spatial dimensions of the image after rearranging the - column blocks.This is a 1-dimensional tensor with size of at least 2, - containing the value [H_img, W_img] for a 2-D image or [dim_i1, dim_i2, - ..., dim_iN] for a N-D image. - block_shape - Type tensor(int64). - The shape of the block to apply on the input.This is a 1-dimensional - tensor of size of at least 2, containing the value [H_block, W_block] - for a 2-D image or [dim_b1, dim_b2, ..., dim_bN] for a N-D block.This is - the block-shape before dilation is applied to it. - dilations - Attribute. - 1-dimensional tensor with dilation value along each spatial axis of the - image. If not present, the dilation defaults to 1 along each spatial - axis of the image. - pads - Attribute. - 1-dimensional tensor with padding value for the beginning and ending - along each spatial axis, it can take any value greater than or equal to - 0. The value represent the number of pixels added to the beginning and - end part of the corresponding axis. ``pads`` format should be as follow - [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin is the number - of pixels added at the beginning of axis ``i`` and xi_end is the number - of pixels added at the end of axis ``i``. If not present, the padding - defaults to 0 along start and end of each spatial axis. - strides - Attribute. - 1-dimensional tensor with stride value along each spatial axis. If not - present, the stride defaults to 1 along each spatial axis. - - Returns - ======= - output : Var - Type T. - Output tensor produced by rearranging blocks into an image. - - Notes - ===== - Signature: ``ai.onnx@18::Col2Im``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +The operator rearranges column blocks back into a multidimensional image + +Col2Im behaves similarly to PyTorch's fold +https://pytorch.org/docs/stable/generated/torch.nn.Fold.html, but it +only supports *batched* multi-dimensional image tensors. Another +implementation in Python with N-dimension support can be found at +https://github.com/f-dangel/unfoldNd/. + +NOTE: Although specifying image_shape looks redundant because it could +be calculated from convolution formulas, it is required as input for +more advanced scenarios as explained at PyTorch's implementation +(https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Col2Im.cpp#L10) + +Parameters +========== +input + Type T. + Input data tensor to be rearranged from column blocks back into an + image. This is a 3-dimensional tensor containing [N, C \* + n-ary-product(block_shape), L], where N is batch dimension, C is image + channel dimension and L is number of blocks.The blocks are enumerated in + increasing lexicographic-order of their indices.For example, with an + image-size 10\ *20 and block-size 9*\ 18, there would be 2*3 blocks, + enumerated in the order block(0, 0), block(0, 1), block(0, 2), block(1, + 0), block(1, 1), block(1, 2). +image_shape + Type tensor(int64). + The shape of the spatial dimensions of the image after rearranging the + column blocks.This is a 1-dimensional tensor with size of at least 2, + containing the value [H_img, W_img] for a 2-D image or [dim_i1, dim_i2, + ..., dim_iN] for a N-D image. +block_shape + Type tensor(int64). + The shape of the block to apply on the input.This is a 1-dimensional + tensor of size of at least 2, containing the value [H_block, W_block] + for a 2-D image or [dim_b1, dim_b2, ..., dim_bN] for a N-D block.This is + the block-shape before dilation is applied to it. +dilations + Attribute. + 1-dimensional tensor with dilation value along each spatial axis of the + image. If not present, the dilation defaults to 1 along each spatial + axis of the image. +pads + Attribute. + 1-dimensional tensor with padding value for the beginning and ending + along each spatial axis, it can take any value greater than or equal to + 0. The value represent the number of pixels added to the beginning and + end part of the corresponding axis. ``pads`` format should be as follow + [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin is the number + of pixels added at the beginning of axis ``i`` and xi_end is the number + of pixels added at the end of axis ``i``. If not present, the padding + defaults to 0 along start and end of each spatial axis. +strides + Attribute. + 1-dimensional tensor with stride value along each spatial axis. If not + present, the stride defaults to 1 along each spatial axis. + +Returns +======= +output : Var + Type T. + Output tensor produced by rearranging blocks into an image. + +Notes +===== +Signature: ``ai.onnx@18::Col2Im``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Col2Im( - _Col2Im.Attributes( - dilations=AttrInt64s.maybe(dilations, name="dilations"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _Col2Im.Inputs( - input=unwrap_vars(input), - image_shape=unwrap_vars(image_shape), - block_shape=unwrap_vars(block_shape), - ), - ) - .get_output_vars( - input=get_value(input), - image_shape=get_value(image_shape), - block_shape=get_value(block_shape), - ) - .output - ) - - -def group_normalization( - X: Var, - scale: Var, - bias: Var, - *, - epsilon: float = 9.999999747378752e-06, - num_groups: int, -) -> Var: + return _Col2Im( + _Col2Im.Attributes( + dilations=AttrInt64s.maybe(dilations, name="dilations"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _Col2Im.Inputs( + input=unwrap_vars(input), image_shape=unwrap_vars(image_shape), block_shape=unwrap_vars(block_shape), ), ).get_output_vars( + input=get_value(input), image_shape=get_value(image_shape), block_shape=get_value(block_shape), ).output + + +def group_normalization(X: Var, scale: Var, bias: Var, *, epsilon: float = 9.999999747378752e-06, num_groups: int, ) -> Var: r""" - A GroupNormalization function. Carries out group normalization as - described in the paper https://arxiv.org/abs/1803.08494 - - This operator transforms input according to - - :: - - y = scale * (x - mean) / sqrt(variance + epsilon) + bias, - - where the mean and variance are computed per instance per group of - channels, and ``scale`` and ``bias`` should be specified for each group - of channels. The number of groups ``num_groups`` should be divisible by - the number of channels so that there are an equal number of channels per - group. - - When the number of groups is the same as the number of channels, this - operator is equivalent to InstanceNormalization. When there is only one - group, this operator is equivalent to LayerNormalization. - - Parameters - ========== - X - Type T. - Input data tensor. Dimensions for image cases are ``(N x C x H x W)``, - where ``N`` is the batch size, ``C`` is the number of channels, and - ``H`` and ``W`` are the height and width of the data. Statistics are - computed for every group of channels over ``C``, ``H``, and ``W``. For - non-image cases, the dimensions are in the form of - ``(N x C x D1 x D2 ... Dn)``. - scale - Type T. - Scale tensor of shape ``(num_groups)``. - bias - Type T. - Bias tensor of shape ``(num_groups)``. - epsilon - Attribute. - The epsilon value to use to avoid division by zero. - num_groups - Attribute. - The number of groups of channels. It should be a divisor of the number - of channels ``C``. - - Returns - ======= - Y : Var - Type T. - The output tensor of the same shape as ``X``. - - Notes - ===== - Signature: ``ai.onnx@18::GroupNormalization``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` +A GroupNormalization function. Carries out group normalization as +described in the paper https://arxiv.org/abs/1803.08494 + +This operator transforms input according to + +:: + + y = scale * (x - mean) / sqrt(variance + epsilon) + bias, + +where the mean and variance are computed per instance per group of +channels, and ``scale`` and ``bias`` should be specified for each group +of channels. The number of groups ``num_groups`` should be divisible by +the number of channels so that there are an equal number of channels per +group. + +When the number of groups is the same as the number of channels, this +operator is equivalent to InstanceNormalization. When there is only one +group, this operator is equivalent to LayerNormalization. + +Parameters +========== +X + Type T. + Input data tensor. Dimensions for image cases are ``(N x C x H x W)``, + where ``N`` is the batch size, ``C`` is the number of channels, and + ``H`` and ``W`` are the height and width of the data. Statistics are + computed for every group of channels over ``C``, ``H``, and ``W``. For + non-image cases, the dimensions are in the form of + ``(N x C x D1 x D2 ... Dn)``. +scale + Type T. + Scale tensor of shape ``(num_groups)``. +bias + Type T. + Bias tensor of shape ``(num_groups)``. +epsilon + Attribute. + The epsilon value to use to avoid division by zero. +num_groups + Attribute. + The number of groups of channels. It should be a divisor of the number + of channels ``C``. + +Returns +======= +Y : Var + Type T. + The output tensor of the same shape as ``X``. + +Notes +===== +Signature: ``ai.onnx@18::GroupNormalization``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _GroupNormalization( - _GroupNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - num_groups=AttrInt64(num_groups, name="num_groups"), - ), - _GroupNormalization.Inputs( - X=unwrap_vars(X), - scale=unwrap_vars(scale), - bias=unwrap_vars(bias), - ), - ) - .get_output_vars( - X=get_value(X), - scale=get_value(scale), - bias=get_value(bias), - ) - .Y - ) - - -def lp_pool( - X: Var, - *, - auto_pad: str = "NOTSET", - ceil_mode: int = 0, - dilations: Optional[Iterable[int]] = None, - kernel_shape: Iterable[int], - p: int = 2, - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: + return _GroupNormalization( + _GroupNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + num_groups=AttrInt64(num_groups, name="num_groups"), + ), _GroupNormalization.Inputs( + X=unwrap_vars(X), scale=unwrap_vars(scale), bias=unwrap_vars(bias), ), ).get_output_vars( + X=get_value(X), scale=get_value(scale), bias=get_value(bias), ).Y + + +def lp_pool(X: Var, *, auto_pad: str = "NOTSET", ceil_mode: int = 0, dilations: Optional[Iterable[int]] = None, kernel_shape: Iterable[int], p: int = 2, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: r""" - LpPool consumes an input tensor X and applies Lp pooling across the - tensor according to kernel sizes, stride sizes, and pad lengths. Lp - pooling consisting of computing the Lp norm on all values of a subset of - the input tensor according to the kernel size and downsampling the data - into the output tensor Y for further processing. The output spatial - shape will be following: - - :: - - output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) - - or - - :: - - output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) - - if ceil_mode is enabled ``pad_shape[i]`` is the sum of pads along axis - ``i``. - - ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, - the output spatial shape will be following: - - :: - - VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) - - And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: - - :: - - pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i] - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. - ceil_mode - Attribute. - Whether to use ceil or floor (default) to compute the output shape. - dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults is 1 along each spatial axis. - kernel_shape - Attribute. - The size of the kernel along each axis. - p - Attribute. - p value of the Lp norm used to pool over the input data. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - - Returns - ======= - Y : Var - Type T. - Output data tensor from Lp pooling across the input tensor. Dimensions - will vary based on various kernel, stride, and pad sizes. - - Notes - ===== - Signature: ``ai.onnx@18::LpPool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +LpPool consumes an input tensor X and applies Lp pooling across the +tensor according to kernel sizes, stride sizes, and pad lengths. Lp +pooling consisting of computing the Lp norm on all values of a subset of +the input tensor according to the kernel size and downsampling the data +into the output tensor Y for further processing. The output spatial +shape will be following: + +:: + + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) + +or + +:: + + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) + +if ceil_mode is enabled ``pad_shape[i]`` is the sum of pads along axis +``i``. + +``auto_pad`` is a DEPRECATED attribute. If you are using them currently, +the output spatial shape will be following: + +:: + + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + +And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: + +:: + + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i] + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. +ceil_mode + Attribute. + Whether to use ceil or floor (default) to compute the output shape. +dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults is 1 along each spatial axis. +kernel_shape + Attribute. + The size of the kernel along each axis. +p + Attribute. + p value of the Lp norm used to pool over the input data. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + +Returns +======= +Y : Var + Type T. + Output data tensor from Lp pooling across the input tensor. Dimensions + will vary based on various kernel, stride, and pad sizes. + +Notes +===== +Signature: ``ai.onnx@18::LpPool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _LpPool( - _LpPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - p=AttrInt64(p, name="p"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _LpPool.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def mish( - X: Var, -) -> Var: + return _LpPool( + _LpPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + p=AttrInt64(p, name="p"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _LpPool.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def mish(X: Var, ) -> Var: r""" - Mish: A Self Regularized Non-Monotonic Neural Activation Function. +Mish: A Self Regularized Non-Monotonic Neural Activation Function. - Perform the linear unit element-wise on the input tensor X using - formula: +Perform the linear unit element-wise on the input tensor X using +formula: - :: +:: - mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x})) + mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x})) - Parameters - ========== - X - Type T. - Input tensor +Parameters +========== +X + Type T. + Input tensor - Returns - ======= - Y : Var - Type T. - Output tensor +Returns +======= +Y : Var + Type T. + Output tensor - Notes - ===== - Signature: ``ai.onnx@18::Mish``. +Notes +===== +Signature: ``ai.onnx@18::Mish``. - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _Mish( - _Mish.Attributes(), - _Mish.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def optional_get_element( - input: Var, -) -> Var: + return _Mish( + _Mish.Attributes( + ), _Mish.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def optional_get_element(input: Var, ) -> Var: r""" - If the input is a tensor or sequence type, it returns the input. If the - input is an optional type, it outputs the element in the input. It is an - error if the input is an empty optional-type (i.e. does not have an - element) and the behavior is undefined in this case. - - Parameters - ========== - input - Type O. - The optional input. - - Returns - ======= - output : Var - Type V. - Output element in the optional input. - - Notes - ===== - Signature: ``ai.onnx@18::OptionalGetElement``. - - Type constraints: - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +If the input is a tensor or sequence type, it returns the input. If the +input is an optional type, it outputs the element in the input. It is an +error if the input is an empty optional-type (i.e. does not have an +element) and the behavior is undefined in this case. + +Parameters +========== +input + Type O. + The optional input. + +Returns +======= +output : Var + Type V. + Output element in the optional input. + +Notes +===== +Signature: ``ai.onnx@18::OptionalGetElement``. + +Type constraints: + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _OptionalGetElement( - _OptionalGetElement.Attributes(), - _OptionalGetElement.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def optional_has_element( - input: Optional[Var] = None, -) -> Var: + return _OptionalGetElement( + _OptionalGetElement.Attributes( + ), _OptionalGetElement.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def optional_has_element(input: Optional[Var] = None, ) -> Var: r""" - Returns true if (1) the input is an optional-type and contains an - element, or, (2) the input is a tensor or sequence type. If the input is - not provided or is an empty optional-type, this op returns false. - - Parameters - ========== - input - Type O. - The optional input. - - Returns - ======= - output : Var - Type B. - A scalar boolean tensor. If true, it indicates that optional-type input - contains an element. Otherwise, it is empty. - - Notes - ===== - Signature: ``ai.onnx@18::OptionalHasElement``. - - Type constraints: - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - B: `tensor(bool)` +Returns true if (1) the input is an optional-type and contains an +element, or, (2) the input is a tensor or sequence type. If the input is +not provided or is an empty optional-type, this op returns false. + +Parameters +========== +input + Type O. + The optional input. + +Returns +======= +output : Var + Type B. + A scalar boolean tensor. If true, it indicates that optional-type input + contains an element. Otherwise, it is empty. + +Notes +===== +Signature: ``ai.onnx@18::OptionalHasElement``. + +Type constraints: + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - B: `tensor(bool)` """ - return ( - _OptionalHasElement( - _OptionalHasElement.Attributes(), - _OptionalHasElement.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def pad( - data: Var, - pads: Var, - constant_value: Optional[Var] = None, - axes: Optional[Var] = None, - *, - mode: str = "constant", -) -> Var: + return _OptionalHasElement( + _OptionalHasElement.Attributes( + ), _OptionalHasElement.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output + + +def pad(data: Var, pads: Var, constant_value: Optional[Var] = None, axes: Optional[Var] = None, *, mode: str = "constant", ) -> Var: r""" - Given a tensor containing the data to be padded (``data``), a tensor - containing the number of start and end pad values for axis (``pads``), - (optionally) a ``mode``, and (optionally) ``constant_value``, a padded - tensor (``output``) is generated. - - The three supported ``modes`` are (similar to corresponding modes - supported by ``numpy.pad``): - - 1) ``constant``\ (default) - pads with a given constant value as - specified by ``constant_value`` (which defaults to 0, empty string, - or False) - - 2) ``reflect`` - pads with the reflection of the vector mirrored on the - first and last values of the vector along each axis - - 3) ``edge`` - pads with the edge values of array - - Example 1 (``constant`` mode): - - Insert 0 pads to the beginning of the second dimension. - - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'constant' - - constant_value = 0.0 - - output = [ - [0.0, 0.0, 1.0, 1.2], - [0.0, 0.0, 2.3, 3.4], - [0.0, 0.0, 4.5, 5.7], - ] - - Example 2 (``reflect`` mode): - - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'reflect' - - output = [ - [1.0, 1.2, 1.0, 1.2], - [2.3, 3.4, 2.3, 3.4], - [4.5, 5.7, 4.5, 5.7], - ] - - Example 3 (``edge`` mode): - - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'edge' - - output = [ - [1.0, 1.0, 1.0, 1.2], - [2.3, 2.3, 2.3, 3.4], - [4.5, 4.5, 4.5, 5.7], - ] - - Parameters - ========== - data - Type T. - Input tensor. - pads - Type tensor(int64). - Tensor of integers indicating the number of padding elements to add or - remove (if negative) at the beginning and end of each axis. For 2D input - tensor, it is the number of pixels. ``pads`` should be a 1D tensor of - shape [2 \* num_axes] where ``num_axes`` refers to the number of - elements in the ``axes`` input or the input rank if ``axes`` are not - provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, - ..., x1_end, x2_end,...], where xi_begin is the number of pad values - added at the beginning of axis ``axes[i]`` and xi_end, the number of pad - values added at the end of axis ``axes[i]``. - constant_value - Type T. - (Optional) A scalar value to be used if the mode chosen is ``constant`` - (by default it is 0, empty string or False). - axes - Type Tind. - 1-D tensor of axes that ``pads`` apply to. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(data). Behavior is undefined if an axis is repeated. If not - provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). - mode - Attribute. - Supported modes: ``constant``\ (default), ``reflect``, ``edge`` - - Returns - ======= - output : Var - Type T. - Tensor after padding. - - Notes - ===== - Signature: ``ai.onnx@18::Pad``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` +Given a tensor containing the data to be padded (``data``), a tensor +containing the number of start and end pad values for axis (``pads``), +(optionally) a ``mode``, and (optionally) ``constant_value``, a padded +tensor (``output``) is generated. + +The three supported ``modes`` are (similar to corresponding modes +supported by ``numpy.pad``): + +1) ``constant``\ (default) - pads with a given constant value as + specified by ``constant_value`` (which defaults to 0, empty string, + or False) + +2) ``reflect`` - pads with the reflection of the vector mirrored on the + first and last values of the vector along each axis + +3) ``edge`` - pads with the edge values of array + +Example 1 (``constant`` mode): + +Insert 0 pads to the beginning of the second dimension. + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + +Example 2 (``reflect`` mode): + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] + +Example 3 (``edge`` mode): + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] + +Parameters +========== +data + Type T. + Input tensor. +pads + Type tensor(int64). + Tensor of integers indicating the number of padding elements to add or + remove (if negative) at the beginning and end of each axis. For 2D input + tensor, it is the number of pixels. ``pads`` should be a 1D tensor of + shape [2 \* num_axes] where ``num_axes`` refers to the number of + elements in the ``axes`` input or the input rank if ``axes`` are not + provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, + ..., x1_end, x2_end,...], where xi_begin is the number of pad values + added at the beginning of axis ``axes[i]`` and xi_end, the number of pad + values added at the end of axis ``axes[i]``. +constant_value + Type T. + (Optional) A scalar value to be used if the mode chosen is ``constant`` + (by default it is 0, empty string or False). +axes + Type Tind. + 1-D tensor of axes that ``pads`` apply to. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(data). Behavior is undefined if an axis is repeated. If not + provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). +mode + Attribute. + Supported modes: ``constant``\ (default), ``reflect``, ``edge`` + +Returns +======= +output : Var + Type T. + Tensor after padding. + +Notes +===== +Signature: ``ai.onnx@18::Pad``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return ( - _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), - _Pad.Inputs( - data=unwrap_vars(data), - pads=unwrap_vars(pads), - constant_value=unwrap_vars(constant_value), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), - ) - .output - ) - - -def reduce_l1( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), _Pad.Inputs( + data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), pads=get_value(pads), constant_value=get_value(constant_value), axes=get_value(axes), ).output + + +def reduce_l1(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the L1 norm of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields 0. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceL1``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` +Computes the L1 norm of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields 0. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceL1``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return ( - _ReduceL1( - _ReduceL1.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceL1.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_l2( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceL1( + _ReduceL1.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceL1.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_l2(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the L2 norm of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields 0. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceL2``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` +Computes the L2 norm of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields 0. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceL2``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return ( - _ReduceL2( - _ReduceL2.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceL2.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_log_sum( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceL2( + _ReduceL2.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceL2.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_log_sum(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the log sum of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields minus infinity (if - supported by the datatype) or undefined otherwise. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceLogSum``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` +Computes the log sum of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields minus infinity (if +supported by the datatype) or undefined otherwise. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceLogSum``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return ( - _ReduceLogSum( - _ReduceLogSum.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceLogSum.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_log_sum_exp( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceLogSum( + _ReduceLogSum.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceLogSum.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_log_sum_exp(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the log sum exponent of the input tensor's elements along the - provided axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields minus infinity (if - supported by the datatype) or undefined otherwise. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceLogSumExp``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` +Computes the log sum exponent of the input tensor's elements along the +provided axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields minus infinity (if +supported by the datatype) or undefined otherwise. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceLogSumExp``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return ( - _ReduceLogSumExp( - _ReduceLogSumExp.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceLogSumExp.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_max( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceLogSumExp( + _ReduceLogSumExp.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceLogSumExp.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_max(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the max of the input tensor's elements along the provided axes. - The resulting tensor has the same rank as the input if ``keepdims`` - equals 1. If ``keepdims`` equals 0, then the resulting tensor has the - reduced dimension pruned. Input tensors of rank zero are valid. - Reduction over an empty set of values yields minus infinity (if - supported by the datatype) or the minimum value of the data type - otherwise. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceMax``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Computes the max of the input tensor's elements along the provided axes. +The resulting tensor has the same rank as the input if ``keepdims`` +equals 1. If ``keepdims`` equals 0, then the resulting tensor has the +reduced dimension pruned. Input tensors of rank zero are valid. +Reduction over an empty set of values yields minus infinity (if +supported by the datatype) or the minimum value of the data type +otherwise. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceMax``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _ReduceMax( - _ReduceMax.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceMax.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_mean( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceMax( + _ReduceMax.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceMax.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_mean(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the mean of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields undefined. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceMean``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` +Computes the mean of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields undefined. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceMean``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return ( - _ReduceMean( - _ReduceMean.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceMean.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_min( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceMean( + _ReduceMean.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceMean.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_min(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the min of the input tensor's elements along the provided axes. - The resulting tensor has the same rank as the input if ``keepdims`` - equals 1. If ``keepdims`` equals 0, then the resulting tensor has the - reduced dimension pruned. Input tensors of rank zero are valid. - Reduction over an empty set of values yields plus infinity (if supported - by the datatype) or the maximum value of the data type otherwise. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceMin``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Computes the min of the input tensor's elements along the provided axes. +The resulting tensor has the same rank as the input if ``keepdims`` +equals 1. If ``keepdims`` equals 0, then the resulting tensor has the +reduced dimension pruned. Input tensors of rank zero are valid. +Reduction over an empty set of values yields plus infinity (if supported +by the datatype) or the maximum value of the data type otherwise. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceMin``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _ReduceMin( - _ReduceMin.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceMin.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_prod( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceMin( + _ReduceMin.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceMin.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_prod(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the product of the input tensor's elements along the provided - axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields 1. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceProd``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` +Computes the product of the input tensor's elements along the provided +axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields 1. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceProd``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return ( - _ReduceProd( - _ReduceProd.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceProd.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_sum_square( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceProd( + _ReduceProd.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceProd.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_sum_square(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the sum square of the input tensor's elements along the - provided axes. The resulting tensor has the same rank as the input if - ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting - tensor has the reduced dimension pruned. Input tensors of rank zero are - valid. Reduction over an empty set of values yields 0. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@18::ReduceSumSquare``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` +Computes the sum square of the input tensor's elements along the +provided axes. The resulting tensor has the same rank as the input if +``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting +tensor has the reduced dimension pruned. Input tensors of rank zero are +valid. Reduction over an empty set of values yields 0. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@18::ReduceSumSquare``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return ( - _ReduceSumSquare( - _ReduceSumSquare.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceSumSquare.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def resize( - X: Var, - roi: Optional[Var] = None, - scales: Optional[Var] = None, - sizes: Optional[Var] = None, - *, - antialias: int = 0, - axes: Optional[Iterable[int]] = None, - coordinate_transformation_mode: str = "half_pixel", - cubic_coeff_a: float = -0.75, - exclude_outside: int = 0, - extrapolation_value: float = 0.0, - keep_aspect_ratio_policy: str = "stretch", - mode: str = "nearest", - nearest_mode: str = "round_prefer_floor", -) -> Var: + return _ReduceSumSquare( + _ReduceSumSquare.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceSumSquare.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def resize(X: Var, roi: Optional[Var] = None, scales: Optional[Var] = None, sizes: Optional[Var] = None, *, antialias: int = 0, axes: Optional[Iterable[int]] = None, coordinate_transformation_mode: str = "half_pixel", cubic_coeff_a: float = -0.75, exclude_outside: int = 0, extrapolation_value: float = 0.0, keep_aspect_ratio_policy: str = "stretch", mode: str = "nearest", nearest_mode: str = "round_prefer_floor", ) -> Var: r""" - Resize the input tensor. In general, it calculates every value in the - output tensor as a weighted average of neighborhood (a.k.a. sampling - locations) in the input tensor. Each dimension value of the output - tensor is: - ``output_dimension = floor(input_dimension * (roi_end - roi_start) * scale)`` - if input "sizes" is not specified. - - Parameters - ========== - X - Type T1. - N-D tensor - roi - Type T2. - 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is - the rank of X or the length of axes, if provided. The RoIs' coordinates - are normalized in the coordinate system of the input image. It only - takes effect when coordinate_transformation_mode is "tf_crop_and_resize" - scales - Type tensor(float). - The scale array along each dimension. It takes value greater than 0. If - it's less than 1, it's sampling down, otherwise, it's upsampling. The - number of elements of 'scales' should be the same as the rank of input - 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' - MUST be specified and it is an error if both are specified. If 'sizes' - is needed, the user can use an empty string as the name of 'scales' in - this operator's input list. - sizes - Type tensor(int64). - Target size of the output tensor. Its interpretation depends on the - 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' - should be the same as the rank of input 'X', or the length of 'axes', if - provided. Only one of 'scales' and 'sizes' can be specified. - antialias - Attribute. - If set to 1, "linear" and "cubic" interpolation modes will use an - antialiasing filter when downscaling. Antialiasing is achieved by - stretching the resampling filter by a factor max(1, 1 / scale), which - means that when downsampling, more input pixels contribute to an output - pixel. - axes - Attribute. - If provided, it specifies a subset of axes that 'roi', 'scales' and - 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., - r-1], where r = rank(data). Non-specified dimensions are interpreted as - non-resizable. Negative value means counting dimensions from the back. - Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined - if an axis is repeated. - coordinate_transformation_mode - Attribute. - This attribute describes how to transform the coordinate in the resized - tensor to the coordinate in the original tensor. - - The coordinate of each dimension is transformed individually. Let's - describe a case using axis x as an example. Denote x_resized as the - coordinate of axis x in the resized tensor, x_original as the coordinate - of axis x in the original tensor, ``length_original`` as the length of - the original tensor in axis x, length_resized as the length of the - resized tensor in axis x, roi_x = (start_x, end_x) of the axis x in - input "roi", ``scale = length_resized / length_original``, - - if coordinate_transformation_mode is ``"half_pixel"``, - ``x_original = (x_resized + 0.5) / scale - 0.5`` - - if coordinate_transformation_mode is ``"pytorch_half_pixel"``, - ``x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0`` - - if coordinate_transformation_mode is ``"align_corners"``, - ``x_original = x_resized * (length_original - 1) / (length_resized - 1)`` - - if coordinate_transformation_mode is ``"asymmetric"``, - ``x_original = x_resized / scale`` - - if coordinate_transformation_mode is ``"tf_crop_and_resize"``, - ``x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1)`` - . - cubic_coeff_a - Attribute. - The coefficient 'a' used in cubic interpolation. Two common choice are - -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out - Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the - details. This attribute is valid only if mode is "cubic". - exclude_outside - Attribute. - If set to 1, the weight of sampling locations outside the tensor will be - set to 0 and the weight will be renormalized so that their sum is 1.0. - The default value is 0. - extrapolation_value - Attribute. - When coordinate_transformation_mode is "tf_crop_and_resize" and - x_original is outside the range [0, length_original - 1], this value is - used as the corresponding output value. Default is 0.0f. - keep_aspect_ratio_policy - Attribute. - This attribute describes how to interpret the ``sizes`` input with - regard to keeping the original aspect ratio of the input, and it is not - applicable when the ``scales`` input is used. - - Given a set of ``sizes``, associated with a subset of ``axes`` - (explicitly provided or default), and assuming ``d = axes[i]``, with - ``i`` being the index of the provided ``sizes``. - - If ``keep_aspect_ratio_policy`` is ``"stretch"``, the original aspect - ratio is disregarded, and the input is resized to the specified size: - ``out_size[d] = sizes[i]`` - - If ``keep_aspect_ratio_policy`` is ``"not_larger"``, the sizes are - adjusted so that no extent of the output is larger than the specified - size, while keeping the original aspect ratio: - ``scale = Min(sizes[i] / in_size[d])`` - ``out_size[d] = round_int(scale * in_size[i])`` - - If ``keep_aspect_ratio_policy`` is ``"not_smaller"``, the sizes are - adjusted so that no extent of the output is smaller than the specified - size, while keeping the original aspect ratio: - ``scale = Max(sizes[i] / in_size[d])`` - ``out_size[d] = round_int(scale * in_size[i])`` - - For non-resizable axes (those not specified in ``axes``), the output - size will be equal to the input size. - - Note: ``round_int`` stands for computing the nearest integer value, - rounding halfway cases up. - mode - Attribute. - Three interpolation modes: "nearest" (default), "linear" and "cubic". - The "linear" mode includes linear interpolation for 1D tensor and - N-linear interpolation for N-D tensor (for example, bilinear - interpolation for 2D tensor). The "cubic" mode includes cubic - interpolation for 1D tensor and N-cubic interpolation for N-D tensor - (for example, bicubic interpolation for 2D tensor). - nearest_mode - Attribute. - Four modes: "round_prefer_floor" (default, as known as round half down), - "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only - used by nearest interpolation. It indicates how to get "nearest" pixel - in input tensor from x_original, so this attribute is valid only if - "mode" is "nearest". - - Returns - ======= - Y : Var - Type T1. - N-D tensor after resizing - - Notes - ===== - Signature: ``ai.onnx@18::Resize``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Resize the input tensor. In general, it calculates every value in the +output tensor as a weighted average of neighborhood (a.k.a. sampling +locations) in the input tensor. Each dimension value of the output +tensor is: +``output_dimension = floor(input_dimension * (roi_end - roi_start) * scale)`` +if input "sizes" is not specified. + +Parameters +========== +X + Type T1. + N-D tensor +roi + Type T2. + 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is + the rank of X or the length of axes, if provided. The RoIs' coordinates + are normalized in the coordinate system of the input image. It only + takes effect when coordinate_transformation_mode is "tf_crop_and_resize" +scales + Type tensor(float). + The scale array along each dimension. It takes value greater than 0. If + it's less than 1, it's sampling down, otherwise, it's upsampling. The + number of elements of 'scales' should be the same as the rank of input + 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' + MUST be specified and it is an error if both are specified. If 'sizes' + is needed, the user can use an empty string as the name of 'scales' in + this operator's input list. +sizes + Type tensor(int64). + Target size of the output tensor. Its interpretation depends on the + 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' + should be the same as the rank of input 'X', or the length of 'axes', if + provided. Only one of 'scales' and 'sizes' can be specified. +antialias + Attribute. + If set to 1, "linear" and "cubic" interpolation modes will use an + antialiasing filter when downscaling. Antialiasing is achieved by + stretching the resampling filter by a factor max(1, 1 / scale), which + means that when downsampling, more input pixels contribute to an output + pixel. +axes + Attribute. + If provided, it specifies a subset of axes that 'roi', 'scales' and + 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., + r-1], where r = rank(data). Non-specified dimensions are interpreted as + non-resizable. Negative value means counting dimensions from the back. + Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined + if an axis is repeated. +coordinate_transformation_mode + Attribute. + This attribute describes how to transform the coordinate in the resized + tensor to the coordinate in the original tensor. + + The coordinate of each dimension is transformed individually. Let's + describe a case using axis x as an example. Denote x_resized as the + coordinate of axis x in the resized tensor, x_original as the coordinate + of axis x in the original tensor, ``length_original`` as the length of + the original tensor in axis x, length_resized as the length of the + resized tensor in axis x, roi_x = (start_x, end_x) of the axis x in + input "roi", ``scale = length_resized / length_original``, + + if coordinate_transformation_mode is ``"half_pixel"``, + ``x_original = (x_resized + 0.5) / scale - 0.5`` + + if coordinate_transformation_mode is ``"pytorch_half_pixel"``, + ``x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0`` + + if coordinate_transformation_mode is ``"align_corners"``, + ``x_original = x_resized * (length_original - 1) / (length_resized - 1)`` + + if coordinate_transformation_mode is ``"asymmetric"``, + ``x_original = x_resized / scale`` + + if coordinate_transformation_mode is ``"tf_crop_and_resize"``, + ``x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1)`` + . +cubic_coeff_a + Attribute. + The coefficient 'a' used in cubic interpolation. Two common choice are + -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out + Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the + details. This attribute is valid only if mode is "cubic". +exclude_outside + Attribute. + If set to 1, the weight of sampling locations outside the tensor will be + set to 0 and the weight will be renormalized so that their sum is 1.0. + The default value is 0. +extrapolation_value + Attribute. + When coordinate_transformation_mode is "tf_crop_and_resize" and + x_original is outside the range [0, length_original - 1], this value is + used as the corresponding output value. Default is 0.0f. +keep_aspect_ratio_policy + Attribute. + This attribute describes how to interpret the ``sizes`` input with + regard to keeping the original aspect ratio of the input, and it is not + applicable when the ``scales`` input is used. + + Given a set of ``sizes``, associated with a subset of ``axes`` + (explicitly provided or default), and assuming ``d = axes[i]``, with + ``i`` being the index of the provided ``sizes``. + + If ``keep_aspect_ratio_policy`` is ``"stretch"``, the original aspect + ratio is disregarded, and the input is resized to the specified size: + ``out_size[d] = sizes[i]`` + + If ``keep_aspect_ratio_policy`` is ``"not_larger"``, the sizes are + adjusted so that no extent of the output is larger than the specified + size, while keeping the original aspect ratio: + ``scale = Min(sizes[i] / in_size[d])`` + ``out_size[d] = round_int(scale * in_size[i])`` + + If ``keep_aspect_ratio_policy`` is ``"not_smaller"``, the sizes are + adjusted so that no extent of the output is smaller than the specified + size, while keeping the original aspect ratio: + ``scale = Max(sizes[i] / in_size[d])`` + ``out_size[d] = round_int(scale * in_size[i])`` + + For non-resizable axes (those not specified in ``axes``), the output + size will be equal to the input size. + + Note: ``round_int`` stands for computing the nearest integer value, + rounding halfway cases up. +mode + Attribute. + Three interpolation modes: "nearest" (default), "linear" and "cubic". + The "linear" mode includes linear interpolation for 1D tensor and + N-linear interpolation for N-D tensor (for example, bilinear + interpolation for 2D tensor). The "cubic" mode includes cubic + interpolation for 1D tensor and N-cubic interpolation for N-D tensor + (for example, bicubic interpolation for 2D tensor). +nearest_mode + Attribute. + Four modes: "round_prefer_floor" (default, as known as round half down), + "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only + used by nearest interpolation. It indicates how to get "nearest" pixel + in input tensor from x_original, so this attribute is valid only if + "mode" is "nearest". + +Returns +======= +Y : Var + Type T1. + N-D tensor after resizing + +Notes +===== +Signature: ``ai.onnx@18::Resize``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _Resize( - _Resize.Attributes( - antialias=AttrInt64(antialias, name="antialias"), - axes=AttrInt64s.maybe(axes, name="axes"), - coordinate_transformation_mode=AttrString( - coordinate_transformation_mode, - name="coordinate_transformation_mode", - ), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32( - extrapolation_value, name="extrapolation_value" - ), - keep_aspect_ratio_policy=AttrString( - keep_aspect_ratio_policy, name="keep_aspect_ratio_policy" - ), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), - _Resize.Inputs( - X=unwrap_vars(X), - roi=unwrap_vars(roi), - scales=unwrap_vars(scales), - sizes=unwrap_vars(sizes), - ), - ) - .get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), - ) - .Y - ) - - -def scatter_elements( - data: Var, - indices: Var, - updates: Var, - *, - axis: int = 0, - reduction: str = "none", -) -> Var: + return _Resize( + _Resize.Attributes( + antialias=AttrInt64(antialias, name="antialias"), + axes=AttrInt64s.maybe(axes, name="axes"), + coordinate_transformation_mode=AttrString(coordinate_transformation_mode, name="coordinate_transformation_mode"), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32(extrapolation_value, name="extrapolation_value"), + keep_aspect_ratio_policy=AttrString(keep_aspect_ratio_policy, name="keep_aspect_ratio_policy"), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), + ), _Resize.Inputs( + X=unwrap_vars(X), roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), ).get_output_vars( + X=get_value(X), roi=get_value(roi), scales=get_value(scales), sizes=get_value(sizes), ).Y + + +def scatter_elements(data: Var, indices: Var, updates: Var, *, axis: int = 0, reduction: str = "none", ) -> Var: r""" - ScatterElements takes three inputs ``data``, ``updates``, and - ``indices`` of the same rank r >= 1 and an optional attribute axis that - identifies an axis of ``data`` (by default, the outer-most axis, that is - axis 0). The output of the operation is produced by creating a copy of - the input ``data``, and then updating its value to values specified by - ``updates`` at specific index positions specified by ``indices``. Its - output shape is the same as the shape of ``data``. - - For each entry in ``updates``, the target index in ``data`` is obtained - by combining the corresponding entry in ``indices`` with the index of - the entry itself: the index-value for dimension = axis is obtained from - the value of the corresponding entry in ``indices`` and the index-value - for dimension != axis is obtained from the index of the entry itself. - - ``reduction`` allows specification of an optional reduction operation, - which is applied to all values in ``updates`` tensor into ``output`` at - the specified ``indices``. In cases where ``reduction`` is set to - "none", indices should not have duplicate entries: that is, if idx1 != - idx2, then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor - case, the update corresponding to the [i][j] entry is performed as - below: - - :: - - output[indices[i][j]][j] = updates[i][j] if axis = 0, - output[i][indices[i][j]] = updates[i][j] if axis = 1, - - When ``reduction`` is set to some reduction function ``f``, the update - corresponding to the [i][j] entry is performed as below: - - :: - - output[indices[i][j]][j] = f(output[indices[i][j]][j], updates[i][j]) if axis = 0, - output[i][indices[i][j]] = f(output[i][indices[i][j]], updates[i][j]) if axis = 1, - - where the ``f`` is ``+``, ``*``, ``max`` or ``min`` as specified. - - This operator is the inverse of GatherElements. It is similar to Torch's - Scatter operation. - - (Opset 18 change): Adds max/min to the set of allowed reduction ops. - - Example 1: - - :: - - data = [ - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - ] - indices = [ - [1, 0, 2], - [0, 2, 1], - ] - updates = [ - [1.0, 1.1, 1.2], - [2.0, 2.1, 2.2], - ] - output = [ - [2.0, 1.1, 0.0] - [1.0, 0.0, 2.2] - [0.0, 2.1, 1.2] - ] - - Example 2: - - :: - - data = [[1.0, 2.0, 3.0, 4.0, 5.0]] - indices = [[1, 3]] - updates = [[1.1, 2.1]] - axis = 1 - output = [[1.0, 1.1, 3.0, 2.1, 5.0]] - - Parameters - ========== - data - Type T. - Tensor of rank r >= 1. - indices - Type Tind. - Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index - values are expected to be within bounds [-s, s-1] along axis of size s. - It is an error if any of the index values are out of bounds. - updates - Type T. - Tensor of rank r >=1 (same rank and shape as indices) - axis - Attribute. - Which axis to scatter on. Negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(data). - reduction - Attribute. - Type of reduction to apply: none (default), add, mul, max, min. 'none': - no reduction applied. 'add': reduction using the addition operation. - 'mul': reduction using the multiplication operation.'max': reduction - using the maximum operation.'min': reduction using the minimum - operation. - - Returns - ======= - output : Var - Type T. - Tensor of rank r >= 1 (same rank as input). - - Notes - ===== - Signature: ``ai.onnx@18::ScatterElements``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` +ScatterElements takes three inputs ``data``, ``updates``, and +``indices`` of the same rank r >= 1 and an optional attribute axis that +identifies an axis of ``data`` (by default, the outer-most axis, that is +axis 0). The output of the operation is produced by creating a copy of +the input ``data``, and then updating its value to values specified by +``updates`` at specific index positions specified by ``indices``. Its +output shape is the same as the shape of ``data``. + +For each entry in ``updates``, the target index in ``data`` is obtained +by combining the corresponding entry in ``indices`` with the index of +the entry itself: the index-value for dimension = axis is obtained from +the value of the corresponding entry in ``indices`` and the index-value +for dimension != axis is obtained from the index of the entry itself. + +``reduction`` allows specification of an optional reduction operation, +which is applied to all values in ``updates`` tensor into ``output`` at +the specified ``indices``. In cases where ``reduction`` is set to +"none", indices should not have duplicate entries: that is, if idx1 != +idx2, then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor +case, the update corresponding to the [i][j] entry is performed as +below: + +:: + + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + +When ``reduction`` is set to some reduction function ``f``, the update +corresponding to the [i][j] entry is performed as below: + +:: + + output[indices[i][j]][j] = f(output[indices[i][j]][j], updates[i][j]) if axis = 0, + output[i][indices[i][j]] = f(output[i][indices[i][j]], updates[i][j]) if axis = 1, + +where the ``f`` is ``+``, ``*``, ``max`` or ``min`` as specified. + +This operator is the inverse of GatherElements. It is similar to Torch's +Scatter operation. + +(Opset 18 change): Adds max/min to the set of allowed reduction ops. + +Example 1: + +:: + + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + +Example 2: + +:: + + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + +Parameters +========== +data + Type T. + Tensor of rank r >= 1. +indices + Type Tind. + Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index + values are expected to be within bounds [-s, s-1] along axis of size s. + It is an error if any of the index values are out of bounds. +updates + Type T. + Tensor of rank r >=1 (same rank and shape as indices) +axis + Attribute. + Which axis to scatter on. Negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(data). +reduction + Attribute. + Type of reduction to apply: none (default), add, mul, max, min. 'none': + no reduction applied. 'add': reduction using the addition operation. + 'mul': reduction using the multiplication operation.'max': reduction + using the maximum operation.'min': reduction using the minimum + operation. + +Returns +======= +output : Var + Type T. + Tensor of rank r >= 1 (same rank as input). + +Notes +===== +Signature: ``ai.onnx@18::ScatterElements``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return ( - _ScatterElements( - _ScatterElements.Attributes( - axis=AttrInt64(axis, name="axis"), - reduction=AttrString(reduction, name="reduction"), - ), - _ScatterElements.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - updates=unwrap_vars(updates), - ), - ) - .get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), - ) - .output - ) - - -def scatter_nd( - data: Var, - indices: Var, - updates: Var, - *, - reduction: str = "none", -) -> Var: + return _ScatterElements( + _ScatterElements.Attributes( + axis=AttrInt64(axis, name="axis"), + reduction=AttrString(reduction, name="reduction"), + ), _ScatterElements.Inputs( + data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), ).get_output_vars( + data=get_value(data), indices=get_value(indices), updates=get_value(updates), ).output + + +def scatter_nd(data: Var, indices: Var, updates: Var, *, reduction: str = "none", ) -> Var: r""" - ScatterND takes three inputs ``data`` tensor of rank r >= 1, ``indices`` - tensor of rank q >= 1, and ``updates`` tensor of rank q + r - - indices.shape[-1] - 1. The output of the operation is produced by - creating a copy of the input ``data``, and then updating its value to - values specified by ``updates`` at specific index positions specified by - ``indices``. Its output shape is the same as the shape of ``data``. - - ``indices`` is an integer tensor. Let k denote indices.shape[-1], the - last dimension in the shape of ``indices``. ``indices`` is treated as a - (q-1)-dimensional tensor of k-tuples, where each k-tuple is a - partial-index into ``data``. Hence, k can be a value at most the rank of - ``data``. When k equals rank(data), each update entry specifies an - update to a single element of the tensor. When k is less than rank(data) - each update entry specifies an update to a slice of the tensor. Index - values are allowed to be negative, as per the usual convention for - counting backwards from the end, but are expected in the valid range. - - ``updates`` is treated as a (q-1)-dimensional tensor of - replacement-slice-values. Thus, the first (q-1) dimensions of - updates.shape must match the first (q-1) dimensions of indices.shape. - The remaining dimensions of ``updates`` correspond to the dimensions of - the replacement-slice-values. Each replacement-slice-value is a (r-k) - dimensional tensor, corresponding to the trailing (r-k) dimensions of - ``data``. Thus, the shape of ``updates`` must equal indices.shape[0:q-1] - ++ data.shape[k:r-1], where ++ denotes the concatenation of shapes. - - The ``output`` is calculated via the following equation: - - :: - - output = np.copy(data) - update_indices = indices.shape[:-1] - for idx in np.ndindex(update_indices): - output[indices[idx]] = updates[idx] - - The order of iteration in the above loop is not specified. In - particular, indices should not have duplicate entries: that is, if idx1 - != idx2, then indices[idx1] != indices[idx2]. This ensures that the - output value does not depend on the iteration order. - - ``reduction`` allows specification of an optional reduction operation, - which is applied to all values in ``updates`` tensor into ``output`` at - the specified ``indices``. In cases where ``reduction`` is set to - "none", indices should not have duplicate entries: that is, if idx1 != - idx2, then indices[idx1] != indices[idx2]. This ensures that the output - value does not depend on the iteration order. When ``reduction`` is set - to some reduction function ``f``, ``output`` is calculated as follows: - - :: - - output = np.copy(data) - update_indices = indices.shape[:-1] - for idx in np.ndindex(update_indices): - output[indices[idx]] = f(output[indices[idx]], updates[idx]) - - where the ``f`` is ``+``, ``*``, ``max`` or ``min`` as specified. - - This operator is the inverse of GatherND. - - (Opset 18 change): Adds max/min to the set of allowed reduction ops. - - Example 1: - - :: - - data = [1, 2, 3, 4, 5, 6, 7, 8] - indices = [[4], [3], [1], [7]] - updates = [9, 10, 11, 12] - output = [1, 11, 3, 10, 9, 6, 7, 12] - - Example 2: - - :: - - data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] - indices = [[0], [2]] - updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], - [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] - output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], - [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] - - Parameters - ========== - data - Type T. - Tensor of rank r >= 1. - indices - Type tensor(int64). - Tensor of rank q >= 1. - updates - Type T. - Tensor of rank q + r - indices_shape[-1] - 1. - reduction - Attribute. - Type of reduction to apply: none (default), add, mul, max, min. 'none': - no reduction applied. 'add': reduction using the addition operation. - 'mul': reduction using the addition operation. 'max': reduction using - the maximum operation.'min': reduction using the minimum operation. - - Returns - ======= - output : Var - Type T. - Tensor of rank r >= 1. - - Notes - ===== - Signature: ``ai.onnx@18::ScatterND``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +ScatterND takes three inputs ``data`` tensor of rank r >= 1, ``indices`` +tensor of rank q >= 1, and ``updates`` tensor of rank q + r - +indices.shape[-1] - 1. The output of the operation is produced by +creating a copy of the input ``data``, and then updating its value to +values specified by ``updates`` at specific index positions specified by +``indices``. Its output shape is the same as the shape of ``data``. + +``indices`` is an integer tensor. Let k denote indices.shape[-1], the +last dimension in the shape of ``indices``. ``indices`` is treated as a +(q-1)-dimensional tensor of k-tuples, where each k-tuple is a +partial-index into ``data``. Hence, k can be a value at most the rank of +``data``. When k equals rank(data), each update entry specifies an +update to a single element of the tensor. When k is less than rank(data) +each update entry specifies an update to a slice of the tensor. Index +values are allowed to be negative, as per the usual convention for +counting backwards from the end, but are expected in the valid range. + +``updates`` is treated as a (q-1)-dimensional tensor of +replacement-slice-values. Thus, the first (q-1) dimensions of +updates.shape must match the first (q-1) dimensions of indices.shape. +The remaining dimensions of ``updates`` correspond to the dimensions of +the replacement-slice-values. Each replacement-slice-value is a (r-k) +dimensional tensor, corresponding to the trailing (r-k) dimensions of +``data``. Thus, the shape of ``updates`` must equal indices.shape[0:q-1] +++ data.shape[k:r-1], where ++ denotes the concatenation of shapes. + +The ``output`` is calculated via the following equation: + +:: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] = updates[idx] + +The order of iteration in the above loop is not specified. In +particular, indices should not have duplicate entries: that is, if idx1 +!= idx2, then indices[idx1] != indices[idx2]. This ensures that the +output value does not depend on the iteration order. + +``reduction`` allows specification of an optional reduction operation, +which is applied to all values in ``updates`` tensor into ``output`` at +the specified ``indices``. In cases where ``reduction`` is set to +"none", indices should not have duplicate entries: that is, if idx1 != +idx2, then indices[idx1] != indices[idx2]. This ensures that the output +value does not depend on the iteration order. When ``reduction`` is set +to some reduction function ``f``, ``output`` is calculated as follows: + +:: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] = f(output[indices[idx]], updates[idx]) + +where the ``f`` is ``+``, ``*``, ``max`` or ``min`` as specified. + +This operator is the inverse of GatherND. + +(Opset 18 change): Adds max/min to the set of allowed reduction ops. + +Example 1: + +:: + + data = [1, 2, 3, 4, 5, 6, 7, 8] + indices = [[4], [3], [1], [7]] + updates = [9, 10, 11, 12] + output = [1, 11, 3, 10, 9, 6, 7, 12] + +Example 2: + +:: + + data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + indices = [[0], [2]] + updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] + output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + +Parameters +========== +data + Type T. + Tensor of rank r >= 1. +indices + Type tensor(int64). + Tensor of rank q >= 1. +updates + Type T. + Tensor of rank q + r - indices_shape[-1] - 1. +reduction + Attribute. + Type of reduction to apply: none (default), add, mul, max, min. 'none': + no reduction applied. 'add': reduction using the addition operation. + 'mul': reduction using the addition operation. 'max': reduction using + the maximum operation.'min': reduction using the minimum operation. + +Returns +======= +output : Var + Type T. + Tensor of rank r >= 1. + +Notes +===== +Signature: ``ai.onnx@18::ScatterND``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _ScatterND( - _ScatterND.Attributes( - reduction=AttrString(reduction, name="reduction"), - ), - _ScatterND.Inputs( - data=unwrap_vars(data), - indices=unwrap_vars(indices), - updates=unwrap_vars(updates), - ), - ) - .get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), - ) - .output - ) - - -def split( - input: Var, - split: Optional[Var] = None, - *, - axis: int = 0, - num_outputs: Optional[int] = None, -) -> Sequence[Var]: + return _ScatterND( + _ScatterND.Attributes( + reduction=AttrString(reduction, name="reduction"), + ), _ScatterND.Inputs( + data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), ).get_output_vars( + data=get_value(data), indices=get_value(indices), updates=get_value(updates), ).output + + +def split(input: Var, split: Optional[Var] = None, *, axis: int = 0, num_outputs: Optional[int] = None, ) -> Sequence[Var]: r""" - Split a tensor into a list of tensors, along the specified 'axis'. - Either input 'split' or the attribute 'num_outputs' should be specified, - but not both. If the attribute 'num_outputs' is specified, then the - tensor is split into equal sized parts. If the tensor is not evenly - splittable into ``num_outputs``, the last chunk will be smaller. If the - input 'split' is specified, it indicates the sizes of each output in the - split. - - Parameters - ========== - input - Type T. - The tensor to split - split - Type tensor(int64). - Optional length of each output. Values should be >= 0.Sum of the values - must be equal to the dim value at 'axis' specified. - axis - Attribute. - Which axis to split on. A negative value means counting dimensions from - the back. Accepted range is [-rank, rank-1] where r = rank(input). - num_outputs - Attribute. - Number of outputs to split parts of the tensor into. If the tensor is - not evenly splittable the last chunk will be smaller. - - Returns - ======= - outputs : Sequence[Var] - Type T. - One or more outputs forming list of tensors after splitting - - Notes - ===== - Signature: ``ai.onnx@18::Split``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Split a tensor into a list of tensors, along the specified 'axis'. +Either input 'split' or the attribute 'num_outputs' should be specified, +but not both. If the attribute 'num_outputs' is specified, then the +tensor is split into equal sized parts. If the tensor is not evenly +splittable into ``num_outputs``, the last chunk will be smaller. If the +input 'split' is specified, it indicates the sizes of each output in the +split. + +Parameters +========== +input + Type T. + The tensor to split +split + Type tensor(int64). + Optional length of each output. Values should be >= 0.Sum of the values + must be equal to the dim value at 'axis' specified. +axis + Attribute. + Which axis to split on. A negative value means counting dimensions from + the back. Accepted range is [-rank, rank-1] where r = rank(input). +num_outputs + Attribute. + Number of outputs to split parts of the tensor into. If the tensor is + not evenly splittable the last chunk will be smaller. + +Returns +======= +outputs : Sequence[Var] + Type T. + One or more outputs forming list of tensors after splitting + +Notes +===== +Signature: ``ai.onnx@18::Split``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Split( - _Split.Attributes( - axis=AttrInt64(axis, name="axis"), - num_outputs=AttrInt64.maybe(num_outputs, name="num_outputs"), - ), - _Split.Inputs( - input=unwrap_vars(input), - split=unwrap_vars(split), - ), - out_variadic=num_outputs, - ) - .get_output_vars( - input=get_value(input), - split=get_value(split), - ) - .outputs - ) + return _Split( + _Split.Attributes( + axis=AttrInt64(axis, name="axis"), + num_outputs=AttrInt64.maybe(num_outputs, name="num_outputs"), + ), _Split.Inputs( + input=unwrap_vars(input), split=unwrap_vars(split), ), out_variadic=num_outputs, ).get_output_vars( + input=get_value(input), split=get_value(split), ).outputs def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -3381,4 +2791,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 8fc23f65..c8119fd7 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -1,18 +1,21 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: BSD-3-Clause - # ruff: noqa: E741 -- Allow ambiguous variable name -from collections.abc import Iterable, Sequence +import typing +import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( + Any, Callable, Optional, + Union, ) from typing import cast as typing_cast import numpy as np import numpy.typing as npt +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, AttrFloat32, @@ -23,354 +26,184 @@ AttrString, AttrStrings, AttrTensor, + AttrType, ) -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._graph import Graph, subgraph +from spox._internal_op import intro from spox._node import OpType -from spox._standard import StandardNode -from spox._type_system import Tensor, Type +from spox._standard import InferenceError, StandardNode +from spox._type_system import Tensor, Type, Sequence as SpoxSequence from spox._value_prop import PropValueType -from spox._var import Var, VarInfo, get_value, unwrap_vars -from spox.opset.ai.onnx.v18 import ( - _DFT, - _GRU, - _LRN, - _LSTM, - _RNN, - _STFT, - _Abs, - _Acos, - _Acosh, - _Add, - _And, - _ArgMax, - _ArgMin, - _Asin, - _Asinh, - _Atan, - _Atanh, - _BatchNormalization, - _Bernoulli, - _BitShift, - _BitwiseAnd, - _BitwiseNot, - _BitwiseOr, - _BitwiseXor, - _BlackmanWindow, - _Ceil, - _Celu, - _CenterCropPad, - _Clip, - _Col2Im, - _Compress, - _Concat, - _ConcatFromSequence, - _ConstantOfShape, - _Conv, - _ConvInteger, - _ConvTranspose, - _Cos, - _Cosh, - _CumSum, - _DepthToSpace, - _Det, - _Div, - _Dropout, - _DynamicQuantizeLinear, - _Einsum, - _Elu, - _Erf, - _Exp, - _Expand, - _EyeLike, - _Flatten, - _Floor, - _Gather, - _GatherElements, - _GatherND, - _Gemm, - _GlobalAveragePool, - _GlobalLpPool, - _GlobalMaxPool, - _Greater, - _GreaterOrEqual, - _GridSample, - _GroupNormalization, - _HammingWindow, - _HannWindow, - _Hardmax, - _HardSigmoid, - _HardSwish, - _InstanceNormalization, - _IsInf, - _IsNaN, - _LayerNormalization, - _LeakyRelu, - _Less, - _LessOrEqual, - _Log, - _LogSoftmax, - _LpNormalization, - _LpPool, - _MatMul, - _MatMulInteger, - _Max, - _MaxPool, - _MaxRoiPool, - _MaxUnpool, - _Mean, - _MeanVarianceNormalization, - _MelWeightMatrix, - _Min, - _Mish, - _Mod, - _Mul, - _Multinomial, - _Neg, - _NegativeLogLikelihoodLoss, - _NonMaxSuppression, - _NonZero, - _Not, - _OneHot, - _Optional, - _OptionalGetElement, - _OptionalHasElement, - _Or, - _Pow, - _PRelu, - _QLinearConv, - _QLinearMatMul, - _RandomNormal, - _RandomNormalLike, - _RandomUniform, - _RandomUniformLike, - _Range, - _Reciprocal, - _ReduceL1, - _ReduceL2, - _ReduceLogSum, - _ReduceLogSumExp, - _ReduceMax, - _ReduceMean, - _ReduceMin, - _ReduceProd, - _ReduceSum, - _ReduceSumSquare, - _Relu, - _ReverseSequence, - _RoiAlign, - _Round, - _ScatterElements, - _ScatterND, - _Selu, - _SequenceAt, - _SequenceConstruct, - _SequenceEmpty, - _SequenceErase, - _SequenceInsert, - _SequenceLength, - _SequenceMap, - _Shrink, - _Sigmoid, - _Sign, - _Sin, - _Sinh, - _Slice, - _Softmax, - _SoftmaxCrossEntropyLoss, - _Softplus, - _Softsign, - _SpaceToDepth, - _Split, - _SplitToSequence, - _Sqrt, - _Squeeze, - _StringNormalizer, - _Sub, - _Sum, - _Tan, - _Tanh, - _TfIdfVectorizer, - _ThresholdedRelu, - _Tile, - _TopK, - _Transpose, - _Trilu, - _Unique, - _Unsqueeze, - _Where, - _Xor, - abs, - acos, - acosh, - add, - and_, - arg_max, - arg_min, - asin, - asinh, - atan, - atanh, - batch_normalization, - bernoulli, - bit_shift, - bitwise_and, - bitwise_not, - bitwise_or, - bitwise_xor, - blackman_window, - ceil, - celu, - center_crop_pad, - clip, - col2_im, - compress, - concat, - concat_from_sequence, - constant_of_shape, - conv, - conv_integer, - conv_transpose, - cos, - cosh, - cumsum, - depth_to_space, - det, - dft, - div, - dropout, - dynamic_quantize_linear, - einsum, - elu, - erf, - exp, - expand, - eye_like, - flatten, - floor, - gather, - gather_elements, - gather_nd, - gemm, - global_average_pool, - global_lp_pool, - global_max_pool, - greater, - greater_or_equal, - grid_sample, - group_normalization, - gru, - hamming_window, - hann_window, - hard_sigmoid, - hard_swish, - hardmax, - instance_normalization, - isinf, - isnan, - layer_normalization, - leaky_relu, - less, - less_or_equal, - log, - log_softmax, - lp_normalization, - lp_pool, - lrn, - lstm, - matmul, - matmul_integer, - max, - max_pool, - max_roi_pool, - max_unpool, - mean, - mean_variance_normalization, - mel_weight_matrix, - min, - mish, - mod, - mul, - multinomial, - neg, - negative_log_likelihood_loss, - non_max_suppression, - non_zero, - not_, - one_hot, - optional, - optional_get_element, - optional_has_element, - or_, - pow, - prelu, - qlinear_conv, - qlinear_matmul, - random_normal, - random_normal_like, - random_uniform, - random_uniform_like, - range, - reciprocal, - reduce_l1, - reduce_l2, - reduce_log_sum, - reduce_log_sum_exp, - reduce_max, - reduce_mean, - reduce_min, - reduce_prod, - reduce_sum, - reduce_sum_square, - relu, - reverse_sequence, - rnn, - roi_align, - round, - scatter_elements, - scatter_nd, - selu, - sequence_at, - sequence_construct, - sequence_empty, - sequence_erase, - sequence_insert, - sequence_length, - sequence_map, - shrink, - sigmoid, - sign, - sin, - sinh, - slice, - softmax, - softmax_cross_entropy_loss, - softplus, - softsign, - space_to_depth, - split, - split_to_sequence, - sqrt, - squeeze, - stft, - string_normalizer, - sub, - sum, - tan, - tanh, - tf_idf_vectorizer, - thresholded_relu, - tile, - top_k, - transpose, - trilu, - unique, - unsqueeze, - where, - xor, -) +from spox.opset.ai.onnx.v18 import _Abs, abs +from spox.opset.ai.onnx.v18 import _Acos, acos +from spox.opset.ai.onnx.v18 import _Acosh, acosh +from spox.opset.ai.onnx.v18 import _Add, add +from spox.opset.ai.onnx.v18 import _And, and_ +from spox.opset.ai.onnx.v18 import _ArgMax, arg_max +from spox.opset.ai.onnx.v18 import _ArgMin, arg_min +from spox.opset.ai.onnx.v18 import _Asin, asin +from spox.opset.ai.onnx.v18 import _Asinh, asinh +from spox.opset.ai.onnx.v18 import _Atan, atan +from spox.opset.ai.onnx.v18 import _Atanh, atanh +from spox.opset.ai.onnx.v18 import _BatchNormalization, batch_normalization +from spox.opset.ai.onnx.v18 import _Bernoulli, bernoulli +from spox.opset.ai.onnx.v18 import _BitShift, bit_shift +from spox.opset.ai.onnx.v18 import _BitwiseAnd, bitwise_and +from spox.opset.ai.onnx.v18 import _BitwiseNot, bitwise_not +from spox.opset.ai.onnx.v18 import _BitwiseOr, bitwise_or +from spox.opset.ai.onnx.v18 import _BitwiseXor, bitwise_xor +from spox.opset.ai.onnx.v18 import _BlackmanWindow, blackman_window +from spox.opset.ai.onnx.v18 import _Ceil, ceil +from spox.opset.ai.onnx.v18 import _Celu, celu +from spox.opset.ai.onnx.v18 import _CenterCropPad, center_crop_pad +from spox.opset.ai.onnx.v18 import _Clip, clip +from spox.opset.ai.onnx.v18 import _Col2Im, col2_im +from spox.opset.ai.onnx.v18 import _Compress, compress +from spox.opset.ai.onnx.v18 import _Concat, concat +from spox.opset.ai.onnx.v18 import _ConcatFromSequence, concat_from_sequence +from spox.opset.ai.onnx.v18 import _ConstantOfShape, constant_of_shape +from spox.opset.ai.onnx.v18 import _Conv, conv +from spox.opset.ai.onnx.v18 import _ConvInteger, conv_integer +from spox.opset.ai.onnx.v18 import _ConvTranspose, conv_transpose +from spox.opset.ai.onnx.v18 import _Cos, cos +from spox.opset.ai.onnx.v18 import _Cosh, cosh +from spox.opset.ai.onnx.v18 import _CumSum, cumsum +from spox.opset.ai.onnx.v18 import _DFT, dft +from spox.opset.ai.onnx.v18 import _DepthToSpace, depth_to_space +from spox.opset.ai.onnx.v18 import _Det, det +from spox.opset.ai.onnx.v18 import _Div, div +from spox.opset.ai.onnx.v18 import _Dropout, dropout +from spox.opset.ai.onnx.v18 import _DynamicQuantizeLinear, dynamic_quantize_linear +from spox.opset.ai.onnx.v18 import _Einsum, einsum +from spox.opset.ai.onnx.v18 import _Elu, elu +from spox.opset.ai.onnx.v18 import _Erf, erf +from spox.opset.ai.onnx.v18 import _Exp, exp +from spox.opset.ai.onnx.v18 import _Expand, expand +from spox.opset.ai.onnx.v18 import _EyeLike, eye_like +from spox.opset.ai.onnx.v18 import _Flatten, flatten +from spox.opset.ai.onnx.v18 import _Floor, floor +from spox.opset.ai.onnx.v18 import _GRU, gru +from spox.opset.ai.onnx.v18 import _Gather, gather +from spox.opset.ai.onnx.v18 import _GatherElements, gather_elements +from spox.opset.ai.onnx.v18 import _GatherND, gather_nd +from spox.opset.ai.onnx.v18 import _Gemm, gemm +from spox.opset.ai.onnx.v18 import _GlobalAveragePool, global_average_pool +from spox.opset.ai.onnx.v18 import _GlobalLpPool, global_lp_pool +from spox.opset.ai.onnx.v18 import _GlobalMaxPool, global_max_pool +from spox.opset.ai.onnx.v18 import _Greater, greater +from spox.opset.ai.onnx.v18 import _GreaterOrEqual, greater_or_equal +from spox.opset.ai.onnx.v18 import _GridSample, grid_sample +from spox.opset.ai.onnx.v18 import _GroupNormalization, group_normalization +from spox.opset.ai.onnx.v18 import _HammingWindow, hamming_window +from spox.opset.ai.onnx.v18 import _HannWindow, hann_window +from spox.opset.ai.onnx.v18 import _HardSigmoid, hard_sigmoid +from spox.opset.ai.onnx.v18 import _HardSwish, hard_swish +from spox.opset.ai.onnx.v18 import _Hardmax, hardmax +from spox.opset.ai.onnx.v18 import _InstanceNormalization, instance_normalization +from spox.opset.ai.onnx.v18 import _IsInf, isinf +from spox.opset.ai.onnx.v18 import _IsNaN, isnan +from spox.opset.ai.onnx.v18 import _LRN, lrn +from spox.opset.ai.onnx.v18 import _LSTM, lstm +from spox.opset.ai.onnx.v18 import _LayerNormalization, layer_normalization +from spox.opset.ai.onnx.v18 import _LeakyRelu, leaky_relu +from spox.opset.ai.onnx.v18 import _Less, less +from spox.opset.ai.onnx.v18 import _LessOrEqual, less_or_equal +from spox.opset.ai.onnx.v18 import _Log, log +from spox.opset.ai.onnx.v18 import _LogSoftmax, log_softmax +from spox.opset.ai.onnx.v18 import _LpNormalization, lp_normalization +from spox.opset.ai.onnx.v18 import _LpPool, lp_pool +from spox.opset.ai.onnx.v18 import _MatMul, matmul +from spox.opset.ai.onnx.v18 import _MatMulInteger, matmul_integer +from spox.opset.ai.onnx.v18 import _Max, max +from spox.opset.ai.onnx.v18 import _MaxPool, max_pool +from spox.opset.ai.onnx.v18 import _MaxRoiPool, max_roi_pool +from spox.opset.ai.onnx.v18 import _MaxUnpool, max_unpool +from spox.opset.ai.onnx.v18 import _Mean, mean +from spox.opset.ai.onnx.v18 import _MeanVarianceNormalization, mean_variance_normalization +from spox.opset.ai.onnx.v18 import _MelWeightMatrix, mel_weight_matrix +from spox.opset.ai.onnx.v18 import _Min, min +from spox.opset.ai.onnx.v18 import _Mish, mish +from spox.opset.ai.onnx.v18 import _Mod, mod +from spox.opset.ai.onnx.v18 import _Mul, mul +from spox.opset.ai.onnx.v18 import _Multinomial, multinomial +from spox.opset.ai.onnx.v18 import _Neg, neg +from spox.opset.ai.onnx.v18 import _NegativeLogLikelihoodLoss, negative_log_likelihood_loss +from spox.opset.ai.onnx.v18 import _NonMaxSuppression, non_max_suppression +from spox.opset.ai.onnx.v18 import _NonZero, non_zero +from spox.opset.ai.onnx.v18 import _Not, not_ +from spox.opset.ai.onnx.v18 import _OneHot, one_hot +from spox.opset.ai.onnx.v18 import _Optional, optional +from spox.opset.ai.onnx.v18 import _OptionalGetElement, optional_get_element +from spox.opset.ai.onnx.v18 import _OptionalHasElement, optional_has_element +from spox.opset.ai.onnx.v18 import _Or, or_ +from spox.opset.ai.onnx.v18 import _PRelu, prelu +from spox.opset.ai.onnx.v18 import _Pow, pow +from spox.opset.ai.onnx.v18 import _QLinearConv, qlinear_conv +from spox.opset.ai.onnx.v18 import _QLinearMatMul, qlinear_matmul +from spox.opset.ai.onnx.v18 import _RNN, rnn +from spox.opset.ai.onnx.v18 import _RandomNormal, random_normal +from spox.opset.ai.onnx.v18 import _RandomNormalLike, random_normal_like +from spox.opset.ai.onnx.v18 import _RandomUniform, random_uniform +from spox.opset.ai.onnx.v18 import _RandomUniformLike, random_uniform_like +from spox.opset.ai.onnx.v18 import _Range, range +from spox.opset.ai.onnx.v18 import _Reciprocal, reciprocal +from spox.opset.ai.onnx.v18 import _ReduceL1, reduce_l1 +from spox.opset.ai.onnx.v18 import _ReduceL2, reduce_l2 +from spox.opset.ai.onnx.v18 import _ReduceLogSum, reduce_log_sum +from spox.opset.ai.onnx.v18 import _ReduceLogSumExp, reduce_log_sum_exp +from spox.opset.ai.onnx.v18 import _ReduceMax, reduce_max +from spox.opset.ai.onnx.v18 import _ReduceMean, reduce_mean +from spox.opset.ai.onnx.v18 import _ReduceMin, reduce_min +from spox.opset.ai.onnx.v18 import _ReduceProd, reduce_prod +from spox.opset.ai.onnx.v18 import _ReduceSum, reduce_sum +from spox.opset.ai.onnx.v18 import _ReduceSumSquare, reduce_sum_square +from spox.opset.ai.onnx.v18 import _Relu, relu +from spox.opset.ai.onnx.v18 import _ReverseSequence, reverse_sequence +from spox.opset.ai.onnx.v18 import _RoiAlign, roi_align +from spox.opset.ai.onnx.v18 import _Round, round +from spox.opset.ai.onnx.v18 import _STFT, stft +from spox.opset.ai.onnx.v18 import _ScatterElements, scatter_elements +from spox.opset.ai.onnx.v18 import _ScatterND, scatter_nd +from spox.opset.ai.onnx.v18 import _Selu, selu +from spox.opset.ai.onnx.v18 import _SequenceAt, sequence_at +from spox.opset.ai.onnx.v18 import _SequenceConstruct, sequence_construct +from spox.opset.ai.onnx.v18 import _SequenceEmpty, sequence_empty +from spox.opset.ai.onnx.v18 import _SequenceErase, sequence_erase +from spox.opset.ai.onnx.v18 import _SequenceInsert, sequence_insert +from spox.opset.ai.onnx.v18 import _SequenceLength, sequence_length +from spox.opset.ai.onnx.v18 import _SequenceMap, sequence_map +from spox.opset.ai.onnx.v18 import _Shrink, shrink +from spox.opset.ai.onnx.v18 import _Sigmoid, sigmoid +from spox.opset.ai.onnx.v18 import _Sign, sign +from spox.opset.ai.onnx.v18 import _Sin, sin +from spox.opset.ai.onnx.v18 import _Sinh, sinh +from spox.opset.ai.onnx.v18 import _Slice, slice +from spox.opset.ai.onnx.v18 import _Softmax, softmax +from spox.opset.ai.onnx.v18 import _SoftmaxCrossEntropyLoss, softmax_cross_entropy_loss +from spox.opset.ai.onnx.v18 import _Softplus, softplus +from spox.opset.ai.onnx.v18 import _Softsign, softsign +from spox.opset.ai.onnx.v18 import _SpaceToDepth, space_to_depth +from spox.opset.ai.onnx.v18 import _Split, split +from spox.opset.ai.onnx.v18 import _SplitToSequence, split_to_sequence +from spox.opset.ai.onnx.v18 import _Sqrt, sqrt +from spox.opset.ai.onnx.v18 import _Squeeze, squeeze +from spox.opset.ai.onnx.v18 import _StringNormalizer, string_normalizer +from spox.opset.ai.onnx.v18 import _Sub, sub +from spox.opset.ai.onnx.v18 import _Sum, sum +from spox.opset.ai.onnx.v18 import _Tan, tan +from spox.opset.ai.onnx.v18 import _Tanh, tanh +from spox.opset.ai.onnx.v18 import _TfIdfVectorizer, tf_idf_vectorizer +from spox.opset.ai.onnx.v18 import _ThresholdedRelu, thresholded_relu +from spox.opset.ai.onnx.v18 import _Tile, tile +from spox.opset.ai.onnx.v18 import _TopK, top_k +from spox.opset.ai.onnx.v18 import _Transpose, transpose +from spox.opset.ai.onnx.v18 import _Trilu, trilu +from spox.opset.ai.onnx.v18 import _Unique, unique +from spox.opset.ai.onnx.v18 import _Unsqueeze, unsqueeze +from spox.opset.ai.onnx.v18 import _Where, where +from spox.opset.ai.onnx.v18 import _Xor, xor class _AveragePool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -396,7 +229,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Cast(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -417,7 +249,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _CastLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -438,7 +269,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Constant(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -457,9 +287,7 @@ class Outputs(BaseOutputs): output: VarInfo def propagate_values(self, initializers) -> dict[str, PropValueType]: - ((key, raw),) = ( - (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None - ) + ((key, raw),) = ((k, v.value) for k, v in self.attrs.get_fields().items() if v is not None) if key == "value": value = raw elif key == "value_float": @@ -477,18 +305,14 @@ def propagate_values(self, initializers) -> dict[str, PropValueType]: elif key == "sparse_value": return {} else: - raise RuntimeError( - f"Could not extract the set Constant value attribute, got: {key}" - ) + raise RuntimeError(f"Could not extract the set Constant value attribute, got: {key}") return {"output": value} - op_type = OpType("Constant", "", 19) attrs: Attributes inputs: BaseInputs outputs: Outputs - class _DeformConv(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -517,7 +341,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _DequantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -539,7 +362,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Equal(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -560,7 +382,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Identity(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -580,7 +401,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _If(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -601,7 +421,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Loop(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -623,7 +442,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Pad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -646,7 +464,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _QuantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -669,7 +486,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Reshape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -690,7 +506,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Resize(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -721,7 +536,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Scan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -746,7 +560,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Shape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -767,7 +580,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Size(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -787,1964 +599,1655 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - -def average_pool( - X: Var, - *, - auto_pad: str = "NOTSET", - ceil_mode: int = 0, - count_include_pad: int = 0, - dilations: Optional[Iterable[int]] = None, - kernel_shape: Iterable[int], - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: +def average_pool(X: Var, *, auto_pad: str = "NOTSET", ceil_mode: int = 0, count_include_pad: int = 0, dilations: Optional[Iterable[int]] = None, kernel_shape: Iterable[int], pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: r""" - AveragePool consumes an input tensor X and applies average pooling - across the tensor according to kernel sizes, stride sizes, and pad - lengths. average pooling consisting of computing the average on all - values of a subset of the input tensor according to the kernel size and - downsampling the data into the output tensor Y for further processing. - The output spatial shape is calculated differently depending on whether - explicit padding is used, where pads is employed, or auto padding is - used, where auto_pad is utilized. With explicit padding - (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): - - :: - - output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) - - or - - :: - - output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) - - if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. Sliding windows that would start in the right padded region are - ignored. - - ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, - the output spatial shape will be following when ceil_mode is enabled: - - :: - - VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) - - or when ceil_mode is disabled - (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): - - :: - - VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 - - And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: - - :: - - pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] - - The output of each pooling window is divided by the number of elements - (exclude pad when attribute count_include_pad is zero). - - Parameters - ========== - X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. Optionally, if dimension denotation is in - effect, the operation expects the input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. - auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. - ceil_mode - Attribute. - Whether to use ceil or floor (default) to compute the output shape. - count_include_pad - Attribute. - Whether include pad pixels when calculating values for the edges. - Default is 0, doesn't count include pad. - dilations - Attribute. - Dilation value along each spatial axis of filter. If not present, the - dilation defaults to 1 along each spatial axis. - kernel_shape - Attribute. - The size of the kernel along each axis. - pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. - strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - - Returns - ======= - Y : Var - Type T. - Output data tensor from average or max pooling across the input tensor. - Dimensions will vary based on various kernel, stride, and pad sizes. - Floor value of the dimension is used - - Notes - ===== - Signature: ``ai.onnx@19::AveragePool``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +AveragePool consumes an input tensor X and applies average pooling +across the tensor according to kernel sizes, stride sizes, and pad +lengths. average pooling consisting of computing the average on all +values of a subset of the input tensor according to the kernel size and +downsampling the data into the output tensor Y for further processing. +The output spatial shape is calculated differently depending on whether +explicit padding is used, where pads is employed, or auto padding is +used, where auto_pad is utilized. With explicit padding +(https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): + +:: + + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + +or + +:: + + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + +if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis +``i``. Sliding windows that would start in the right padded region are +ignored. + +``auto_pad`` is a DEPRECATED attribute. If you are using them currently, +the output spatial shape will be following when ceil_mode is enabled: + +:: + + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + +or when ceil_mode is disabled +(https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): + +:: + + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 + +And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: + +:: + + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + +The output of each pooling window is divided by the number of elements +(exclude pad when attribute count_include_pad is zero). + +Parameters +========== +X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. Optionally, if dimension denotation is in + effect, the operation expects the input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. +auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. +ceil_mode + Attribute. + Whether to use ceil or floor (default) to compute the output shape. +count_include_pad + Attribute. + Whether include pad pixels when calculating values for the edges. + Default is 0, doesn't count include pad. +dilations + Attribute. + Dilation value along each spatial axis of filter. If not present, the + dilation defaults to 1 along each spatial axis. +kernel_shape + Attribute. + The size of the kernel along each axis. +pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. +strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + +Returns +======= +Y : Var + Type T. + Output data tensor from average or max pooling across the input tensor. + Dimensions will vary based on various kernel, stride, and pad sizes. + Floor value of the dimension is used + +Notes +===== +Signature: ``ai.onnx@19::AveragePool``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _AveragePool( - _AveragePool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - count_include_pad=AttrInt64( - count_include_pad, name="count_include_pad" - ), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _AveragePool.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def cast( - input: Var, - *, - saturate: int = 1, - to: npt.DTypeLike, -) -> Var: + return _AveragePool( + _AveragePool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + count_include_pad=AttrInt64(count_include_pad, name="count_include_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _AveragePool.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def cast(input: Var, *, saturate: int = 1, to: npt.DTypeLike, ) -> Var: r""" - The operator casts the elements of a given input tensor to a data type - specified by the 'to' argument and returns an output tensor of the same - size in the converted type. The 'to' argument must be one of the data - types specified in the 'DataType' enum field in the TensorProto message. - - Casting from string tensor in plain (e.g., "3.14" and "1000") and - scientific numeric representations (e.g., "1e-5" and "1E8") to float - types is supported. For example, converting string "100.5" to an integer - may yield result 100. There are some string literals reserved for - special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are - positive infinity, negative infinity, and not-a-number, respectively. - Any string which can exactly match "+INF" in a case-insensitive way - would be mapped to positive infinite. Similarly, this case-insensitive - rule is applied to "INF" and "NaN". When casting from numeric tensors to - string tensors, plain floating-point representation (such as - "314.15926") would be used. Converting non-numerical-literal string such - as "Hello World!" is an undefined behavior. Cases of converting string - representing floating-point arithmetic value, such as "2.718", to INT is - an undefined behavior. - - Conversion from a numerical type to any numerical type is always - allowed. User must be aware of precision loss and value change caused by - range difference between two types. For example, a 64-bit float - 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, - converting an integer 36 to Boolean may produce 1 because we truncate - bits which can't be stored in the targeted type. - - In more detail, the conversion among numerical types should follow these - rules if the destination type is not a float 8 type. - - - Casting from floating point to: - - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. - - - Casting from fixed point to: - - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. - - - Casting from bool to: - - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. - - Float 8 type were introduced to speed up the training of deep models. By - default the conversion of a float *x* obeys to the following rules. - ``[x]`` means the value rounded to the target mantissa width. - - ============== =========== ======== ======== ======== - x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ - ============== =========== ======== ======== ======== - 0 0 0 0 0 - -0 -0 0 -0 0 - NaN NaN NaN NaN NaN - +/- Inf +/- FLT_MAX NaN FLT_MAX NaN - [x] > FLT_MAX FLT_MAX FLT_MAX FLT_MAX FLT_MAX - [x] < -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX - else RNE RNE RNE RNE - ============== =========== ======== ======== ======== - - The behavior changes if the parameter 'saturate' is set to False. The - rules then become: - - ============== ====== ======== ======= ======== - x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ - ============== ====== ======== ======= ======== - 0 0 0 0 0 - -0 -0 0 -0 0 - NaN NaN NaN NaN NaN - +/- Inf NaN NaN +/- Inf NaN - [x] > FLT_MAX NaN NaN Inf NaN - [x] < -FLT_MAX NaN NaN -Inf NaN - else RNE RNE RNE RNE - ============== ====== ======== ======= ======== - - Parameters - ========== - input - Type T1. - Input tensor to be cast. - saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. All cases are fully described in two tables - inserted in the operator description. - to - Attribute. - The data type to which the elements of the input tensor are cast. - Strictly must be one of the types from DataType enum in TensorProto - - Returns - ======= - output : Var - Type T2. - Output tensor with the same shape as input with type specified by the - 'to' argument - - Notes - ===== - Signature: ``ai.onnx@19::Cast``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +The operator casts the elements of a given input tensor to a data type +specified by the 'to' argument and returns an output tensor of the same +size in the converted type. The 'to' argument must be one of the data +types specified in the 'DataType' enum field in the TensorProto message. + +Casting from string tensor in plain (e.g., "3.14" and "1000") and +scientific numeric representations (e.g., "1e-5" and "1E8") to float +types is supported. For example, converting string "100.5" to an integer +may yield result 100. There are some string literals reserved for +special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are +positive infinity, negative infinity, and not-a-number, respectively. +Any string which can exactly match "+INF" in a case-insensitive way +would be mapped to positive infinite. Similarly, this case-insensitive +rule is applied to "INF" and "NaN". When casting from numeric tensors to +string tensors, plain floating-point representation (such as +"314.15926") would be used. Converting non-numerical-literal string such +as "Hello World!" is an undefined behavior. Cases of converting string +representing floating-point arithmetic value, such as "2.718", to INT is +an undefined behavior. + +Conversion from a numerical type to any numerical type is always +allowed. User must be aware of precision loss and value change caused by +range difference between two types. For example, a 64-bit float +3.1415926459 may be round to a 32-bit float 3.141592. Similarly, +converting an integer 36 to Boolean may produce 1 because we truncate +bits which can't be stored in the targeted type. + +In more detail, the conversion among numerical types should follow these +rules if the destination type is not a float 8 type. + +- Casting from floating point to: + + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. + +- Casting from fixed point to: + + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. + +- Casting from bool to: + + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. + +Float 8 type were introduced to speed up the training of deep models. By +default the conversion of a float *x* obeys to the following rules. +``[x]`` means the value rounded to the target mantissa width. + +============== =========== ======== ======== ======== +x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ +============== =========== ======== ======== ======== +0 0 0 0 0 +-0 -0 0 -0 0 +NaN NaN NaN NaN NaN ++/- Inf +/- FLT_MAX NaN FLT_MAX NaN +[x] > FLT_MAX FLT_MAX FLT_MAX FLT_MAX FLT_MAX +[x] < -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX +else RNE RNE RNE RNE +============== =========== ======== ======== ======== + +The behavior changes if the parameter 'saturate' is set to False. The +rules then become: + +============== ====== ======== ======= ======== +x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ +============== ====== ======== ======= ======== +0 0 0 0 0 +-0 -0 0 -0 0 +NaN NaN NaN NaN NaN ++/- Inf NaN NaN +/- Inf NaN +[x] > FLT_MAX NaN NaN Inf NaN +[x] < -FLT_MAX NaN NaN -Inf NaN +else RNE RNE RNE RNE +============== ====== ======== ======= ======== + +Parameters +========== +input + Type T1. + Input tensor to be cast. +saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. All cases are fully described in two tables + inserted in the operator description. +to + Attribute. + The data type to which the elements of the input tensor are cast. + Strictly must be one of the types from DataType enum in TensorProto + +Returns +======= +output : Var + Type T2. + Output tensor with the same shape as input with type specified by the + 'to' argument + +Notes +===== +Signature: ``ai.onnx@19::Cast``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Cast( - _Cast.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - to=AttrDtype(to, name="to"), - ), - _Cast.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Cast( + _Cast.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + to=AttrDtype(to, name="to"), + ), _Cast.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def cast_like( - input: Var, - target_type: Var, - *, - saturate: int = 1, -) -> Var: +def cast_like(input: Var, target_type: Var, *, saturate: int = 1, ) -> Var: r""" - The operator casts the elements of a given input tensor (the first - input) to the same data type as the elements of the second input tensor. - See documentation of the Cast operator for further details. - - Parameters - ========== - input - Type T1. - Input tensor to be cast. - target_type - Type T2. - The (first) input tensor will be cast to produce a tensor of the same - type as this (second input) tensor. - saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. Please refer to operator Cast description for - further details. - - Returns - ======= - output : Var - Type T2. - Output tensor produced by casting the first input tensor to have the - same type as the second input tensor. - - Notes - ===== - Signature: ``ai.onnx@19::CastLike``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +The operator casts the elements of a given input tensor (the first +input) to the same data type as the elements of the second input tensor. +See documentation of the Cast operator for further details. + +Parameters +========== +input + Type T1. + Input tensor to be cast. +target_type + Type T2. + The (first) input tensor will be cast to produce a tensor of the same + type as this (second input) tensor. +saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. Please refer to operator Cast description for + further details. + +Returns +======= +output : Var + Type T2. + Output tensor produced by casting the first input tensor to have the + same type as the second input tensor. + +Notes +===== +Signature: ``ai.onnx@19::CastLike``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _CastLike( - _CastLike.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - ), - _CastLike.Inputs( - input=unwrap_vars(input), - target_type=unwrap_vars(target_type), - ), - ) - .get_output_vars( - input=get_value(input), - target_type=get_value(target_type), - ) - .output - ) + return _CastLike( + _CastLike.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + ), _CastLike.Inputs( + input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), ).get_output_vars( + input=get_value(input), target_type=get_value(target_type), ).output -def constant( - *, - value: Optional[np.ndarray] = None, - value_float: Optional[float] = None, - value_floats: Optional[Iterable[float]] = None, - value_int: Optional[int] = None, - value_ints: Optional[Iterable[int]] = None, - value_string: Optional[str] = None, - value_strings: Optional[Iterable[str]] = None, -) -> Var: +def constant(*, value: Optional[np.ndarray] = None, value_float: Optional[float] = None, value_floats: Optional[Iterable[float]] = None, value_int: Optional[int] = None, value_ints: Optional[Iterable[int]] = None, value_string: Optional[str] = None, value_strings: Optional[Iterable[str]] = None, ) -> Var: r""" - This operator produces a constant tensor. Exactly one of the provided - attributes, either value, sparse_value, or value\_\* must be specified. - - Parameters - ========== - sparse_value - Attribute. - The value for the elements of the output tensor in sparse format. - value - Attribute. - The value for the elements of the output tensor. - value_float - Attribute. - The value for the sole element for the scalar, float32, output tensor. - value_floats - Attribute. - The values for the elements for the 1D, float32, output tensor. - value_int - Attribute. - The value for the sole element for the scalar, int64, output tensor. - value_ints - Attribute. - The values for the elements for the 1D, int64, output tensor. - value_string - Attribute. - The value for the sole element for the scalar, UTF-8 string, output - tensor. - value_strings - Attribute. - The values for the elements for the 1D, UTF-8 string, output tensor. - - Returns - ======= - output : Var - Type T. - Output tensor containing the same value of the provided tensor. - - Notes - ===== - Signature: ``ai.onnx@19::Constant``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +This operator produces a constant tensor. Exactly one of the provided +attributes, either value, sparse_value, or value\_\* must be specified. + +Parameters +========== +sparse_value + Attribute. + The value for the elements of the output tensor in sparse format. +value + Attribute. + The value for the elements of the output tensor. +value_float + Attribute. + The value for the sole element for the scalar, float32, output tensor. +value_floats + Attribute. + The values for the elements for the 1D, float32, output tensor. +value_int + Attribute. + The value for the sole element for the scalar, int64, output tensor. +value_ints + Attribute. + The values for the elements for the 1D, int64, output tensor. +value_string + Attribute. + The value for the sole element for the scalar, UTF-8 string, output + tensor. +value_strings + Attribute. + The values for the elements for the 1D, UTF-8 string, output tensor. + +Returns +======= +output : Var + Type T. + Output tensor containing the same value of the provided tensor. + +Notes +===== +Signature: ``ai.onnx@19::Constant``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), - _Constant.Inputs(), - ) - .get_output_vars() - .output - ) - - -def deform_conv( - X: Var, - W: Var, - offset: Var, - B: Optional[Var] = None, - mask: Optional[Var] = None, - *, - dilations: Optional[Iterable[int]] = None, - group: int = 1, - kernel_shape: Optional[Iterable[int]] = None, - offset_group: int = 1, - pads: Optional[Iterable[int]] = None, - strides: Optional[Iterable[int]] = None, -) -> Var: + return _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), _Constant.Inputs( + ), ).get_output_vars( + ).output + + +def deform_conv(X: Var, W: Var, offset: Var, B: Optional[Var] = None, mask: Optional[Var] = None, *, dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, offset_group: int = 1, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: r""" - Performs deformable convolution as described in - https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168. - This operator specification supports the general N-D case. Note that - most common use cases have 2D or 3D data. - - Parameters - ========== - X - Type T. - Input data tensor. For 2D image data, it has shape (N, C, H, W) where N - is the batch size, C is the number of input channels, and H and W are - the height and width. In general, the shape is (N, C, D1, D2, ... , Dn) - for n-dimensional data, where D1 to Dn are the spatial dimension sizes. - Most common use cases have n = 2 or 3. - W - Type T. - Weight tensor that will be used in the convolutions. It has shape (oC, - C/group, kH, kW), where oC is the number of output channels and kH and - kW are the kernel height and width. For more than 2 dimensions, it has - shape (oC, C/group, k1, k2, ... , kn). - offset - Type T. - Offset tensor denoting the offset for the sampling locations in the - convolution kernel. It has shape (N, offset_group \* kH \* kW \* 2, oH, - oW) for 2D data or (N, offset_group \* k1 \* k2 \* ... \* kn \* n, o1, - o2, ... , on) for nD data. Use linear interpolationfor fractional offset - values. Sampling locations outside of the padded input tensor gives - zero. - B - Type T. - Optional 1D bias of length oC to be added to the convolution. Default is - a tensor of zeros. - mask - Type T. - The mask tensor to be applied to each position in the convolution - kernel. It has shape (N, offset_group \* kH \* kW, oH, oW) for 2D data - or (N, offset_group \* k1 \* k2 \* ... \* kn \* n, o1, o2, ... , on) for - nD data. Default is a tensor of ones. - dilations - Attribute. - Dilation value along each spatial axis of the kernel. Default is 1 along - each axis. - group - Attribute. - Number of groups the input and output channels, C and oC, are divided - into. C and oC must both be divisible by group. Default is 1. - kernel_shape - Attribute. - Shape of the convolution kernel. If not present, it is inferred from the - shape of input W. - offset_group - Attribute. - Number of groups of offset. C must be divisible by offset_group. Default - is 1. - pads - Attribute. - Padding for the beginning and end along each spatial axis. The values - represent the number of pixels added to the beginning and end of the - corresponding axis and can take any nonnegative value. The format should - be as follows: [x1_begin, x2_begin, ..., x1_end, x2_end, ...], where - xi_begin is the number of pixels added at the beginning of axis ``i`` - and xi_end is the number of pixels added at the end of axis ``i``. - Default is 0 along each axis. - strides - Attribute. - Stride along each spatial axis. Default is 1 along each axis. - - Returns - ======= - Y : Var - Type T. - Output data tensor that contains the result of convolution. It has shape - (N, oC, oH, oW) for 2D data or (N, oC, o1, o2, ..., on) for nD data - - Notes - ===== - Signature: ``ai.onnx@19::DeformConv``. - - Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Performs deformable convolution as described in +https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168. +This operator specification supports the general N-D case. Note that +most common use cases have 2D or 3D data. + +Parameters +========== +X + Type T. + Input data tensor. For 2D image data, it has shape (N, C, H, W) where N + is the batch size, C is the number of input channels, and H and W are + the height and width. In general, the shape is (N, C, D1, D2, ... , Dn) + for n-dimensional data, where D1 to Dn are the spatial dimension sizes. + Most common use cases have n = 2 or 3. +W + Type T. + Weight tensor that will be used in the convolutions. It has shape (oC, + C/group, kH, kW), where oC is the number of output channels and kH and + kW are the kernel height and width. For more than 2 dimensions, it has + shape (oC, C/group, k1, k2, ... , kn). +offset + Type T. + Offset tensor denoting the offset for the sampling locations in the + convolution kernel. It has shape (N, offset_group \* kH \* kW \* 2, oH, + oW) for 2D data or (N, offset_group \* k1 \* k2 \* ... \* kn \* n, o1, + o2, ... , on) for nD data. Use linear interpolationfor fractional offset + values. Sampling locations outside of the padded input tensor gives + zero. +B + Type T. + Optional 1D bias of length oC to be added to the convolution. Default is + a tensor of zeros. +mask + Type T. + The mask tensor to be applied to each position in the convolution + kernel. It has shape (N, offset_group \* kH \* kW, oH, oW) for 2D data + or (N, offset_group \* k1 \* k2 \* ... \* kn \* n, o1, o2, ... , on) for + nD data. Default is a tensor of ones. +dilations + Attribute. + Dilation value along each spatial axis of the kernel. Default is 1 along + each axis. +group + Attribute. + Number of groups the input and output channels, C and oC, are divided + into. C and oC must both be divisible by group. Default is 1. +kernel_shape + Attribute. + Shape of the convolution kernel. If not present, it is inferred from the + shape of input W. +offset_group + Attribute. + Number of groups of offset. C must be divisible by offset_group. Default + is 1. +pads + Attribute. + Padding for the beginning and end along each spatial axis. The values + represent the number of pixels added to the beginning and end of the + corresponding axis and can take any nonnegative value. The format should + be as follows: [x1_begin, x2_begin, ..., x1_end, x2_end, ...], where + xi_begin is the number of pixels added at the beginning of axis ``i`` + and xi_end is the number of pixels added at the end of axis ``i``. + Default is 0 along each axis. +strides + Attribute. + Stride along each spatial axis. Default is 1 along each axis. + +Returns +======= +Y : Var + Type T. + Output data tensor that contains the result of convolution. It has shape + (N, oC, oH, oW) for 2D data or (N, oC, o1, o2, ..., on) for nD data + +Notes +===== +Signature: ``ai.onnx@19::DeformConv``. + +Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _DeformConv( - _DeformConv.Attributes( - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - offset_group=AttrInt64(offset_group, name="offset_group"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), - _DeformConv.Inputs( - X=unwrap_vars(X), - W=unwrap_vars(W), - offset=unwrap_vars(offset), - B=unwrap_vars(B), - mask=unwrap_vars(mask), - ), - ) - .get_output_vars( - X=get_value(X), - W=get_value(W), - offset=get_value(offset), - B=get_value(B), - mask=get_value(mask), - ) - .Y - ) - - -def dequantize_linear( - x: Var, - x_scale: Var, - x_zero_point: Optional[Var] = None, - *, - axis: int = 1, -) -> Var: + return _DeformConv( + _DeformConv.Attributes( + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + offset_group=AttrInt64(offset_group, name="offset_group"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), _DeformConv.Inputs( + X=unwrap_vars(X), W=unwrap_vars(W), offset=unwrap_vars(offset), B=unwrap_vars(B), mask=unwrap_vars(mask), ), ).get_output_vars( + X=get_value(X), W=get_value(W), offset=get_value(offset), B=get_value(B), mask=get_value(mask), ).Y + + +def dequantize_linear(x: Var, x_scale: Var, x_zero_point: Optional[Var] = None, *, axis: int = 1, ) -> Var: r""" - The linear dequantization operator. It consumes a quantized tensor, a - scale, and a zero point to compute the full precision tensor. The - dequantization formula is ``y = (x - x_zero_point) * x_scale``. - ``x_scale`` and ``x_zero_point`` must have same shape, and can be either - a scalar for per-tensor / per layer quantization, or a 1-D tensor for - per-axis quantization. ``x_zero_point`` and ``x`` must have same type. - ``x`` and ``y`` must have same shape. In the case of dequantizing int32, - there's no zero point (zero point is supposed to be 0). ``zero-point`` - is usually not used in the case of float8e4m3fn, float8e4m3fnuz, - float8e5m2, float8e5m2fnuz quantization, but the dequantization formula - remains the same for consistency and 'x_scale' still determines the - output type. - - Parameters - ========== - x - Type T1. - N-D quantized input tensor to be de-quantized. - x_scale - Type T2. - Scale for input 'x'. It can be a scalar, which means a per-tensor/layer - dequantization, or a 1-D tensor for per-axis dequantization. - x_zero_point - Type T1. - Zero point for input 'x'. Shape must match x_scale. It's optional. Zero - point is 0 when it's not specified. - axis - Attribute. - (Optional) The axis of the dequantizing dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - - Returns - ======= - y : Var - Type T2. - N-D full precision output tensor. It has same shape as input 'x'. - - Notes - ===== - Signature: ``ai.onnx@19::DequantizeLinear``. - - Type constraints: - - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` +The linear dequantization operator. It consumes a quantized tensor, a +scale, and a zero point to compute the full precision tensor. The +dequantization formula is ``y = (x - x_zero_point) * x_scale``. +``x_scale`` and ``x_zero_point`` must have same shape, and can be either +a scalar for per-tensor / per layer quantization, or a 1-D tensor for +per-axis quantization. ``x_zero_point`` and ``x`` must have same type. +``x`` and ``y`` must have same shape. In the case of dequantizing int32, +there's no zero point (zero point is supposed to be 0). ``zero-point`` +is usually not used in the case of float8e4m3fn, float8e4m3fnuz, +float8e5m2, float8e5m2fnuz quantization, but the dequantization formula +remains the same for consistency and 'x_scale' still determines the +output type. + +Parameters +========== +x + Type T1. + N-D quantized input tensor to be de-quantized. +x_scale + Type T2. + Scale for input 'x'. It can be a scalar, which means a per-tensor/layer + dequantization, or a 1-D tensor for per-axis dequantization. +x_zero_point + Type T1. + Zero point for input 'x'. Shape must match x_scale. It's optional. Zero + point is 0 when it's not specified. +axis + Attribute. + (Optional) The axis of the dequantizing dimension of the input tensor. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + +Returns +======= +y : Var + Type T2. + N-D full precision output tensor. It has same shape as input 'x'. + +Notes +===== +Signature: ``ai.onnx@19::DequantizeLinear``. + +Type constraints: + - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - return ( - _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _DequantizeLinear.Inputs( - x=unwrap_vars(x), - x_scale=unwrap_vars(x_scale), - x_zero_point=unwrap_vars(x_zero_point), - ), - ) - .get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - ) - .y - ) + return _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _DequantizeLinear.Inputs( + x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), ).get_output_vars( + x=get_value(x), x_scale=get_value(x_scale), x_zero_point=get_value(x_zero_point), ).y -def equal( - A: Var, - B: Var, -) -> Var: +def equal(A: Var, B: Var, ) -> Var: r""" - Returns the tensor resulted from performing the ``equal`` logical - operation elementwise on the input tensors ``A`` and ``B`` (with - Numpy-style broadcasting support). - - This operator supports **multidirectional (i.e., Numpy-style) - broadcasting**; for more details please check `the - doc `__. - - Parameters - ========== - A - Type T. - First input operand for the logical operator. - B - Type T. - Second input operand for the logical operator. - - Returns - ======= - C : Var - Type T1. - Result tensor. - - Notes - ===== - Signature: ``ai.onnx@19::Equal``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` +Returns the tensor resulted from performing the ``equal`` logical +operation elementwise on the input tensors ``A`` and ``B`` (with +Numpy-style broadcasting support). + +This operator supports **multidirectional (i.e., Numpy-style) +broadcasting**; for more details please check `the +doc `__. + +Parameters +========== +A + Type T. + First input operand for the logical operator. +B + Type T. + Second input operand for the logical operator. + +Returns +======= +C : Var + Type T1. + Result tensor. + +Notes +===== +Signature: ``ai.onnx@19::Equal``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` """ - return ( - _Equal( - _Equal.Attributes(), - _Equal.Inputs( - A=unwrap_vars(A), - B=unwrap_vars(B), - ), - ) - .get_output_vars( - A=get_value(A), - B=get_value(B), - ) - .C - ) + return _Equal( + _Equal.Attributes( + ), _Equal.Inputs( + A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( + A=get_value(A), B=get_value(B), ).C -def identity( - input: Var, -) -> Var: +def identity(input: Var, ) -> Var: r""" - Identity operator - - Parameters - ========== - input - Type V. - Input tensor - - Returns - ======= - output : Var - Type V. - Tensor to copy input into. - - Notes - ===== - Signature: ``ai.onnx@19::Identity``. - - Type constraints: - - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Identity operator + +Parameters +========== +input + Type V. + Input tensor + +Returns +======= +output : Var + Type V. + Tensor to copy input into. + +Notes +===== +Signature: ``ai.onnx@19::Identity``. + +Type constraints: + - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Identity( - _Identity.Attributes(), - _Identity.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Identity( + _Identity.Attributes( + ), _Identity.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def if_( - cond: Var, - *, - else_branch: Callable[[], Iterable[Var]], - then_branch: Callable[[], Iterable[Var]], -) -> Sequence[Var]: +def if_(cond: Var, *, else_branch: Callable[[], Iterable[Var]], then_branch: Callable[[], Iterable[Var]], ) -> Sequence[Var]: r""" - If conditional - - Parameters - ========== - cond - Type B. - Condition for the if. The tensor must contain a single element. - else_branch - Attribute. - Graph to run if condition is false. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the then_branch. - then_branch - Attribute. - Graph to run if condition is true. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the else_branch. - - Returns - ======= - outputs : Sequence[Var] - Type V. - Values that are live-out to the enclosing scope. The return values in - the ``then_branch`` and ``else_branch`` must be of the same data type. - The ``then_branch`` and ``else_branch`` may produce tensors with the - same element type and different shapes. If corresponding outputs from - the then-branch and the else-branch have static shapes S1 and S2, then - the shape of the corresponding output variable of the if-node (if - present) must be compatible with both S1 and S2 as it represents the - union of both possible shapes.For example, if in a model file, the first - output of ``then_branch`` is typed float tensor with shape [2] and the - first output of ``else_branch`` is another float tensor with shape [3], - If's first output should have (a) no shape set, or (b) a shape of rank 1 - with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank - 1 with a unique ``dim_param``. In contrast, the first output cannot have - the shape [2] since [2] and [3] are not compatible. - - Notes - ===== - Signature: ``ai.onnx@19::If``. - - Type constraints: - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +If conditional + +Parameters +========== +cond + Type B. + Condition for the if. The tensor must contain a single element. +else_branch + Attribute. + Graph to run if condition is false. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the then_branch. +then_branch + Attribute. + Graph to run if condition is true. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the else_branch. + +Returns +======= +outputs : Sequence[Var] + Type V. + Values that are live-out to the enclosing scope. The return values in + the ``then_branch`` and ``else_branch`` must be of the same data type. + The ``then_branch`` and ``else_branch`` may produce tensors with the + same element type and different shapes. If corresponding outputs from + the then-branch and the else-branch have static shapes S1 and S2, then + the shape of the corresponding output variable of the if-node (if + present) must be compatible with both S1 and S2 as it represents the + union of both possible shapes.For example, if in a model file, the first + output of ``then_branch`` is typed float tensor with shape [2] and the + first output of ``else_branch`` is another float tensor with shape [3], + If's first output should have (a) no shape set, or (b) a shape of rank 1 + with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank + 1 with a unique ``dim_param``. In contrast, the first output cannot have + the shape [2] since [2] and [3] are not compatible. + +Notes +===== +Signature: ``ai.onnx@19::If``. + +Type constraints: + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - _else_branch_subgraph: Graph = subgraph((), else_branch) - _then_branch_subgraph: Graph = subgraph((), then_branch) - return ( - _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), - _If.Inputs( - cond=unwrap_vars(cond), - ), - out_variadic=len(_else_branch_subgraph.requested_results), - ) - .get_output_vars( - cond=get_value(cond), - ) - .outputs + _else_branch_subgraph: Graph = subgraph( + (), + else_branch + ) + _then_branch_subgraph: Graph = subgraph( + (), + then_branch ) + return _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), _If.Inputs( + cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), ).get_output_vars( + cond=get_value(cond), ).outputs -def loop( - M: Optional[Var] = None, - cond: Optional[Var] = None, - v_initial: Sequence[Var] = (), - *, - body: Callable[..., Iterable[Var]], -) -> Sequence[Var]: +def loop(M: Optional[Var] = None, cond: Optional[Var] = None, v_initial: Sequence[Var] = (), *, body: Callable[..., Iterable[Var]], ) -> Sequence[Var]: r""" - Generic Looping construct. This loop has multiple termination - conditions: - - 1) Trip count. Iteration count specified at runtime. Set by specifying - the input M. Optional. Set to empty string to omit. Note that a - static trip count (specified at graph construction time) can be - specified by passing in a constant node for input M. - 2) Loop termination condition. This is an input to the op that - determines whether to run the first iteration and also a loop-carried - dependency for the body graph. The body graph must yield a value for - the condition variable, whether this input is provided or not. - - This table summarizes the operating modes of this operator with - equivalent C-style code: - - Operator inputs defined as (max_trip_count, condition_var). - - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } - - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } - - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } - - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } - - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } - - *Sample usage - cond as well as trip count* - - :: - - graph predict-net { - %a = Constant[value = ]() - %b = Constant[value = ]() - %keepgoing = Constant[value = ]() - %max_trip_count = Constant[value = ]() - %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) - return - } - - graph body-net ( - %i[INT32, scalar] // iteration number - %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used - %b_in[INT32, scalar] // incoming value of loop-carried-dependency b - ) { - %my_local = Add(%a, %b_in) - %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b - %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition - %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated - return %keepgoing_out, %b_out, %user_defined_val - } - - *Sample equivalent C code* - - :: - - { - /* User-defined code (enclosing scope) */ - int a = 3, b = 6; - bool keepgoing = true; // Analogous to input cond - /* End user-defined code */ - - /* Implicitly-defined code */ - const int max_trip_count = 10; // Analogous to input M - int user_defined_vals[]; // Imagine this is resizable - /* End implicitly-defined code */ - /* initialize loop-carried variables and scan-output variables */ - bool keepgoing_out = keepgoing - int b_out = b - - for (int i=0; i < max_trip_count && keepgoing_out; ++i) { - /* Implicitly-defined code: bind actual parameter values - to formal parameter variables of loop-body */ - bool keepgoing_in = keepgoing_out; - bool b_in = b_out; - - /* User-defined code (loop body) */ - int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine - b_out = a - b_in; - keepgoing_out = my_local > b_out; - user_defined_val = b_in + b_in; // b_in and b_out are different variables - /* End user-defined code */ - - /* Implicitly defined-code */ - user_defined_vals[i] = user_defined_val // accumulate scan-output values - } - // int t = my_local; // Can't do this. my_local is not accessible here. - - // The values below are bound to the output variables of the loop and therefore accessible - // b_out; user_defined_vals; keepgoing_out; - } - - There are several things of note in this code snippet: - - 1) Values from the enclosing scope (i.e. variable "a" here) are in scope - and can be referenced in the inputs of the loop. - 2) Any values computed in the loop body that needs to be used in a - subsequent iteration or after the loop are modelled using a pair of - variables in the loop-body, consisting of an input variable (eg., - b_in) and an output variable (eg., b_out). These are referred to as - loop-carried dependences. The loop operation node supplies the input - value of the input variable for the first iteration, and returns the - output value of the output variable produced by the final iteration. - 3) Scan_output variables are used to implicitly concatenate values - computed across all the iterations. In the above example, the value - of user_defined_val computed over all iterations are concatenated and - returned as the value of user_defined_vals after the loop. - 4) Values created in the body cannot be accessed in the enclosing scope, - except using the mechanism described above. - - Note that the semantics of this op support "diagonal" or "wavefront" - execution. (See Step 3 here for an example: - https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). - Frontends should emit multi-layer RNNs as a series of While operators - (with time being the inner looping dimension), with each successive - layer consuming the scan_outputs from the previous layer, possibly going - through several point-wise operators (e.g. dropout, residual - connections, linear layer). - - The input/output of subgraph (produced by loop node) matching is based - on order instead of name. The implementation will figure out the names - based on this order. - - Parameters - ========== - M - Type I. - A maximum trip-count for the loop specified at runtime. Optional. Pass - empty string to skip. - cond - Type B. - A boolean termination condition. Optional. Pass empty string to skip. - v_initial - Type V. - The initial values of any loop-carried dependencies (values that change - across loop iterations) - body - Attribute. - The graph run each iteration. It has 2+N inputs: (iteration_num, - condition, loop carried dependencies...). It has 1+N+K outputs: - (condition, loop carried dependencies..., scan_outputs...). Each - scan_output is created by concatenating the value of the specified - output value at the end of each iteration of the loop. It is an error if - the dimensions or data type of these scan_outputs change across loop - iterations. - - Returns - ======= - v_final_and_scan_outputs : Sequence[Var] - Type V. - Final N loop carried dependency values then K scan_outputs. Scan outputs - must be Tensors. - - Notes - ===== - Signature: ``ai.onnx@19::Loop``. - - Type constraints: - - I: `tensor(int64)` - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Generic Looping construct. This loop has multiple termination +conditions: + +1) Trip count. Iteration count specified at runtime. Set by specifying + the input M. Optional. Set to empty string to omit. Note that a + static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. +2) Loop termination condition. This is an input to the op that + determines whether to run the first iteration and also a loop-carried + dependency for the body graph. The body graph must yield a value for + the condition variable, whether this input is provided or not. + +This table summarizes the operating modes of this operator with +equivalent C-style code: + +Operator inputs defined as (max_trip_count, condition_var). + +- input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } + +- input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } + +- input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } + +- input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } + +- input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } + +*Sample usage - cond as well as trip count* + +:: + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + +*Sample equivalent C code* + +:: + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + +There are several things of note in this code snippet: + +1) Values from the enclosing scope (i.e. variable "a" here) are in scope + and can be referenced in the inputs of the loop. +2) Any values computed in the loop body that needs to be used in a + subsequent iteration or after the loop are modelled using a pair of + variables in the loop-body, consisting of an input variable (eg., + b_in) and an output variable (eg., b_out). These are referred to as + loop-carried dependences. The loop operation node supplies the input + value of the input variable for the first iteration, and returns the + output value of the output variable produced by the final iteration. +3) Scan_output variables are used to implicitly concatenate values + computed across all the iterations. In the above example, the value + of user_defined_val computed over all iterations are concatenated and + returned as the value of user_defined_vals after the loop. +4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + +Note that the semantics of this op support "diagonal" or "wavefront" +execution. (See Step 3 here for an example: +https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). +Frontends should emit multi-layer RNNs as a series of While operators +(with time being the inner looping dimension), with each successive +layer consuming the scan_outputs from the previous layer, possibly going +through several point-wise operators (e.g. dropout, residual +connections, linear layer). + +The input/output of subgraph (produced by loop node) matching is based +on order instead of name. The implementation will figure out the names +based on this order. + +Parameters +========== +M + Type I. + A maximum trip-count for the loop specified at runtime. Optional. Pass + empty string to skip. +cond + Type B. + A boolean termination condition. Optional. Pass empty string to skip. +v_initial + Type V. + The initial values of any loop-carried dependencies (values that change + across loop iterations) +body + Attribute. + The graph run each iteration. It has 2+N inputs: (iteration_num, + condition, loop carried dependencies...). It has 1+N+K outputs: + (condition, loop carried dependencies..., scan_outputs...). Each + scan_output is created by concatenating the value of the specified + output value at the end of each iteration of the loop. It is an error if + the dimensions or data type of these scan_outputs change across loop + iterations. + +Returns +======= +v_final_and_scan_outputs : Sequence[Var] + Type V. + Final N loop carried dependency values then K scan_outputs. Scan outputs + must be Tensors. + +Notes +===== +Signature: ``ai.onnx@19::Loop``. + +Type constraints: + - I: `tensor(int64)` + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ _body_subgraph: Graph = subgraph( - typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))]) - + [var.unwrap_type() for var in v_initial], - body, - ) - return ( - _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), - _Loop.Inputs( - M=unwrap_vars(M), - cond=unwrap_vars(cond), - v_initial=unwrap_vars(v_initial), - ), - out_variadic=len(_body_subgraph.requested_results) - 1, - ) - .get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), - ) - .v_final_and_scan_outputs + typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))])+ [var.unwrap_type() for var in v_initial], + body ) + return _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), _Loop.Inputs( + M=unwrap_vars(M), cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, ).get_output_vars( + M=get_value(M), cond=get_value(cond), v_initial=get_value(v_initial), ).v_final_and_scan_outputs -def pad( - data: Var, - pads: Var, - constant_value: Optional[Var] = None, - axes: Optional[Var] = None, - *, - mode: str = "constant", -) -> Var: +def pad(data: Var, pads: Var, constant_value: Optional[Var] = None, axes: Optional[Var] = None, *, mode: str = "constant", ) -> Var: r""" - Given a tensor containing the data to be padded (``data``), a tensor - containing the number of start and end pad values for axis (``pads``), - (optionally) a ``mode``, and (optionally) ``constant_value``, a padded - tensor (``output``) is generated. - - The three supported ``modes`` are (similar to corresponding modes - supported by ``numpy.pad``): - - 1) ``constant``\ (default) - pads with a given constant value as - specified by ``constant_value`` (which defaults to 0, empty string, - or False) - - 2) ``reflect`` - pads with the reflection of the vector mirrored on the - first and last values of the vector along each axis - - 3) ``edge`` - pads with the edge values of array - - 4) ``wrap`` - wrap-around padding as if the data tensor forms a torus - - Example 1 (``constant`` mode): - - Insert 0 pads to the beginning of the second dimension. - - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'constant' - - constant_value = 0.0 - - output = [ - [0.0, 0.0, 1.0, 1.2], - [0.0, 0.0, 2.3, 3.4], - [0.0, 0.0, 4.5, 5.7], - ] - - Example 2 (``reflect`` mode): +Given a tensor containing the data to be padded (``data``), a tensor +containing the number of start and end pad values for axis (``pads``), +(optionally) a ``mode``, and (optionally) ``constant_value``, a padded +tensor (``output``) is generated. - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'reflect' +The three supported ``modes`` are (similar to corresponding modes +supported by ``numpy.pad``): - output = [ - [1.0, 1.2, 1.0, 1.2], - [2.3, 3.4, 2.3, 3.4], - [4.5, 5.7, 4.5, 5.7], - ] +1) ``constant``\ (default) - pads with a given constant value as + specified by ``constant_value`` (which defaults to 0, empty string, + or False) - Example 3 (``edge`` mode): +2) ``reflect`` - pads with the reflection of the vector mirrored on the + first and last values of the vector along each axis - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] +3) ``edge`` - pads with the edge values of array - pads = [0, 2, 0, 0] +4) ``wrap`` - wrap-around padding as if the data tensor forms a torus - mode = 'edge' +Example 1 (``constant`` mode): - output = [ - [1.0, 1.0, 1.0, 1.2], - [2.3, 2.3, 2.3, 3.4], - [4.5, 4.5, 4.5, 5.7], - ] +Insert 0 pads to the beginning of the second dimension. - Example 4 (``wrap`` mode): +:: - :: + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [2, 1, 1, 1] - - mode = 'wrap' - - output = [ - [3.4, 2.3, 3.4, 2.3], - [5.7, 4.5, 5.7, 4.5], - [1.2, 1.0, 1.2, 1.0], - [3.4, 2.3, 3.4, 2.3], - [5.7, 4.5, 5.7, 4.5], - [1.2, 1.0, 1.2, 1.0], - ] - - Parameters - ========== - data - Type T. - Input tensor. - pads - Type tensor(int64). - Tensor of integers indicating the number of padding elements to add or - remove (if negative) at the beginning and end of each axis. For 2D input - tensor, it is the number of pixels. ``pads`` should be a 1D tensor of - shape [2 \* num_axes] where ``num_axes`` refers to the number of - elements in the ``axes`` input or the input rank if ``axes`` are not - provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, - ..., x1_end, x2_end,...], where xi_begin is the number of pad values - added at the beginning of axis ``axes[i]`` and xi_end, the number of pad - values added at the end of axis ``axes[i]``. - constant_value - Type T. - (Optional) A scalar value to be used if the mode chosen is ``constant`` - (by default it is 0, empty string or False). - axes - Type Tind. - 1-D tensor of axes that ``pads`` apply to. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(data). Behavior is undefined if an axis is repeated. If not - provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). - mode - Attribute. - Supported modes: ``constant``\ (default), ``reflect``, ``edge``, - ``wrap`` - - Returns - ======= - output : Var - Type T. - Tensor after padding. - - Notes - ===== - Signature: ``ai.onnx@19::Pad``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + +Example 2 (``reflect`` mode): + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] + +Example 3 (``edge`` mode): + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] + +Example 4 (``wrap`` mode): + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [2, 1, 1, 1] + + mode = 'wrap' + + output = [ + [3.4, 2.3, 3.4, 2.3], + [5.7, 4.5, 5.7, 4.5], + [1.2, 1.0, 1.2, 1.0], + [3.4, 2.3, 3.4, 2.3], + [5.7, 4.5, 5.7, 4.5], + [1.2, 1.0, 1.2, 1.0], + ] + +Parameters +========== +data + Type T. + Input tensor. +pads + Type tensor(int64). + Tensor of integers indicating the number of padding elements to add or + remove (if negative) at the beginning and end of each axis. For 2D input + tensor, it is the number of pixels. ``pads`` should be a 1D tensor of + shape [2 \* num_axes] where ``num_axes`` refers to the number of + elements in the ``axes`` input or the input rank if ``axes`` are not + provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, + ..., x1_end, x2_end,...], where xi_begin is the number of pad values + added at the beginning of axis ``axes[i]`` and xi_end, the number of pad + values added at the end of axis ``axes[i]``. +constant_value + Type T. + (Optional) A scalar value to be used if the mode chosen is ``constant`` + (by default it is 0, empty string or False). +axes + Type Tind. + 1-D tensor of axes that ``pads`` apply to. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(data). Behavior is undefined if an axis is repeated. If not + provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). +mode + Attribute. + Supported modes: ``constant``\ (default), ``reflect``, ``edge``, + ``wrap`` + +Returns +======= +output : Var + Type T. + Tensor after padding. + +Notes +===== +Signature: ``ai.onnx@19::Pad``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return ( - _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), - _Pad.Inputs( - data=unwrap_vars(data), - pads=unwrap_vars(pads), - constant_value=unwrap_vars(constant_value), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), - ) - .output - ) + return _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), _Pad.Inputs( + data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), pads=get_value(pads), constant_value=get_value(constant_value), axes=get_value(axes), ).output -def quantize_linear( - x: Var, - y_scale: Var, - y_zero_point: Optional[Var] = None, - *, - axis: int = 1, - saturate: int = 1, -) -> Var: +def quantize_linear(x: Var, y_scale: Var, y_zero_point: Optional[Var] = None, *, axis: int = 1, saturate: int = 1, ) -> Var: r""" - The linear quantization operator. It consumes a high precision tensor, a - scale, and a zero point to compute the low precision / quantized tensor. - The scale factor and zero point must have same shape, and can be either - a scalar for per-tensor / per layer quantization, or a 1-D tensor for - per-axis quantization. The quantization formula is - ``y = saturate ((x / y_scale) + y_zero_point)``. For saturation, it - saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8. For (x - / y_scale), it's rounding to the nearest even. Refer to - https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and - 'y' must have same type. 'y_zero_point' is usually not used for - quantization to float8e4m3fn, float8e4m3fnuz, float8e5m2, - float8e5m2fnuz, but the quantization formula remains the same for - consistency and the type of the attribute 'y_zero_point' still - determines the quantization type. - - Parameters - ========== - x - Type T1. - N-D full precision Input tensor to be quantized. - y_scale - Type T1. - Scale for doing quantization to get 'y'. It can be a scalar, which means - per-tensor/layer quantization, or a 1-D Tensor for per-axis - quantization. - y_zero_point - Type T2. - Zero point for doing quantization to get 'y'. Shape must match y_scale. - Default is uint8 with zero point of 0 if it's not specified. - axis - Attribute. - (Optional) The axis of the quantization dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. All cases are fully described in two tables - inserted in the operator description. - - Returns - ======= - y : Var - Type T2. - N-D quantized output tensor. It has same shape as input 'x'. - - Notes - ===== - Signature: ``ai.onnx@19::QuantizeLinear``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` +The linear quantization operator. It consumes a high precision tensor, a +scale, and a zero point to compute the low precision / quantized tensor. +The scale factor and zero point must have same shape, and can be either +a scalar for per-tensor / per layer quantization, or a 1-D tensor for +per-axis quantization. The quantization formula is +``y = saturate ((x / y_scale) + y_zero_point)``. For saturation, it +saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8. For (x +/ y_scale), it's rounding to the nearest even. Refer to +https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and +'y' must have same type. 'y_zero_point' is usually not used for +quantization to float8e4m3fn, float8e4m3fnuz, float8e5m2, +float8e5m2fnuz, but the quantization formula remains the same for +consistency and the type of the attribute 'y_zero_point' still +determines the quantization type. + +Parameters +========== +x + Type T1. + N-D full precision Input tensor to be quantized. +y_scale + Type T1. + Scale for doing quantization to get 'y'. It can be a scalar, which means + per-tensor/layer quantization, or a 1-D Tensor for per-axis + quantization. +y_zero_point + Type T2. + Zero point for doing quantization to get 'y'. Shape must match y_scale. + Default is uint8 with zero point of 0 if it's not specified. +axis + Attribute. + (Optional) The axis of the quantization dimension of the input tensor. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). +saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. All cases are fully described in two tables + inserted in the operator description. + +Returns +======= +y : Var + Type T2. + N-D quantized output tensor. It has same shape as input 'x'. + +Notes +===== +Signature: ``ai.onnx@19::QuantizeLinear``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` + - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - return ( - _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - saturate=AttrInt64(saturate, name="saturate"), - ), - _QuantizeLinear.Inputs( - x=unwrap_vars(x), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ) - .get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - ) - .y - ) + return _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + saturate=AttrInt64(saturate, name="saturate"), + ), _QuantizeLinear.Inputs( + x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( + x=get_value(x), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y -def reshape( - data: Var, - shape: Var, - *, - allowzero: int = 0, -) -> Var: +def reshape(data: Var, shape: Var, *, allowzero: int = 0, ) -> Var: r""" - Reshape the input tensor similar to numpy.reshape. First input is the - data tensor, second input is a shape tensor which specifies the output - shape. It outputs the reshaped tensor. At most one dimension of the new - shape can be -1. In this case, the value is inferred from the size of - the tensor and the remaining dimensions. A dimension could also be 0, in - which case the actual dimension value is unchanged (i.e. taken from the - input tensor). If 'allowzero' is set, and the new shape includes 0, the - dimension will be set explicitly to zero (i.e. not taken from input - tensor). Shape (second input) could be an empty shape, which means - converting to a scalar. The input tensor's shape and the output tensor's - shape are required to have the same number of elements. - - If the attribute 'allowzero' is set, it is invalid for the specified - shape to contain both a zero value and -1, as the value of the dimension - corresponding to -1 cannot be determined uniquely. - - Parameters - ========== - data - Type T. - An input tensor. - shape - Type tensor(int64). - Specified shape for output. - allowzero - Attribute. - (Optional) By default, when any value in the 'shape' input is equal to - zero the corresponding dimension value is copied from the input tensor - dynamically. allowzero=1 indicates that if any value in the 'shape' - input is set to zero, the zero value is honored, similar to NumPy. - - Returns - ======= - reshaped : Var - Type T. - Reshaped data. - - Notes - ===== - Signature: ``ai.onnx@19::Reshape``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Reshape the input tensor similar to numpy.reshape. First input is the +data tensor, second input is a shape tensor which specifies the output +shape. It outputs the reshaped tensor. At most one dimension of the new +shape can be -1. In this case, the value is inferred from the size of +the tensor and the remaining dimensions. A dimension could also be 0, in +which case the actual dimension value is unchanged (i.e. taken from the +input tensor). If 'allowzero' is set, and the new shape includes 0, the +dimension will be set explicitly to zero (i.e. not taken from input +tensor). Shape (second input) could be an empty shape, which means +converting to a scalar. The input tensor's shape and the output tensor's +shape are required to have the same number of elements. + +If the attribute 'allowzero' is set, it is invalid for the specified +shape to contain both a zero value and -1, as the value of the dimension +corresponding to -1 cannot be determined uniquely. + +Parameters +========== +data + Type T. + An input tensor. +shape + Type tensor(int64). + Specified shape for output. +allowzero + Attribute. + (Optional) By default, when any value in the 'shape' input is equal to + zero the corresponding dimension value is copied from the input tensor + dynamically. allowzero=1 indicates that if any value in the 'shape' + input is set to zero, the zero value is honored, similar to NumPy. + +Returns +======= +reshaped : Var + Type T. + Reshaped data. + +Notes +===== +Signature: ``ai.onnx@19::Reshape``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), - _Reshape.Inputs( - data=unwrap_vars(data), - shape=unwrap_vars(shape), - ), - ) - .get_output_vars( - data=get_value(data), - shape=get_value(shape), - ) - .reshaped - ) + return _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), _Reshape.Inputs( + data=unwrap_vars(data), shape=unwrap_vars(shape), ), ).get_output_vars( + data=get_value(data), shape=get_value(shape), ).reshaped -def resize( - X: Var, - roi: Optional[Var] = None, - scales: Optional[Var] = None, - sizes: Optional[Var] = None, - *, - antialias: int = 0, - axes: Optional[Iterable[int]] = None, - coordinate_transformation_mode: str = "half_pixel", - cubic_coeff_a: float = -0.75, - exclude_outside: int = 0, - extrapolation_value: float = 0.0, - keep_aspect_ratio_policy: str = "stretch", - mode: str = "nearest", - nearest_mode: str = "round_prefer_floor", -) -> Var: +def resize(X: Var, roi: Optional[Var] = None, scales: Optional[Var] = None, sizes: Optional[Var] = None, *, antialias: int = 0, axes: Optional[Iterable[int]] = None, coordinate_transformation_mode: str = "half_pixel", cubic_coeff_a: float = -0.75, exclude_outside: int = 0, extrapolation_value: float = 0.0, keep_aspect_ratio_policy: str = "stretch", mode: str = "nearest", nearest_mode: str = "round_prefer_floor", ) -> Var: r""" - Resize the input tensor. In general, it calculates every value in the - output tensor as a weighted average of neighborhood (a.k.a. sampling - locations) in the input tensor. Each dimension value of the output - tensor is: +Resize the input tensor. In general, it calculates every value in the +output tensor as a weighted average of neighborhood (a.k.a. sampling +locations) in the input tensor. Each dimension value of the output +tensor is: + +:: + + output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) + +if input "sizes" is not specified. + +Parameters +========== +X + Type T1. + N-D tensor +roi + Type T2. + 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is + the rank of X or the length of axes, if provided. The RoIs' coordinates + are normalized in the coordinate system of the input image. It only + takes effect when coordinate_transformation_mode is "tf_crop_and_resize" +scales + Type tensor(float). + The scale array along each dimension. It takes value greater than 0. If + it's less than 1, it's sampling down, otherwise, it's upsampling. The + number of elements of 'scales' should be the same as the rank of input + 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' + MUST be specified and it is an error if both are specified. If 'sizes' + is needed, the user can use an empty string as the name of 'scales' in + this operator's input list. +sizes + Type tensor(int64). + Target size of the output tensor. Its interpretation depends on the + 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' + should be the same as the rank of input 'X', or the length of 'axes', if + provided. Only one of 'scales' and 'sizes' can be specified. +antialias + Attribute. + If set to 1, "linear" and "cubic" interpolation modes will use an + antialiasing filter when downscaling. Antialiasing is achieved by + stretching the resampling filter by a factor max(1, 1 / scale), which + means that when downsampling, more input pixels contribute to an output + pixel. +axes + Attribute. + If provided, it specifies a subset of axes that 'roi', 'scales' and + 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., + r-1], where r = rank(data). Non-specified dimensions are interpreted as + non-resizable. Negative value means counting dimensions from the back. + Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined + if an axis is repeated. +coordinate_transformation_mode + Attribute. + This attribute describes how to transform the coordinate in the resized + tensor to the coordinate in the original tensor. + + The coordinate of each dimension is transformed individually. Let's + describe a case using axis x as an example. Denote ``x_resized`` as the + coordinate of axis x in the resized tensor, ``x_original`` as the + coordinate of axis x in the original tensor, ``length_original`` as the + length of the original tensor in axis x, ``length_resized`` as the + length of the resized tensor in axis x, + ``scale = length_resized / length_original``, ``output_width`` the + target length on the axis x which can be a fractional number when it is + calculated out of a scale factor, and ``output_width_int`` the effective + output width as an integer. + + if coordinate_transformation_mode is ``"half_pixel"``, :: - output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) - - if input "sizes" is not specified. - - Parameters - ========== - X - Type T1. - N-D tensor - roi - Type T2. - 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is - the rank of X or the length of axes, if provided. The RoIs' coordinates - are normalized in the coordinate system of the input image. It only - takes effect when coordinate_transformation_mode is "tf_crop_and_resize" - scales - Type tensor(float). - The scale array along each dimension. It takes value greater than 0. If - it's less than 1, it's sampling down, otherwise, it's upsampling. The - number of elements of 'scales' should be the same as the rank of input - 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' - MUST be specified and it is an error if both are specified. If 'sizes' - is needed, the user can use an empty string as the name of 'scales' in - this operator's input list. - sizes - Type tensor(int64). - Target size of the output tensor. Its interpretation depends on the - 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' - should be the same as the rank of input 'X', or the length of 'axes', if - provided. Only one of 'scales' and 'sizes' can be specified. - antialias - Attribute. - If set to 1, "linear" and "cubic" interpolation modes will use an - antialiasing filter when downscaling. Antialiasing is achieved by - stretching the resampling filter by a factor max(1, 1 / scale), which - means that when downsampling, more input pixels contribute to an output - pixel. - axes - Attribute. - If provided, it specifies a subset of axes that 'roi', 'scales' and - 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., - r-1], where r = rank(data). Non-specified dimensions are interpreted as - non-resizable. Negative value means counting dimensions from the back. - Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined - if an axis is repeated. - coordinate_transformation_mode - Attribute. - This attribute describes how to transform the coordinate in the resized - tensor to the coordinate in the original tensor. - - The coordinate of each dimension is transformed individually. Let's - describe a case using axis x as an example. Denote ``x_resized`` as the - coordinate of axis x in the resized tensor, ``x_original`` as the - coordinate of axis x in the original tensor, ``length_original`` as the - length of the original tensor in axis x, ``length_resized`` as the - length of the resized tensor in axis x, - ``scale = length_resized / length_original``, ``output_width`` the - target length on the axis x which can be a fractional number when it is - calculated out of a scale factor, and ``output_width_int`` the effective - output width as an integer. - - if coordinate_transformation_mode is ``"half_pixel"``, - - :: - - x_original = (x_resized + 0.5) / scale - 0.5 - - if coordinate_transformation_mode is ``"half_pixel_symmetric"``, - - :: - - adjustment = output_width_int / output_width - center = input_width / 2 - offset = center * (1 - adjustment) - x_ori = offset + (x + 0.5) / scale - 0.5 - - if coordinate_transformation_mode is ``"pytorch_half_pixel"``, - - :: - - x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0 - - if coordinate_transformation_mode is ``"align_corners"``, - - :: - - x_original = x_resized * (length_original - 1) / (length_resized - 1) - - if coordinate_transformation_mode is ``"asymmetric"``, - - :: - - x_original = x_resized / scale - - if coordinate_transformation_mode is ``"tf_crop_and_resize"``, - - :: - - x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1) - - . - cubic_coeff_a - Attribute. - The coefficient 'a' used in cubic interpolation. Two common choice are - -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out - Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the - details. This attribute is valid only if mode is "cubic". - exclude_outside - Attribute. - If set to 1, the weight of sampling locations outside the tensor will be - set to 0 and the weight will be renormalized so that their sum is 1.0. - The default value is 0. - extrapolation_value - Attribute. - When coordinate_transformation_mode is "tf_crop_and_resize" and - x_original is outside the range [0, length_original - 1], this value is - used as the corresponding output value. Default is 0.0f. - keep_aspect_ratio_policy - Attribute. - This attribute describes how to interpret the ``sizes`` input with - regard to keeping the original aspect ratio of the input, and it is not - applicable when the ``scales`` input is used. - - Given a set of ``sizes``, associated with a subset of ``axes`` - (explicitly provided or default), and assuming ``d = axes[i]``, with - ``i`` being the index of the provided ``sizes``. - - If ``keep_aspect_ratio_policy`` is ``"stretch"``, the original aspect - ratio is disregarded, and the input is resized to the specified size: - ``out_size[d] = sizes[i]`` - - If ``keep_aspect_ratio_policy`` is ``"not_larger"``, the sizes are - adjusted so that no extent of the output is larger than the specified - size, while keeping the original aspect ratio: - - :: - - scale = Min(sizes[i] / in_size[d]) - out_size[d] = round_int(scale * in_size[i]) - - If ``keep_aspect_ratio_policy`` is ``"not_smaller"``, the sizes are - adjusted so that no extent of the output is smaller than the specified - size, while keeping the original aspect ratio: - - :: - - scale = Max(sizes[i] / in_size[d]) - out_size[d] = round_int(scale * in_size[i]) + x_original = (x_resized + 0.5) / scale - 0.5 - For non-resizable axes (those not specified in ``axes``), the output - size will be equal to the input size. - - Note: ``round_int`` stands for computing the nearest integer value, - rounding halfway cases up. - mode - Attribute. - Three interpolation modes: "nearest" (default), "linear" and "cubic". - The "linear" mode includes linear interpolation for 1D tensor and - N-linear interpolation for N-D tensor (for example, bilinear - interpolation for 2D tensor). The "cubic" mode includes cubic - interpolation for 1D tensor and N-cubic interpolation for N-D tensor - (for example, bicubic interpolation for 2D tensor). - nearest_mode - Attribute. - Four modes: "round_prefer_floor" (default, as known as round half down), - "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only - used by nearest interpolation. It indicates how to get "nearest" pixel - in input tensor from x_original, so this attribute is valid only if - "mode" is "nearest". - - Returns - ======= - Y : Var - Type T1. - N-D tensor after resizing - - Notes - ===== - Signature: ``ai.onnx@19::Resize``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return ( - _Resize( - _Resize.Attributes( - antialias=AttrInt64(antialias, name="antialias"), - axes=AttrInt64s.maybe(axes, name="axes"), - coordinate_transformation_mode=AttrString( - coordinate_transformation_mode, - name="coordinate_transformation_mode", - ), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32( - extrapolation_value, name="extrapolation_value" - ), - keep_aspect_ratio_policy=AttrString( - keep_aspect_ratio_policy, name="keep_aspect_ratio_policy" - ), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), - _Resize.Inputs( - X=unwrap_vars(X), - roi=unwrap_vars(roi), - scales=unwrap_vars(scales), - sizes=unwrap_vars(sizes), - ), - ) - .get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), - ) - .Y - ) - - -def scan( - initial_state_and_scan_inputs: Sequence[Var], - *, - body: Callable[..., Iterable[Var]], - num_scan_inputs: int, - scan_input_axes: Optional[Iterable[int]] = None, - scan_input_directions: Optional[Iterable[int]] = None, - scan_output_axes: Optional[Iterable[int]] = None, - scan_output_directions: Optional[Iterable[int]] = None, -) -> Sequence[Var]: - r""" - Scan can be used to iterate over one or more scan_input tensors, - constructing zero or more scan_output tensors. It combines ideas from - general recurrences, functional programming constructs such as scan, - fold, map, and zip, and is intended to enable generalizations of - RNN-like constructs for sequence-to-sequence processing. Other tensors - (referred to as state_variables here) can be used to carry a state when - iterating from one element to another (similar to hidden-state in RNNs, - also referred to as loop-carried dependences in the context of loops). - Many common usages involve a single scan_input tensor (where - functionality similar to scan, fold and map can be obtained). When more - than one scan_input is used, a behavior similar to zip is obtained. - - The attribute body must be a graph, specifying the computation to be - performed in every iteration. It takes as input the current values of - the state_variables and the current iterated element of the scan_inputs. - It must return the (updated) values of the state_variables and zero or - more scan_output_element tensors. The values of the scan_output_element - tensors are concatenated over all the iterations to produce the - scan_output values of the scan construct (similar to the concatenated - intermediate hidden-state values of RNN-like constructs). All the output - tensors (state_variables as well as scan_output_element tensors) are - required to have the same shape in each iteration of the loop (a - restriction imposed to enable efficient memory allocation). - - Note that the iterated element passed to the body subgraph does not have - a sequence axis. It will have a rank one less than the rank of the - corresponding scan_input. - - The scan operation returns the final values of the state_variables as - well as the scan_outputs. - - The optional attribute scan_input_directions specifies the direction - (forward or backward) for each scan input. If this attribute is omitted, - all sequences are scanned in the forward direction. A bidirectional scan - may be performed by specifying the same tensor input twice in the - scan_inputs, once with a forward direction, and once with a backward - direction. - - The scan_output of the operation is produced by concatenating the - scan_output_element values produced by the body in each iteration. The - optional attribute scan_output_directions specifies the direction in - which scan_output is constructed (by appending or prepending the - scan_output_element to scan_output in each iteration) for each - scan_output. If this attribute is omitted, the scan_output_element is - appended to the scan_output in each iteration. - - The optional attribute scan_input_axes specifies the axis to be scanned - for each scan_input. If omitted, every scan_input will be scanned in - axis 0. For example, if axis 0 is the batch axis and axis 1 is the time - axis (to be scanned), specify an axis value of 1. Note that scanning a - non-zero axis may be less efficient than scanning axis zero. - - The optional attribute scan_output_axes specifies the axis along which - the scan_outputs are accumulated for each scan_output. For example, if - axis 1 is the time axis (to be scanned) for both inputs and outputs, - specify a scan_input axis and scan_output axis value of 1. - - Note that because of the ONNX restriction that only the last parameter - of an operator can be variadic, the initial-states and scan-inputs are - listed together as one input parameter. Similarly, the final-states and - scan-outputs are listed together as one output parameter. The attribute - num_scan_inputs indicates the number M of scan-inputs. - - The behavior of + if coordinate_transformation_mode is ``"half_pixel_symmetric"``, :: - Scan < - num_scan_inputs = m, - body = loop-body, - scan_input_axes = [axis_1, ..., axis_m] - > (init_1, ..., init_n, scan_1, ..., scan_m) + adjustment = output_width_int / output_width + center = input_width / 2 + offset = center * (1 - adjustment) + x_ori = offset + (x + 0.5) / scale - 0.5 - is equivalent to the following pseudo-code: + if coordinate_transformation_mode is ``"pytorch_half_pixel"``, :: - // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i - // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. - sequence_length = scan_1.shape[axis_1]; - - // initialize state-variables - st_1 = init_1; ... st_n = init_n; - // initialize scan-output variables: [] denotes an empty tensor - scan_out_1 = []; ...; scan_out_k = []; - // identify number of iterations: - - // execute loop - for (int t = 0; t < sequence_length; ++t) { - // generate the scan-input elements: the notation T[t] indicates the sub-tensor - // of rank one less than T obtained by indexing T at position t along axis k. - si_1 = scan_1[t]; - ... ; - si_m = scan_m[t]; - // execute loop-body - st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) - // accumulate the scan-output elements - scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); - } - - return st_1, ..., st_n, scan_out_1, ..., scan_out_k; - - *Sample usage: Encoding RNN using a Scan* - - The following example shows how a simple RNN over an input tensor %X, - with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi - and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. - Note that the loop-body is a nested graph, and it directly computes %Wi, - %Ri, %Wbi, and %Rbi (typically constants or initializers in the body - graph). If these values are computed in the outer graph, they need to be - passed in as extra state_variables. + x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0 - :: + if coordinate_transformation_mode is ``"align_corners"``, - graph rnn-encoding { - %H_0 = ... - %X = ... - %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) - return %Y, %Y_h - } - - graph rnn-cell-1 ( - %H_tminus1[FLOAT, tensor] - %X_t[FLOAT, tensor] - ) { - %Wi = ... - %Ri = ... - %Wbi = ... - %Rbi = ... - %t1 = X_t * (Wi^T) - %t2 = H_tminus1*(Ri^T) - %t3 = Add(%t1, %t2) - %t4 = Add(%t3, %Wbi) - %t5 = Add(%t4, %Rbi) - %Ht = Tanh(%t5) - %Accumulate = Identity(%Ht) - return %Ht, %Accumulate - } - - Parameters - ========== - initial_state_and_scan_inputs - Type V. - Initial values of the loop's N state variables followed by M scan_inputs - body - Attribute. - The graph run each iteration. It has N+M inputs: (loop state - variables..., scan_input_elts...). It has N+K outputs: (loop state - variables..., scan_output_elts...). Each scan_output is created by - concatenating the value of the specified scan_output_elt value at the - end of each iteration of the loop. It is an error if the dimensions of - these values change across loop iterations. - num_scan_inputs - Attribute. - An attribute specifying the number of scan_inputs M. - scan_input_axes - Attribute. - An optional list of M flags. The i-th element of the list specifies the - axis to be scanned (the sequence axis) for the i-th scan_input. If - omitted, 0 will be used as the scan axis for every scan_input. Negative - value for an axis means counting dimensions from the back. Accepted - range is [-r, r-1] where r = rank(input). - scan_input_directions - Attribute. - An optional list of M flags. The i-th element of the list specifies the - direction to be scanned for the i-th scan_input tensor: 0 indicates - forward direction and 1 indicates reverse direction. If omitted, all - scan_input tensors will be scanned in the forward direction. - scan_output_axes - Attribute. - An optional list of K flags. The i-th element of the list specifies the - axis for the i-th scan_output. The scan outputs are accumulated along - the specified axis. If omitted, 0 will be used as the scan axis for - every scan_output. Negative value for an axis means counting dimensions - from the back. Accepted range is [-r, r-1]. - scan_output_directions - Attribute. - An optional list of K flags, one for each scan_output. The i-th element - of the list specifies whether the i-th scan_output should be constructed - by appending or prepending a new value in each iteration: 0 indicates - appending and 1 indicates prepending. If omitted, all scan_output - tensors will be produced by appending a value in each iteration. - - Returns - ======= - final_state_and_scan_outputs : Sequence[Var] - Type V. - Final values of the loop's N state variables followed by K scan_outputs - - Notes - ===== - Signature: ``ai.onnx@19::Scan``. - - Type constraints: - - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _body_subgraph: Graph = subgraph( - [ - Tensor( - var.unwrap_tensor().dtype, - (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape), - ) - for var in initial_state_and_scan_inputs[:num_scan_inputs] - ] - + [ - Tensor(var.unwrap_tensor().dtype) - for var in initial_state_and_scan_inputs[num_scan_inputs:] - ], - body, - ) - return ( - _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe( - scan_input_axes, name="scan_input_axes" - ), - scan_input_directions=AttrInt64s.maybe( - scan_input_directions, name="scan_input_directions" - ), - scan_output_axes=AttrInt64s.maybe( - scan_output_axes, name="scan_output_axes" - ), - scan_output_directions=AttrInt64s.maybe( - scan_output_directions, name="scan_output_directions" - ), - ), - _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars( - initial_state_and_scan_inputs - ), - ), - out_variadic=len(_body_subgraph.requested_results), - ) - .get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), - ) - .final_state_and_scan_outputs - ) + :: + x_original = x_resized * (length_original - 1) / (length_resized - 1) -def shape( - data: Var, - *, - end: Optional[int] = None, - start: int = 0, -) -> Var: - r""" - Takes a tensor as input and outputs an 1D int64 tensor containing the - shape of the input tensor. Optional attributes start and end can be used - to compute a slice of the input tensor's shape. If start axis is - omitted, the slice starts from axis 0. The end axis, if specified, is - exclusive (and the returned value will not include the size of that - axis). If the end axis is omitted, the axes upto the last one will be - included. Negative axes indicate counting back from the last axis. Note - that axes will be clamped to the range [0, r-1], where r is the rank of - the input tensor if they are out-of-range (after adding r in the case of - negative axis). Thus, specifying any end value > r is equivalent to - specifying an end value of r, and specifying any start value < -r is - equivalent to specifying a start value of 0. - - Examples: + if coordinate_transformation_mode is ``"asymmetric"``, :: - Input tensor with shape: [2, 3, 4] - No attributes specified. - Output: [2, 3, 4] + x_original = x_resized / scale + + if coordinate_transformation_mode is ``"tf_crop_and_resize"``, :: - Input tensor with shape: [2, 3, 4] - start: -1 - Output: [4] + x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1) + + . +cubic_coeff_a + Attribute. + The coefficient 'a' used in cubic interpolation. Two common choice are + -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out + Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the + details. This attribute is valid only if mode is "cubic". +exclude_outside + Attribute. + If set to 1, the weight of sampling locations outside the tensor will be + set to 0 and the weight will be renormalized so that their sum is 1.0. + The default value is 0. +extrapolation_value + Attribute. + When coordinate_transformation_mode is "tf_crop_and_resize" and + x_original is outside the range [0, length_original - 1], this value is + used as the corresponding output value. Default is 0.0f. +keep_aspect_ratio_policy + Attribute. + This attribute describes how to interpret the ``sizes`` input with + regard to keeping the original aspect ratio of the input, and it is not + applicable when the ``scales`` input is used. + + Given a set of ``sizes``, associated with a subset of ``axes`` + (explicitly provided or default), and assuming ``d = axes[i]``, with + ``i`` being the index of the provided ``sizes``. + + If ``keep_aspect_ratio_policy`` is ``"stretch"``, the original aspect + ratio is disregarded, and the input is resized to the specified size: + ``out_size[d] = sizes[i]`` + + If ``keep_aspect_ratio_policy`` is ``"not_larger"``, the sizes are + adjusted so that no extent of the output is larger than the specified + size, while keeping the original aspect ratio: :: - Input tensor with shape: [2, 3, 4] - end: -1 - Output: [2, 3] + scale = Min(sizes[i] / in_size[d]) + out_size[d] = round_int(scale * in_size[i]) + + If ``keep_aspect_ratio_policy`` is ``"not_smaller"``, the sizes are + adjusted so that no extent of the output is smaller than the specified + size, while keeping the original aspect ratio: :: - Input tensor with shape: [2, 3, 4] - start: 1 - end: 2 - Output: [3] - - Parameters - ========== - data - Type T. - An input tensor. - end - Attribute. - (Optional) Ending axis for slicing the shape. Negative value means - counting dimensions from the back. If omitted, sizes of all axes upto - (including) the last one will be included. - start - Attribute. - (Optional) Starting axis for slicing the shape. Default value is - 0.Negative value means counting dimensions from the back. - - Returns - ======= - shape : Var - Type T1. - Shape of the input tensor - - Notes - ===== - Signature: ``ai.onnx@19::Shape``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` + scale = Max(sizes[i] / in_size[d]) + out_size[d] = round_int(scale * in_size[i]) + + For non-resizable axes (those not specified in ``axes``), the output + size will be equal to the input size. + + Note: ``round_int`` stands for computing the nearest integer value, + rounding halfway cases up. +mode + Attribute. + Three interpolation modes: "nearest" (default), "linear" and "cubic". + The "linear" mode includes linear interpolation for 1D tensor and + N-linear interpolation for N-D tensor (for example, bilinear + interpolation for 2D tensor). The "cubic" mode includes cubic + interpolation for 1D tensor and N-cubic interpolation for N-D tensor + (for example, bicubic interpolation for 2D tensor). +nearest_mode + Attribute. + Four modes: "round_prefer_floor" (default, as known as round half down), + "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only + used by nearest interpolation. It indicates how to get "nearest" pixel + in input tensor from x_original, so this attribute is valid only if + "mode" is "nearest". + +Returns +======= +Y : Var + Type T1. + N-D tensor after resizing + +Notes +===== +Signature: ``ai.onnx@19::Resize``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return _Resize( + _Resize.Attributes( + antialias=AttrInt64(antialias, name="antialias"), + axes=AttrInt64s.maybe(axes, name="axes"), + coordinate_transformation_mode=AttrString(coordinate_transformation_mode, name="coordinate_transformation_mode"), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32(extrapolation_value, name="extrapolation_value"), + keep_aspect_ratio_policy=AttrString(keep_aspect_ratio_policy, name="keep_aspect_ratio_policy"), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), + ), _Resize.Inputs( + X=unwrap_vars(X), roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), ).get_output_vars( + X=get_value(X), roi=get_value(roi), scales=get_value(scales), sizes=get_value(sizes), ).Y + + +def scan(initial_state_and_scan_inputs: Sequence[Var], *, body: Callable[..., Iterable[Var]], num_scan_inputs: int, scan_input_axes: Optional[Iterable[int]] = None, scan_input_directions: Optional[Iterable[int]] = None, scan_output_axes: Optional[Iterable[int]] = None, scan_output_directions: Optional[Iterable[int]] = None, ) -> Sequence[Var]: + r""" +Scan can be used to iterate over one or more scan_input tensors, +constructing zero or more scan_output tensors. It combines ideas from +general recurrences, functional programming constructs such as scan, +fold, map, and zip, and is intended to enable generalizations of +RNN-like constructs for sequence-to-sequence processing. Other tensors +(referred to as state_variables here) can be used to carry a state when +iterating from one element to another (similar to hidden-state in RNNs, +also referred to as loop-carried dependences in the context of loops). +Many common usages involve a single scan_input tensor (where +functionality similar to scan, fold and map can be obtained). When more +than one scan_input is used, a behavior similar to zip is obtained. + +The attribute body must be a graph, specifying the computation to be +performed in every iteration. It takes as input the current values of +the state_variables and the current iterated element of the scan_inputs. +It must return the (updated) values of the state_variables and zero or +more scan_output_element tensors. The values of the scan_output_element +tensors are concatenated over all the iterations to produce the +scan_output values of the scan construct (similar to the concatenated +intermediate hidden-state values of RNN-like constructs). All the output +tensors (state_variables as well as scan_output_element tensors) are +required to have the same shape in each iteration of the loop (a +restriction imposed to enable efficient memory allocation). + +Note that the iterated element passed to the body subgraph does not have +a sequence axis. It will have a rank one less than the rank of the +corresponding scan_input. + +The scan operation returns the final values of the state_variables as +well as the scan_outputs. + +The optional attribute scan_input_directions specifies the direction +(forward or backward) for each scan input. If this attribute is omitted, +all sequences are scanned in the forward direction. A bidirectional scan +may be performed by specifying the same tensor input twice in the +scan_inputs, once with a forward direction, and once with a backward +direction. + +The scan_output of the operation is produced by concatenating the +scan_output_element values produced by the body in each iteration. The +optional attribute scan_output_directions specifies the direction in +which scan_output is constructed (by appending or prepending the +scan_output_element to scan_output in each iteration) for each +scan_output. If this attribute is omitted, the scan_output_element is +appended to the scan_output in each iteration. + +The optional attribute scan_input_axes specifies the axis to be scanned +for each scan_input. If omitted, every scan_input will be scanned in +axis 0. For example, if axis 0 is the batch axis and axis 1 is the time +axis (to be scanned), specify an axis value of 1. Note that scanning a +non-zero axis may be less efficient than scanning axis zero. + +The optional attribute scan_output_axes specifies the axis along which +the scan_outputs are accumulated for each scan_output. For example, if +axis 1 is the time axis (to be scanned) for both inputs and outputs, +specify a scan_input axis and scan_output axis value of 1. + +Note that because of the ONNX restriction that only the last parameter +of an operator can be variadic, the initial-states and scan-inputs are +listed together as one input parameter. Similarly, the final-states and +scan-outputs are listed together as one output parameter. The attribute +num_scan_inputs indicates the number M of scan-inputs. + +The behavior of + +:: + + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) + +is equivalent to the following pseudo-code: + +:: + + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + +*Sample usage: Encoding RNN using a Scan* + +The following example shows how a simple RNN over an input tensor %X, +with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi +and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. +Note that the loop-body is a nested graph, and it directly computes %Wi, +%Ri, %Wbi, and %Rbi (typically constants or initializers in the body +graph). If these values are computed in the outer graph, they need to be +passed in as extra state_variables. + +:: + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + +Parameters +========== +initial_state_and_scan_inputs + Type V. + Initial values of the loop's N state variables followed by M scan_inputs +body + Attribute. + The graph run each iteration. It has N+M inputs: (loop state + variables..., scan_input_elts...). It has N+K outputs: (loop state + variables..., scan_output_elts...). Each scan_output is created by + concatenating the value of the specified scan_output_elt value at the + end of each iteration of the loop. It is an error if the dimensions of + these values change across loop iterations. +num_scan_inputs + Attribute. + An attribute specifying the number of scan_inputs M. +scan_input_axes + Attribute. + An optional list of M flags. The i-th element of the list specifies the + axis to be scanned (the sequence axis) for the i-th scan_input. If + omitted, 0 will be used as the scan axis for every scan_input. Negative + value for an axis means counting dimensions from the back. Accepted + range is [-r, r-1] where r = rank(input). +scan_input_directions + Attribute. + An optional list of M flags. The i-th element of the list specifies the + direction to be scanned for the i-th scan_input tensor: 0 indicates + forward direction and 1 indicates reverse direction. If omitted, all + scan_input tensors will be scanned in the forward direction. +scan_output_axes + Attribute. + An optional list of K flags. The i-th element of the list specifies the + axis for the i-th scan_output. The scan outputs are accumulated along + the specified axis. If omitted, 0 will be used as the scan axis for + every scan_output. Negative value for an axis means counting dimensions + from the back. Accepted range is [-r, r-1]. +scan_output_directions + Attribute. + An optional list of K flags, one for each scan_output. The i-th element + of the list specifies whether the i-th scan_output should be constructed + by appending or prepending a new value in each iteration: 0 indicates + appending and 1 indicates prepending. If omitted, all scan_output + tensors will be produced by appending a value in each iteration. + +Returns +======= +final_state_and_scan_outputs : Sequence[Var] + Type V. + Final values of the loop's N state variables followed by K scan_outputs + +Notes +===== +Signature: ``ai.onnx@19::Scan``. + +Type constraints: + - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), - _Shape.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .shape + _body_subgraph: Graph = subgraph( + [Tensor(var.unwrap_tensor().dtype, (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape)) for var in initial_state_and_scan_inputs[:num_scan_inputs]] + [Tensor(var.unwrap_tensor().dtype) for var in initial_state_and_scan_inputs[num_scan_inputs:]], + body ) + return _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), + scan_input_directions=AttrInt64s.maybe(scan_input_directions, name="scan_input_directions"), + scan_output_axes=AttrInt64s.maybe(scan_output_axes, name="scan_output_axes"), + scan_output_directions=AttrInt64s.maybe(scan_output_directions, name="scan_output_directions"), + ), _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), ).final_state_and_scan_outputs + + +def shape(data: Var, *, end: Optional[int] = None, start: int = 0, ) -> Var: + r""" +Takes a tensor as input and outputs an 1D int64 tensor containing the +shape of the input tensor. Optional attributes start and end can be used +to compute a slice of the input tensor's shape. If start axis is +omitted, the slice starts from axis 0. The end axis, if specified, is +exclusive (and the returned value will not include the size of that +axis). If the end axis is omitted, the axes upto the last one will be +included. Negative axes indicate counting back from the last axis. Note +that axes will be clamped to the range [0, r-1], where r is the rank of +the input tensor if they are out-of-range (after adding r in the case of +negative axis). Thus, specifying any end value > r is equivalent to +specifying an end value of r, and specifying any start value < -r is +equivalent to specifying a start value of 0. + +Examples: + +:: + + Input tensor with shape: [2, 3, 4] + No attributes specified. + Output: [2, 3, 4] + +:: + + Input tensor with shape: [2, 3, 4] + start: -1 + Output: [4] + +:: + + Input tensor with shape: [2, 3, 4] + end: -1 + Output: [2, 3] + +:: + + Input tensor with shape: [2, 3, 4] + start: 1 + end: 2 + Output: [3] + +Parameters +========== +data + Type T. + An input tensor. +end + Attribute. + (Optional) Ending axis for slicing the shape. Negative value means + counting dimensions from the back. If omitted, sizes of all axes upto + (including) the last one will be included. +start + Attribute. + (Optional) Starting axis for slicing the shape. Default value is + 0.Negative value means counting dimensions from the back. + +Returns +======= +shape : Var + Type T1. + Shape of the input tensor + +Notes +===== +Signature: ``ai.onnx@19::Shape``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` + """ + return _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), _Shape.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).shape -def size( - data: Var, -) -> Var: +def size(data: Var, ) -> Var: r""" - Takes a tensor as input and outputs a int64 scalar that equals to the - total number of elements of the input tensor. - - Parameters - ========== - data - Type T. - An input tensor. - - Returns - ======= - size : Var - Type T1. - Total number of elements of the input tensor - - Notes - ===== - Signature: ``ai.onnx@19::Size``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` +Takes a tensor as input and outputs a int64 scalar that equals to the +total number of elements of the input tensor. + +Parameters +========== +data + Type T. + An input tensor. + +Returns +======= +size : Var + Type T1. + Total number of elements of the input tensor + +Notes +===== +Signature: ``ai.onnx@19::Size``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` """ - return ( - _Size( - _Size.Attributes(), - _Size.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .size - ) + return _Size( + _Size.Attributes( + ), _Size.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).size def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -3134,4 +2637,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 0e1d406a..004b613b 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -1,384 +1,219 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: BSD-3-Clause - # ruff: noqa: E741 -- Allow ambiguous variable name +import typing +import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( + Any, + Callable, Optional, + Union, ) +from typing import cast as typing_cast import numpy as np import numpy.typing as npt +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( + AttrDtype, + AttrFloat32, + AttrFloat32s, + AttrGraph, AttrInt64, + AttrInt64s, AttrString, + AttrStrings, AttrTensor, + AttrType, ) -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs +from spox._graph import Graph, subgraph +from spox._internal_op import intro from spox._node import OpType -from spox._standard import StandardNode -from spox._var import Var, VarInfo, get_value, unwrap_vars -from spox.opset.ai.onnx.v19 import ( - _GRU, - _LRN, - _LSTM, - _RNN, - _STFT, - _Abs, - _Acos, - _Acosh, - _Add, - _And, - _ArgMax, - _ArgMin, - _Asin, - _Asinh, - _Atan, - _Atanh, - _AveragePool, - _BatchNormalization, - _Bernoulli, - _BitShift, - _BitwiseAnd, - _BitwiseNot, - _BitwiseOr, - _BitwiseXor, - _BlackmanWindow, - _Cast, - _CastLike, - _Ceil, - _Celu, - _CenterCropPad, - _Clip, - _Col2Im, - _Compress, - _Concat, - _ConcatFromSequence, - _Constant, - _Conv, - _ConvInteger, - _ConvTranspose, - _Cos, - _Cosh, - _CumSum, - _DeformConv, - _DepthToSpace, - _DequantizeLinear, - _Det, - _Div, - _Dropout, - _DynamicQuantizeLinear, - _Einsum, - _Elu, - _Equal, - _Erf, - _Exp, - _Expand, - _EyeLike, - _Flatten, - _Floor, - _Gather, - _GatherElements, - _GatherND, - _Gemm, - _GlobalAveragePool, - _GlobalLpPool, - _GlobalMaxPool, - _Greater, - _GreaterOrEqual, - _GroupNormalization, - _HammingWindow, - _HannWindow, - _Hardmax, - _HardSigmoid, - _HardSwish, - _Identity, - _If, - _InstanceNormalization, - _LayerNormalization, - _LeakyRelu, - _Less, - _LessOrEqual, - _Log, - _LogSoftmax, - _Loop, - _LpNormalization, - _LpPool, - _MatMul, - _MatMulInteger, - _Max, - _MaxPool, - _MaxRoiPool, - _MaxUnpool, - _Mean, - _MeanVarianceNormalization, - _MelWeightMatrix, - _Min, - _Mish, - _Mod, - _Mul, - _Multinomial, - _Neg, - _NegativeLogLikelihoodLoss, - _NonMaxSuppression, - _NonZero, - _Not, - _OneHot, - _Optional, - _OptionalGetElement, - _OptionalHasElement, - _Or, - _Pad, - _Pow, - _PRelu, - _QLinearConv, - _QLinearMatMul, - _QuantizeLinear, - _RandomNormal, - _RandomNormalLike, - _RandomUniform, - _RandomUniformLike, - _Range, - _Reciprocal, - _ReduceL1, - _ReduceL2, - _ReduceLogSum, - _ReduceLogSumExp, - _ReduceMean, - _ReduceProd, - _ReduceSum, - _ReduceSumSquare, - _Relu, - _Reshape, - _Resize, - _ReverseSequence, - _RoiAlign, - _Round, - _Scan, - _ScatterElements, - _ScatterND, - _Selu, - _SequenceAt, - _SequenceConstruct, - _SequenceEmpty, - _SequenceErase, - _SequenceInsert, - _SequenceLength, - _SequenceMap, - _Shape, - _Shrink, - _Sigmoid, - _Sign, - _Sin, - _Sinh, - _Size, - _Slice, - _Softmax, - _SoftmaxCrossEntropyLoss, - _Softplus, - _Softsign, - _SpaceToDepth, - _Split, - _SplitToSequence, - _Sqrt, - _Squeeze, - _StringNormalizer, - _Sub, - _Sum, - _Tan, - _Tanh, - _TfIdfVectorizer, - _ThresholdedRelu, - _Tile, - _TopK, - _Transpose, - _Trilu, - _Unique, - _Unsqueeze, - _Where, - _Xor, - abs, - acos, - acosh, - add, - and_, - arg_max, - arg_min, - asin, - asinh, - atan, - atanh, - average_pool, - batch_normalization, - bernoulli, - bit_shift, - bitwise_and, - bitwise_not, - bitwise_or, - bitwise_xor, - blackman_window, - cast, - cast_like, - ceil, - celu, - center_crop_pad, - clip, - col2_im, - compress, - concat, - concat_from_sequence, - constant, - conv, - conv_integer, - conv_transpose, - cos, - cosh, - cumsum, - deform_conv, - depth_to_space, - dequantize_linear, - det, - div, - dropout, - dynamic_quantize_linear, - einsum, - elu, - equal, - erf, - exp, - expand, - eye_like, - flatten, - floor, - gather, - gather_elements, - gather_nd, - gemm, - global_average_pool, - global_lp_pool, - global_max_pool, - greater, - greater_or_equal, - group_normalization, - gru, - hamming_window, - hann_window, - hard_sigmoid, - hard_swish, - hardmax, - identity, - if_, - instance_normalization, - layer_normalization, - leaky_relu, - less, - less_or_equal, - log, - log_softmax, - loop, - lp_normalization, - lp_pool, - lrn, - lstm, - matmul, - matmul_integer, - max, - max_pool, - max_roi_pool, - max_unpool, - mean, - mean_variance_normalization, - mel_weight_matrix, - min, - mish, - mod, - mul, - multinomial, - neg, - negative_log_likelihood_loss, - non_max_suppression, - non_zero, - not_, - one_hot, - optional, - optional_get_element, - optional_has_element, - or_, - pad, - pow, - prelu, - qlinear_conv, - qlinear_matmul, - quantize_linear, - random_normal, - random_normal_like, - random_uniform, - random_uniform_like, - range, - reciprocal, - reduce_l1, - reduce_l2, - reduce_log_sum, - reduce_log_sum_exp, - reduce_mean, - reduce_prod, - reduce_sum, - reduce_sum_square, - relu, - reshape, - resize, - reverse_sequence, - rnn, - roi_align, - round, - scan, - scatter_elements, - scatter_nd, - selu, - sequence_at, - sequence_construct, - sequence_empty, - sequence_erase, - sequence_insert, - sequence_length, - sequence_map, - shape, - shrink, - sigmoid, - sign, - sin, - sinh, - size, - slice, - softmax, - softmax_cross_entropy_loss, - softplus, - softsign, - space_to_depth, - split, - split_to_sequence, - sqrt, - squeeze, - stft, - string_normalizer, - sub, - sum, - tan, - tanh, - tf_idf_vectorizer, - thresholded_relu, - tile, - top_k, - transpose, - trilu, - unique, - unsqueeze, - where, - xor, -) - - +from spox._standard import InferenceError, StandardNode +from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._value_prop import PropValueType + + +from spox.opset.ai.onnx.v19 import _Abs, abs +from spox.opset.ai.onnx.v19 import _Acos, acos +from spox.opset.ai.onnx.v19 import _Acosh, acosh +from spox.opset.ai.onnx.v19 import _Add, add +from spox.opset.ai.onnx.v19 import _And, and_ +from spox.opset.ai.onnx.v19 import _ArgMax, arg_max +from spox.opset.ai.onnx.v19 import _ArgMin, arg_min +from spox.opset.ai.onnx.v19 import _Asin, asin +from spox.opset.ai.onnx.v19 import _Asinh, asinh +from spox.opset.ai.onnx.v19 import _Atan, atan +from spox.opset.ai.onnx.v19 import _Atanh, atanh +from spox.opset.ai.onnx.v19 import _AveragePool, average_pool +from spox.opset.ai.onnx.v19 import _BatchNormalization, batch_normalization +from spox.opset.ai.onnx.v19 import _Bernoulli, bernoulli +from spox.opset.ai.onnx.v19 import _BitShift, bit_shift +from spox.opset.ai.onnx.v19 import _BitwiseAnd, bitwise_and +from spox.opset.ai.onnx.v19 import _BitwiseNot, bitwise_not +from spox.opset.ai.onnx.v19 import _BitwiseOr, bitwise_or +from spox.opset.ai.onnx.v19 import _BitwiseXor, bitwise_xor +from spox.opset.ai.onnx.v19 import _BlackmanWindow, blackman_window +from spox.opset.ai.onnx.v19 import _Cast, cast +from spox.opset.ai.onnx.v19 import _CastLike, cast_like +from spox.opset.ai.onnx.v19 import _Ceil, ceil +from spox.opset.ai.onnx.v19 import _Celu, celu +from spox.opset.ai.onnx.v19 import _CenterCropPad, center_crop_pad +from spox.opset.ai.onnx.v19 import _Clip, clip +from spox.opset.ai.onnx.v19 import _Col2Im, col2_im +from spox.opset.ai.onnx.v19 import _Compress, compress +from spox.opset.ai.onnx.v19 import _Concat, concat +from spox.opset.ai.onnx.v19 import _ConcatFromSequence, concat_from_sequence +from spox.opset.ai.onnx.v19 import _Constant, constant +from spox.opset.ai.onnx.v19 import _Conv, conv +from spox.opset.ai.onnx.v19 import _ConvInteger, conv_integer +from spox.opset.ai.onnx.v19 import _ConvTranspose, conv_transpose +from spox.opset.ai.onnx.v19 import _Cos, cos +from spox.opset.ai.onnx.v19 import _Cosh, cosh +from spox.opset.ai.onnx.v19 import _CumSum, cumsum +from spox.opset.ai.onnx.v19 import _DeformConv, deform_conv +from spox.opset.ai.onnx.v19 import _DepthToSpace, depth_to_space +from spox.opset.ai.onnx.v19 import _DequantizeLinear, dequantize_linear +from spox.opset.ai.onnx.v19 import _Det, det +from spox.opset.ai.onnx.v19 import _Div, div +from spox.opset.ai.onnx.v19 import _Dropout, dropout +from spox.opset.ai.onnx.v19 import _DynamicQuantizeLinear, dynamic_quantize_linear +from spox.opset.ai.onnx.v19 import _Einsum, einsum +from spox.opset.ai.onnx.v19 import _Elu, elu +from spox.opset.ai.onnx.v19 import _Equal, equal +from spox.opset.ai.onnx.v19 import _Erf, erf +from spox.opset.ai.onnx.v19 import _Exp, exp +from spox.opset.ai.onnx.v19 import _Expand, expand +from spox.opset.ai.onnx.v19 import _EyeLike, eye_like +from spox.opset.ai.onnx.v19 import _Flatten, flatten +from spox.opset.ai.onnx.v19 import _Floor, floor +from spox.opset.ai.onnx.v19 import _GRU, gru +from spox.opset.ai.onnx.v19 import _Gather, gather +from spox.opset.ai.onnx.v19 import _GatherElements, gather_elements +from spox.opset.ai.onnx.v19 import _GatherND, gather_nd +from spox.opset.ai.onnx.v19 import _Gemm, gemm +from spox.opset.ai.onnx.v19 import _GlobalAveragePool, global_average_pool +from spox.opset.ai.onnx.v19 import _GlobalLpPool, global_lp_pool +from spox.opset.ai.onnx.v19 import _GlobalMaxPool, global_max_pool +from spox.opset.ai.onnx.v19 import _Greater, greater +from spox.opset.ai.onnx.v19 import _GreaterOrEqual, greater_or_equal +from spox.opset.ai.onnx.v19 import _GroupNormalization, group_normalization +from spox.opset.ai.onnx.v19 import _HammingWindow, hamming_window +from spox.opset.ai.onnx.v19 import _HannWindow, hann_window +from spox.opset.ai.onnx.v19 import _HardSigmoid, hard_sigmoid +from spox.opset.ai.onnx.v19 import _HardSwish, hard_swish +from spox.opset.ai.onnx.v19 import _Hardmax, hardmax +from spox.opset.ai.onnx.v19 import _Identity, identity +from spox.opset.ai.onnx.v19 import _If, if_ +from spox.opset.ai.onnx.v19 import _InstanceNormalization, instance_normalization +from spox.opset.ai.onnx.v19 import _LRN, lrn +from spox.opset.ai.onnx.v19 import _LSTM, lstm +from spox.opset.ai.onnx.v19 import _LayerNormalization, layer_normalization +from spox.opset.ai.onnx.v19 import _LeakyRelu, leaky_relu +from spox.opset.ai.onnx.v19 import _Less, less +from spox.opset.ai.onnx.v19 import _LessOrEqual, less_or_equal +from spox.opset.ai.onnx.v19 import _Log, log +from spox.opset.ai.onnx.v19 import _LogSoftmax, log_softmax +from spox.opset.ai.onnx.v19 import _Loop, loop +from spox.opset.ai.onnx.v19 import _LpNormalization, lp_normalization +from spox.opset.ai.onnx.v19 import _LpPool, lp_pool +from spox.opset.ai.onnx.v19 import _MatMul, matmul +from spox.opset.ai.onnx.v19 import _MatMulInteger, matmul_integer +from spox.opset.ai.onnx.v19 import _Max, max +from spox.opset.ai.onnx.v19 import _MaxPool, max_pool +from spox.opset.ai.onnx.v19 import _MaxRoiPool, max_roi_pool +from spox.opset.ai.onnx.v19 import _MaxUnpool, max_unpool +from spox.opset.ai.onnx.v19 import _Mean, mean +from spox.opset.ai.onnx.v19 import _MeanVarianceNormalization, mean_variance_normalization +from spox.opset.ai.onnx.v19 import _MelWeightMatrix, mel_weight_matrix +from spox.opset.ai.onnx.v19 import _Min, min +from spox.opset.ai.onnx.v19 import _Mish, mish +from spox.opset.ai.onnx.v19 import _Mod, mod +from spox.opset.ai.onnx.v19 import _Mul, mul +from spox.opset.ai.onnx.v19 import _Multinomial, multinomial +from spox.opset.ai.onnx.v19 import _Neg, neg +from spox.opset.ai.onnx.v19 import _NegativeLogLikelihoodLoss, negative_log_likelihood_loss +from spox.opset.ai.onnx.v19 import _NonMaxSuppression, non_max_suppression +from spox.opset.ai.onnx.v19 import _NonZero, non_zero +from spox.opset.ai.onnx.v19 import _Not, not_ +from spox.opset.ai.onnx.v19 import _OneHot, one_hot +from spox.opset.ai.onnx.v19 import _Optional, optional +from spox.opset.ai.onnx.v19 import _OptionalGetElement, optional_get_element +from spox.opset.ai.onnx.v19 import _OptionalHasElement, optional_has_element +from spox.opset.ai.onnx.v19 import _Or, or_ +from spox.opset.ai.onnx.v19 import _PRelu, prelu +from spox.opset.ai.onnx.v19 import _Pad, pad +from spox.opset.ai.onnx.v19 import _Pow, pow +from spox.opset.ai.onnx.v19 import _QLinearConv, qlinear_conv +from spox.opset.ai.onnx.v19 import _QLinearMatMul, qlinear_matmul +from spox.opset.ai.onnx.v19 import _QuantizeLinear, quantize_linear +from spox.opset.ai.onnx.v19 import _RNN, rnn +from spox.opset.ai.onnx.v19 import _RandomNormal, random_normal +from spox.opset.ai.onnx.v19 import _RandomNormalLike, random_normal_like +from spox.opset.ai.onnx.v19 import _RandomUniform, random_uniform +from spox.opset.ai.onnx.v19 import _RandomUniformLike, random_uniform_like +from spox.opset.ai.onnx.v19 import _Range, range +from spox.opset.ai.onnx.v19 import _Reciprocal, reciprocal +from spox.opset.ai.onnx.v19 import _ReduceL1, reduce_l1 +from spox.opset.ai.onnx.v19 import _ReduceL2, reduce_l2 +from spox.opset.ai.onnx.v19 import _ReduceLogSum, reduce_log_sum +from spox.opset.ai.onnx.v19 import _ReduceLogSumExp, reduce_log_sum_exp +from spox.opset.ai.onnx.v19 import _ReduceMean, reduce_mean +from spox.opset.ai.onnx.v19 import _ReduceProd, reduce_prod +from spox.opset.ai.onnx.v19 import _ReduceSum, reduce_sum +from spox.opset.ai.onnx.v19 import _ReduceSumSquare, reduce_sum_square +from spox.opset.ai.onnx.v19 import _Relu, relu +from spox.opset.ai.onnx.v19 import _Reshape, reshape +from spox.opset.ai.onnx.v19 import _Resize, resize +from spox.opset.ai.onnx.v19 import _ReverseSequence, reverse_sequence +from spox.opset.ai.onnx.v19 import _RoiAlign, roi_align +from spox.opset.ai.onnx.v19 import _Round, round +from spox.opset.ai.onnx.v19 import _STFT, stft +from spox.opset.ai.onnx.v19 import _Scan, scan +from spox.opset.ai.onnx.v19 import _ScatterElements, scatter_elements +from spox.opset.ai.onnx.v19 import _ScatterND, scatter_nd +from spox.opset.ai.onnx.v19 import _Selu, selu +from spox.opset.ai.onnx.v19 import _SequenceAt, sequence_at +from spox.opset.ai.onnx.v19 import _SequenceConstruct, sequence_construct +from spox.opset.ai.onnx.v19 import _SequenceEmpty, sequence_empty +from spox.opset.ai.onnx.v19 import _SequenceErase, sequence_erase +from spox.opset.ai.onnx.v19 import _SequenceInsert, sequence_insert +from spox.opset.ai.onnx.v19 import _SequenceLength, sequence_length +from spox.opset.ai.onnx.v19 import _SequenceMap, sequence_map +from spox.opset.ai.onnx.v19 import _Shape, shape +from spox.opset.ai.onnx.v19 import _Shrink, shrink +from spox.opset.ai.onnx.v19 import _Sigmoid, sigmoid +from spox.opset.ai.onnx.v19 import _Sign, sign +from spox.opset.ai.onnx.v19 import _Sin, sin +from spox.opset.ai.onnx.v19 import _Sinh, sinh +from spox.opset.ai.onnx.v19 import _Size, size +from spox.opset.ai.onnx.v19 import _Slice, slice +from spox.opset.ai.onnx.v19 import _Softmax, softmax +from spox.opset.ai.onnx.v19 import _SoftmaxCrossEntropyLoss, softmax_cross_entropy_loss +from spox.opset.ai.onnx.v19 import _Softplus, softplus +from spox.opset.ai.onnx.v19 import _Softsign, softsign +from spox.opset.ai.onnx.v19 import _SpaceToDepth, space_to_depth +from spox.opset.ai.onnx.v19 import _Split, split +from spox.opset.ai.onnx.v19 import _SplitToSequence, split_to_sequence +from spox.opset.ai.onnx.v19 import _Sqrt, sqrt +from spox.opset.ai.onnx.v19 import _Squeeze, squeeze +from spox.opset.ai.onnx.v19 import _StringNormalizer, string_normalizer +from spox.opset.ai.onnx.v19 import _Sub, sub +from spox.opset.ai.onnx.v19 import _Sum, sum +from spox.opset.ai.onnx.v19 import _Tan, tan +from spox.opset.ai.onnx.v19 import _Tanh, tanh +from spox.opset.ai.onnx.v19 import _TfIdfVectorizer, tf_idf_vectorizer +from spox.opset.ai.onnx.v19 import _ThresholdedRelu, thresholded_relu +from spox.opset.ai.onnx.v19 import _Tile, tile +from spox.opset.ai.onnx.v19 import _TopK, top_k +from spox.opset.ai.onnx.v19 import _Transpose, transpose +from spox.opset.ai.onnx.v19 import _Trilu, trilu +from spox.opset.ai.onnx.v19 import _Unique, unique +from spox.opset.ai.onnx.v19 import _Unsqueeze, unsqueeze +from spox.opset.ai.onnx.v19 import _Where, where +from spox.opset.ai.onnx.v19 import _Xor, xor class _AffineGrid(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -399,7 +234,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ConstantOfShape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -419,7 +253,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _DFT(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -442,7 +275,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Gelu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -462,7 +294,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GridSample(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -485,7 +316,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ImageDecoder(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -505,7 +335,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _IsInf(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -526,7 +355,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _IsNaN(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -546,7 +374,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceMax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -568,7 +395,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _ReduceMin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -590,7 +416,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _RegexFullMatch(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -610,7 +435,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _StringConcat(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -631,7 +455,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _StringSplit(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -653,953 +476,770 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - -def affine_grid( - theta: Var, - size: Var, - *, - align_corners: int = 0, -) -> Var: +def affine_grid(theta: Var, size: Var, *, align_corners: int = 0, ) -> Var: r""" - Generates a 2D or 3D flow field (sampling grid), given a batch of affine - matrices theta - (https://pytorch.org/docs/stable/generated/torch.nn.functional.affine_grid.html). - An affine matrix ``theta`` is applied to a position tensor represented - in its homogeneous expression. Here is an example in 3D: - - :: - - [r00, r01, r02, t0] [x] [x'] - [r10, r11, r12, t1] * [y] = [y'] - [r20, r21, r22, t2] [z] [z'] - [0, 0, 0, 1 ] [1] [1 ] - - where ``(x, y, z)`` is the position in the original space, - ``(x', y', z')`` is the position in the output space. The last row is - always ``[0, 0, 0, 1]`` and is not stored in the affine matrix. - Therefore we have ``theta`` of shape ``(N, 2, 3)`` for 2D or - ``(N, 3, 4)`` for 3D. - - Input ``size`` is used to define grid of positions evenly spaced in the - original 2D or 3D space, with dimensions ranging from ``-1`` to ``1``. - The output ``grid`` contains positions in the output space. - - When ``align_corners=1``, consider ``-1`` and ``1`` to refer to the - centers of the corner pixels (mark ``v`` in illustration). - - :: - - v v v v - |-------------------|------------------| - -1 0 1 - - When ``align_corners=0``, consider ``-1`` and ``1`` to refer to the - outer edge of the corner pixels. - - :: - - v v v v - |------------------|-------------------| - -1 0 1 - - Parameters - ========== - theta - Type T1. - input batch of affine matrices with shape (N, 2, 3) for 2D or (N, 3, 4) - for 3D - size - Type T2. - the target output image size (N, C, H, W) for 2D or (N, C, D, H, W) for - 3D - align_corners - Attribute. - if align_corners=1, consider -1 and 1 to refer to the centers of the - corner pixels. if align_corners=0, consider -1 and 1 to refer to the - outer edge the corner pixels. - - Returns - ======= - grid : Var - Type T1. - output tensor of shape (N, H, W, 2) of 2D sample coordinates or (N, D, - H, W, 3) of 3D sample coordinates. - - Notes - ===== - Signature: ``ai.onnx@20::AffineGrid``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int64)` - """ - return ( - _AffineGrid( - _AffineGrid.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - ), - _AffineGrid.Inputs( - theta=unwrap_vars(theta), - size=unwrap_vars(size), - ), - ) - .get_output_vars( - theta=get_value(theta), - size=get_value(size), - ) - .grid - ) - - -def constant_of_shape( - input: Var, - *, - value: Optional[np.ndarray] = None, -) -> Var: - r""" - Generate a tensor with given value and shape. - - Parameters - ========== - input - Type T1. - 1D tensor. The shape of the expected output tensor. If empty tensor is - given, the output would be a scalar. All values must be >= 0. - value - Attribute. - (Optional) The value of the output elements.Should be a one-element - tensor. If not specified, it defaults to a tensor of value 0 and - datatype float32 - - Returns - ======= - output : Var - Type T2. - Output tensor of shape specified by 'input'.If attribute 'value' is - specified, the value and datatype of the output tensor is taken from - 'value'.If attribute 'value' is not specified, the value in the output - defaults to 0, and the datatype defaults to float32. - - Notes - ===== - Signature: ``ai.onnx@20::ConstantOfShape``. - - Type constraints: - - T1: `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Generates a 2D or 3D flow field (sampling grid), given a batch of affine +matrices theta +(https://pytorch.org/docs/stable/generated/torch.nn.functional.affine_grid.html). +An affine matrix ``theta`` is applied to a position tensor represented +in its homogeneous expression. Here is an example in 3D: + +:: + + [r00, r01, r02, t0] [x] [x'] + [r10, r11, r12, t1] * [y] = [y'] + [r20, r21, r22, t2] [z] [z'] + [0, 0, 0, 1 ] [1] [1 ] + +where ``(x, y, z)`` is the position in the original space, +``(x', y', z')`` is the position in the output space. The last row is +always ``[0, 0, 0, 1]`` and is not stored in the affine matrix. +Therefore we have ``theta`` of shape ``(N, 2, 3)`` for 2D or +``(N, 3, 4)`` for 3D. + +Input ``size`` is used to define grid of positions evenly spaced in the +original 2D or 3D space, with dimensions ranging from ``-1`` to ``1``. +The output ``grid`` contains positions in the output space. + +When ``align_corners=1``, consider ``-1`` and ``1`` to refer to the +centers of the corner pixels (mark ``v`` in illustration). + +:: + + v v v v + |-------------------|------------------| + -1 0 1 + +When ``align_corners=0``, consider ``-1`` and ``1`` to refer to the +outer edge of the corner pixels. + +:: + + v v v v + |------------------|-------------------| + -1 0 1 + +Parameters +========== +theta + Type T1. + input batch of affine matrices with shape (N, 2, 3) for 2D or (N, 3, 4) + for 3D +size + Type T2. + the target output image size (N, C, H, W) for 2D or (N, C, D, H, W) for + 3D +align_corners + Attribute. + if align_corners=1, consider -1 and 1 to refer to the centers of the + corner pixels. if align_corners=0, consider -1 and 1 to refer to the + outer edge the corner pixels. + +Returns +======= +grid : Var + Type T1. + output tensor of shape (N, H, W, 2) of 2D sample coordinates or (N, D, + H, W, 3) of 3D sample coordinates. + +Notes +===== +Signature: ``ai.onnx@20::AffineGrid``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int64)` """ - return ( - _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), - _ConstantOfShape.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) - - -def dft( - input: Var, - dft_length: Optional[Var] = None, - axis: Optional[Var] = None, - *, - inverse: int = 0, - onesided: int = 0, -) -> Var: - r""" - Computes the discrete Fourier Transform (DFT) of the input. - - Assuming the input has shape ``[M, N]``, where ``N`` is the dimension - over which the DFT is computed and ``M`` denotes the conceptual "all - other dimensions," the DFT ``y[m, k]`` of shape ``[M, N]`` is defined as - - .. math:: y[m, k] = \sum_{n=0}^{N-1} e^{-2 \pi j \frac{k n}{N} } x[m, n] , + return _AffineGrid( + _AffineGrid.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + ), _AffineGrid.Inputs( + theta=unwrap_vars(theta), size=unwrap_vars(size), ), ).get_output_vars( + theta=get_value(theta), size=get_value(size), ).grid - and the inverse transform is defined as - .. math:: x[m, n] = \frac{1}{N} \sum_{k=0}^{N-1} e^{2 \pi j \frac{k n}{N} } y[m, k] , +def constant_of_shape(input: Var, *, value: Optional[np.ndarray] = None, ) -> Var: + r""" +Generate a tensor with given value and shape. + +Parameters +========== +input + Type T1. + 1D tensor. The shape of the expected output tensor. If empty tensor is + given, the output would be a scalar. All values must be >= 0. +value + Attribute. + (Optional) The value of the output elements.Should be a one-element + tensor. If not specified, it defaults to a tensor of value 0 and + datatype float32 + +Returns +======= +output : Var + Type T2. + Output tensor of shape specified by 'input'.If attribute 'value' is + specified, the value and datatype of the output tensor is taken from + 'value'.If attribute 'value' is not specified, the value in the output + defaults to 0, and the datatype defaults to float32. + +Notes +===== +Signature: ``ai.onnx@20::ConstantOfShape``. + +Type constraints: + - T1: `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), _ConstantOfShape.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output - where :math:`j` is the imaginary unit. - The actual shape of the output is specified in the "output" section. +def dft(input: Var, dft_length: Optional[Var] = None, axis: Optional[Var] = None, *, inverse: int = 0, onesided: int = 0, ) -> Var: + r""" +Computes the discrete Fourier Transform (DFT) of the input. + +Assuming the input has shape ``[M, N]``, where ``N`` is the dimension +over which the DFT is computed and ``M`` denotes the conceptual "all +other dimensions," the DFT ``y[m, k]`` of shape ``[M, N]`` is defined as + +.. math:: y[m, k] = \sum_{n=0}^{N-1} e^{-2 \pi j \frac{k n}{N} } x[m, n] , + +and the inverse transform is defined as + +.. math:: x[m, n] = \frac{1}{N} \sum_{k=0}^{N-1} e^{2 \pi j \frac{k n}{N} } y[m, k] , + +where :math:`j` is the imaginary unit. + +The actual shape of the output is specified in the "output" section. + +Reference: https://docs.scipy.org/doc/scipy/tutorial/fft.html + +Parameters +========== +input + Type T1. + For real input, the following shape is expected: + ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][1]``. For + complex input, the following shape is expected: + ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][2]``. The + final dimension represents the real and imaginary parts of the value in + that order. +dft_length + Type T2. + The length of the signal as a scalar. If greater than the axis + dimension, the signal will be zero-padded up to ``dft_length``. If less + than the axis dimension, only the first ``dft_length`` values will be + used as the signal. +axis + Type tensor(int64). + The axis as a scalar on which to perform the DFT. Default is ``-2`` + (last signal axis). Negative value means counting dimensions from the + back. Accepted range is :math:`[-r, -2] \cup [0, r-2]` where + ``r = rank(input)``. The last dimension is for representing complex + numbers and thus is an invalid axis. +inverse + Attribute. + Whether to perform the inverse discrete Fourier Transform. Default is 0, + which corresponds to ``false``. +onesided + Attribute. + If ``onesided`` is ``1`` and input is real, only values for ``k`` in + ``[0, 1, 2, ..., floor(n_fft/2) + 1]`` are returned because the + real-to-complex Fourier transform satisfies the conjugate symmetry, + i.e., ``X[m, k] = X[m, n_fft-k]*``, where ``m`` denotes "all other + dimensions" DFT was not applied on. If the input tensor is complex, + onesided output is not possible. Value can be ``0`` or ``1``. Default is + ``0``. + +Returns +======= +output : Var + Type T1. + The Fourier Transform of the input vector. If ``onesided`` is ``0``, the + following shape is expected: + ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][2]``. If + ``axis=0`` and ``onesided`` is ``1``, the following shape is expected: + ``[floor(signal_dim0/2)+1][signal_dim1][signal_dim2]...[signal_dimN][2]``. + If ``axis=1`` and ``onesided`` is ``1``, the following shape is + expected: + ``[signal_dim0][floor(signal_dim1/2)+1][signal_dim2]...[signal_dimN][2]``. + If ``axis=N`` and ``onesided`` is ``1``, the following shape is + expected: + ``[signal_dim0][signal_dim1][signal_dim2]...[floor(signal_dimN/2)+1][2]``. + The ``signal_dim`` at the specified ``axis`` is equal to the + ``dft_length``. + +Notes +===== +Signature: ``ai.onnx@20::DFT``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return _DFT( + _DFT.Attributes( + inverse=AttrInt64(inverse, name="inverse"), + onesided=AttrInt64(onesided, name="onesided"), + ), _DFT.Inputs( + input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), axis=unwrap_vars(axis), ), ).get_output_vars( + input=get_value(input), dft_length=get_value(dft_length), axis=get_value(axis), ).output - Reference: https://docs.scipy.org/doc/scipy/tutorial/fft.html - Parameters - ========== - input - Type T1. - For real input, the following shape is expected: - ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][1]``. For - complex input, the following shape is expected: - ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][2]``. The - final dimension represents the real and imaginary parts of the value in - that order. - dft_length - Type T2. - The length of the signal as a scalar. If greater than the axis - dimension, the signal will be zero-padded up to ``dft_length``. If less - than the axis dimension, only the first ``dft_length`` values will be - used as the signal. - axis - Type tensor(int64). - The axis as a scalar on which to perform the DFT. Default is ``-2`` - (last signal axis). Negative value means counting dimensions from the - back. Accepted range is :math:`[-r, -2] \cup [0, r-2]` where - ``r = rank(input)``. The last dimension is for representing complex - numbers and thus is an invalid axis. - inverse - Attribute. - Whether to perform the inverse discrete Fourier Transform. Default is 0, - which corresponds to ``false``. - onesided - Attribute. - If ``onesided`` is ``1`` and input is real, only values for ``k`` in - ``[0, 1, 2, ..., floor(n_fft/2) + 1]`` are returned because the - real-to-complex Fourier transform satisfies the conjugate symmetry, - i.e., ``X[m, k] = X[m, n_fft-k]*``, where ``m`` denotes "all other - dimensions" DFT was not applied on. If the input tensor is complex, - onesided output is not possible. Value can be ``0`` or ``1``. Default is - ``0``. - - Returns - ======= - output : Var - Type T1. - The Fourier Transform of the input vector. If ``onesided`` is ``0``, the - following shape is expected: - ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][2]``. If - ``axis=0`` and ``onesided`` is ``1``, the following shape is expected: - ``[floor(signal_dim0/2)+1][signal_dim1][signal_dim2]...[signal_dimN][2]``. - If ``axis=1`` and ``onesided`` is ``1``, the following shape is - expected: - ``[signal_dim0][floor(signal_dim1/2)+1][signal_dim2]...[signal_dimN][2]``. - If ``axis=N`` and ``onesided`` is ``1``, the following shape is - expected: - ``[signal_dim0][signal_dim1][signal_dim2]...[floor(signal_dimN/2)+1][2]``. - The ``signal_dim`` at the specified ``axis`` is equal to the - ``dft_length``. - - Notes - ===== - Signature: ``ai.onnx@20::DFT``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return ( - _DFT( - _DFT.Attributes( - inverse=AttrInt64(inverse, name="inverse"), - onesided=AttrInt64(onesided, name="onesided"), - ), - _DFT.Inputs( - input=unwrap_vars(input), - dft_length=unwrap_vars(dft_length), - axis=unwrap_vars(axis), - ), - ) - .get_output_vars( - input=get_value(input), - dft_length=get_value(dft_length), - axis=get_value(axis), - ) - .output - ) - - -def gelu( - X: Var, - *, - approximate: str = "none", -) -> Var: +def gelu(X: Var, *, approximate: str = "none", ) -> Var: r""" - Gelu takes one input data (Tensor) and produces one output data - (Tensor) where the gaussian error linear units function, - :math:`y = 0.5 * x * (1 + erf(x/sqrt(2)))` is applied to the tensor - elementwise. If the attribute "approximate" is set to "tanh", the - function estimation, - :math:`y = 0.5 * x * (1 + Tanh(sqrt(2/\pi) * (x + 0.044715 * x^3)))` is - used and applied to the tensor elementwise. - - Parameters - ========== - X - Type T. - Input tensor - approximate - Attribute. - Gelu approximation algorithm: ``"tanh"``, - ``"none"``\ (default).\ ``"none"``: do not use - approximation.\ ``"tanh"``: use tanh approximation. - - Returns - ======= - Y : Var - Type T. - Output tensor - - Notes - ===== - Signature: ``ai.onnx@20::Gelu``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` +Gelu takes one input data (Tensor) and produces one output data +(Tensor) where the gaussian error linear units function, +:math:`y = 0.5 * x * (1 + erf(x/sqrt(2)))` is applied to the tensor +elementwise. If the attribute "approximate" is set to "tanh", the +function estimation, +:math:`y = 0.5 * x * (1 + Tanh(sqrt(2/\pi) * (x + 0.044715 * x^3)))` is +used and applied to the tensor elementwise. + +Parameters +========== +X + Type T. + Input tensor +approximate + Attribute. + Gelu approximation algorithm: ``"tanh"``, + ``"none"``\ (default).\ ``"none"``: do not use + approximation.\ ``"tanh"``: use tanh approximation. + +Returns +======= +Y : Var + Type T. + Output tensor + +Notes +===== +Signature: ``ai.onnx@20::Gelu``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _Gelu( - _Gelu.Attributes( - approximate=AttrString(approximate, name="approximate"), - ), - _Gelu.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def grid_sample( - X: Var, - grid: Var, - *, - align_corners: int = 0, - mode: str = "linear", - padding_mode: str = "zeros", -) -> Var: + return _Gelu( + _Gelu.Attributes( + approximate=AttrString(approximate, name="approximate"), + ), _Gelu.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def grid_sample(X: Var, grid: Var, *, align_corners: int = 0, mode: str = "linear", padding_mode: str = "zeros", ) -> Var: r""" - Given an input ``X`` and a flow-field ``grid``, computes the output - ``Y`` using ``X`` values and pixel locations from the ``grid``. For - spatial input ``X`` with shape (N, C, H, W), the ``grid`` will have - shape (N, H_out, W_out, 2), the output ``Y`` will have shape (N, C, - H_out, W_out). For volumetric input ``X`` with shape (N, C, D, H, W), - the ``grid`` will have shape (N, D_out, H_out, W_out, 3), the output - ``Y`` will have shape (N, C, D_out, H_out, W_out). More generally, for - an input ``X`` of rank r+2 with shape (N, C, d1, d2, ..., dr), the - ``grid`` will have shape (N, D1_out, D2_out, ..., Dr_out, r), the output - ``Y`` will have shape (N, C, D1_out, D2_out, ..., Dr_out). - - The tensor ``X`` contains values at centers of square pixels (voxels, - etc) locations such as (n, c, d1_in, d2_in, ..., dr_in). The (n, d1_out, - d2_out, ..., dr_out, :) values from the tensor ``grid`` are the - normalized positions for interpolating the values at the (n, c, d1_out, - d2_out, ..., dr_out) locations from the output tensor ``Y`` using a - specified interpolation method (the mode) and a padding mode (for - ``grid`` positions falling outside the 2-dimensional image). - - For example, the values in ``grid[n, h_out, w_out, :]`` are size-2 - vectors specifying normalized positions in the 2-dimensional space of - ``X``. They are used to interpolate output values of - ``Y[n, c, h_out, w_out]``. - - The GridSample operator is often used in doing grid generator and - sampler in the `Spatial Transformer - Networks `__. See also in - `torch.nn.functional.grid_sample `__. - - Parameters - ========== - X - Type T1. - Input tensor of rank r+2 that has shape (N, C, D1, D2, ..., Dr), where N - is the batch size, C is the number of channels, D1, D2, ..., Dr are the - spatial dimensions. - grid - Type T2. - Input offset of shape (N, D1_out, D2_out, ..., Dr_out, r), where D1_out, - D2_out, ..., Dr_out are the spatial dimensions of the grid and output, - and r is the number of spatial dimensions. Grid specifies the sampling - locations normalized by the input spatial dimensions. Therefore, it - should have most values in the range of [-1, 1]. If the grid has values - outside the range of [-1, 1], the corresponding outputs will be handled - as defined by padding_mode. Following computer vision convention, the - coordinates in the length-r location vector are listed from the - innermost tensor dimension to the outermost, the opposite of regular - tensor indexing. - align_corners - Attribute. - If align_corners=1, the extrema (-1 and 1) are considered as referring - to the center points of the input's corner pixels (voxels, etc.). If - align_corners=0, they are instead considered as referring to the corner - points of the input's corner pixels (voxels, etc.), making the sampling - more resolution agnostic. - mode - Attribute. - Three interpolation modes: linear (default), nearest and cubic. The - "linear" mode includes linear and N-linear interpolation modes depending - on the number of spatial dimensions of the input tensor (i.e. linear for - 1 spatial dimension, bilinear for 2 spatial dimensions, etc.). The - "cubic" mode also includes N-cubic interpolation modes following the - same rules. The "nearest" mode rounds to the nearest even index when the - sampling point falls halfway between two indices. - padding_mode - Attribute. - Support padding modes for outside grid values: ``zeros``\ (default), - ``border``, ``reflection``. zeros: use 0 for out-of-bound grid - locations, border: use border values for out-of-bound grid locations, - reflection: use values at locations reflected by the border for - out-of-bound grid locations. If index 0 represents the margin pixel, the - reflected value at index -1 will be the same as the value at index 1. - For location far away from the border, it will keep being reflected - until becoming in bound. If pixel location x = -3.5 reflects by border - -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = - 0.5. - - Returns - ======= - Y : Var - Type T1. - Output tensor of rank r+2 that has shape (N, C, D1_out, D2_out, ..., - Dr_out) of the sampled values. For integer input types, intermediate - values are computed as floating point and cast to integer at the end. - - Notes - ===== - Signature: ``ai.onnx@20::GridSample``. - - Type constraints: - - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` +Given an input ``X`` and a flow-field ``grid``, computes the output +``Y`` using ``X`` values and pixel locations from the ``grid``. For +spatial input ``X`` with shape (N, C, H, W), the ``grid`` will have +shape (N, H_out, W_out, 2), the output ``Y`` will have shape (N, C, +H_out, W_out). For volumetric input ``X`` with shape (N, C, D, H, W), +the ``grid`` will have shape (N, D_out, H_out, W_out, 3), the output +``Y`` will have shape (N, C, D_out, H_out, W_out). More generally, for +an input ``X`` of rank r+2 with shape (N, C, d1, d2, ..., dr), the +``grid`` will have shape (N, D1_out, D2_out, ..., Dr_out, r), the output +``Y`` will have shape (N, C, D1_out, D2_out, ..., Dr_out). + +The tensor ``X`` contains values at centers of square pixels (voxels, +etc) locations such as (n, c, d1_in, d2_in, ..., dr_in). The (n, d1_out, +d2_out, ..., dr_out, :) values from the tensor ``grid`` are the +normalized positions for interpolating the values at the (n, c, d1_out, +d2_out, ..., dr_out) locations from the output tensor ``Y`` using a +specified interpolation method (the mode) and a padding mode (for +``grid`` positions falling outside the 2-dimensional image). + +For example, the values in ``grid[n, h_out, w_out, :]`` are size-2 +vectors specifying normalized positions in the 2-dimensional space of +``X``. They are used to interpolate output values of +``Y[n, c, h_out, w_out]``. + +The GridSample operator is often used in doing grid generator and +sampler in the `Spatial Transformer +Networks `__. See also in +`torch.nn.functional.grid_sample `__. + +Parameters +========== +X + Type T1. + Input tensor of rank r+2 that has shape (N, C, D1, D2, ..., Dr), where N + is the batch size, C is the number of channels, D1, D2, ..., Dr are the + spatial dimensions. +grid + Type T2. + Input offset of shape (N, D1_out, D2_out, ..., Dr_out, r), where D1_out, + D2_out, ..., Dr_out are the spatial dimensions of the grid and output, + and r is the number of spatial dimensions. Grid specifies the sampling + locations normalized by the input spatial dimensions. Therefore, it + should have most values in the range of [-1, 1]. If the grid has values + outside the range of [-1, 1], the corresponding outputs will be handled + as defined by padding_mode. Following computer vision convention, the + coordinates in the length-r location vector are listed from the + innermost tensor dimension to the outermost, the opposite of regular + tensor indexing. +align_corners + Attribute. + If align_corners=1, the extrema (-1 and 1) are considered as referring + to the center points of the input's corner pixels (voxels, etc.). If + align_corners=0, they are instead considered as referring to the corner + points of the input's corner pixels (voxels, etc.), making the sampling + more resolution agnostic. +mode + Attribute. + Three interpolation modes: linear (default), nearest and cubic. The + "linear" mode includes linear and N-linear interpolation modes depending + on the number of spatial dimensions of the input tensor (i.e. linear for + 1 spatial dimension, bilinear for 2 spatial dimensions, etc.). The + "cubic" mode also includes N-cubic interpolation modes following the + same rules. The "nearest" mode rounds to the nearest even index when the + sampling point falls halfway between two indices. +padding_mode + Attribute. + Support padding modes for outside grid values: ``zeros``\ (default), + ``border``, ``reflection``. zeros: use 0 for out-of-bound grid + locations, border: use border values for out-of-bound grid locations, + reflection: use values at locations reflected by the border for + out-of-bound grid locations. If index 0 represents the margin pixel, the + reflected value at index -1 will be the same as the value at index 1. + For location far away from the border, it will keep being reflected + until becoming in bound. If pixel location x = -3.5 reflects by border + -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = + 0.5. + +Returns +======= +Y : Var + Type T1. + Output tensor of rank r+2 that has shape (N, C, D1_out, D2_out, ..., + Dr_out) of the sampled values. For integer input types, intermediate + values are computed as floating point and cast to integer at the end. + +Notes +===== +Signature: ``ai.onnx@20::GridSample``. + +Type constraints: + - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _GridSample( - _GridSample.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - mode=AttrString(mode, name="mode"), - padding_mode=AttrString(padding_mode, name="padding_mode"), - ), - _GridSample.Inputs( - X=unwrap_vars(X), - grid=unwrap_vars(grid), - ), - ) - .get_output_vars( - X=get_value(X), - grid=get_value(grid), - ) - .Y - ) - - -def image_decoder( - encoded_stream: Var, - *, - pixel_format: str = "RGB", -) -> Var: + return _GridSample( + _GridSample.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + mode=AttrString(mode, name="mode"), + padding_mode=AttrString(padding_mode, name="padding_mode"), + ), _GridSample.Inputs( + X=unwrap_vars(X), grid=unwrap_vars(grid), ), ).get_output_vars( + X=get_value(X), grid=get_value(grid), ).Y + + +def image_decoder(encoded_stream: Var, *, pixel_format: str = "RGB", ) -> Var: r""" - Loads and decodes and image from a file. If it can't decode for any - reason (e.g. corrupted encoded stream, invalid format, it will return an - empty matrix). The following image formats are supported: - - - BMP - - JPEG (note: Lossless JPEG support is optional) - - JPEG2000 - - TIFF - - PNG - - WebP - - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow - a channel-last layout: (Height, Width, Channels). **JPEG chroma - upsampling method:** When upsampling the chroma components by a - factor of 2, the pixels are linearly interpolated so that the centers - of the output pixels are 1/4 and 3/4 of the way between input pixel - centers. When rounding, 0.5 is rounded down and up at alternative - pixels locations to prevent bias towards larger values (ordered - dither pattern). Considering adjacent input pixels A, B, and C, B is - upsampled to pixels B0 and B1 so that - - :: - - B0 = round_half_down((1/4) * A + (3/4) * B) - B1 = round_half_up((3/4) * B + (1/4) * C) - - This method, is the default chroma upsampling method in the - well-established libjpeg-turbo library, also referred as "smooth" or - "fancy" upsampling. - - Parameters - ========== - encoded_stream - Type T1. - Encoded stream - pixel_format - Attribute. - Pixel format. Can be one of "RGB", "BGR", or "Grayscale". - - Returns - ======= - image : Var - Type T2. - Decoded image - - Notes - ===== - Signature: ``ai.onnx@20::ImageDecoder``. - - Type constraints: - - T1: `tensor(uint8)` - - T2: `tensor(uint8)` +Loads and decodes and image from a file. If it can't decode for any +reason (e.g. corrupted encoded stream, invalid format, it will return an +empty matrix). The following image formats are supported: + +- BMP +- JPEG (note: Lossless JPEG support is optional) +- JPEG2000 +- TIFF +- PNG +- WebP +- Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow + a channel-last layout: (Height, Width, Channels). **JPEG chroma + upsampling method:** When upsampling the chroma components by a + factor of 2, the pixels are linearly interpolated so that the centers + of the output pixels are 1/4 and 3/4 of the way between input pixel + centers. When rounding, 0.5 is rounded down and up at alternative + pixels locations to prevent bias towards larger values (ordered + dither pattern). Considering adjacent input pixels A, B, and C, B is + upsampled to pixels B0 and B1 so that + +:: + + B0 = round_half_down((1/4) * A + (3/4) * B) + B1 = round_half_up((3/4) * B + (1/4) * C) + +This method, is the default chroma upsampling method in the +well-established libjpeg-turbo library, also referred as "smooth" or +"fancy" upsampling. + +Parameters +========== +encoded_stream + Type T1. + Encoded stream +pixel_format + Attribute. + Pixel format. Can be one of "RGB", "BGR", or "Grayscale". + +Returns +======= +image : Var + Type T2. + Decoded image + +Notes +===== +Signature: ``ai.onnx@20::ImageDecoder``. + +Type constraints: + - T1: `tensor(uint8)` + - T2: `tensor(uint8)` """ - return ( - _ImageDecoder( - _ImageDecoder.Attributes( - pixel_format=AttrString(pixel_format, name="pixel_format"), - ), - _ImageDecoder.Inputs( - encoded_stream=unwrap_vars(encoded_stream), - ), - ) - .get_output_vars( - encoded_stream=get_value(encoded_stream), - ) - .image - ) - - -def isinf( - X: Var, - *, - detect_negative: int = 1, - detect_positive: int = 1, -) -> Var: + return _ImageDecoder( + _ImageDecoder.Attributes( + pixel_format=AttrString(pixel_format, name="pixel_format"), + ), _ImageDecoder.Inputs( + encoded_stream=unwrap_vars(encoded_stream), ), ).get_output_vars( + encoded_stream=get_value(encoded_stream), ).image + + +def isinf(X: Var, *, detect_negative: int = 1, detect_positive: int = 1, ) -> Var: r""" - Map infinity to true and other values to false. - - Parameters - ========== - X - Type T1. - input - detect_negative - Attribute. - (Optional) Whether map negative infinity to true. Default to 1 so that - negative infinity induces true. Set this attribute to 0 if negative - infinity should be mapped to false. - detect_positive - Attribute. - (Optional) Whether map positive infinity to true. Default to 1 so that - positive infinity induces true. Set this attribute to 0 if positive - infinity should be mapped to false. - - Returns - ======= - Y : Var - Type T2. - output - - Notes - ===== - Signature: ``ai.onnx@20::IsInf``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - - T2: `tensor(bool)` +Map infinity to true and other values to false. + +Parameters +========== +X + Type T1. + input +detect_negative + Attribute. + (Optional) Whether map negative infinity to true. Default to 1 so that + negative infinity induces true. Set this attribute to 0 if negative + infinity should be mapped to false. +detect_positive + Attribute. + (Optional) Whether map positive infinity to true. Default to 1 so that + positive infinity induces true. Set this attribute to 0 if positive + infinity should be mapped to false. + +Returns +======= +Y : Var + Type T2. + output + +Notes +===== +Signature: ``ai.onnx@20::IsInf``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` + - T2: `tensor(bool)` """ - return ( - _IsInf( - _IsInf.Attributes( - detect_negative=AttrInt64(detect_negative, name="detect_negative"), - detect_positive=AttrInt64(detect_positive, name="detect_positive"), - ), - _IsInf.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def isnan( - X: Var, -) -> Var: + return _IsInf( + _IsInf.Attributes( + detect_negative=AttrInt64(detect_negative, name="detect_negative"), + detect_positive=AttrInt64(detect_positive, name="detect_positive"), + ), _IsInf.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def isnan(X: Var, ) -> Var: r""" - Returns which elements of the input are NaN. - - Parameters - ========== - X - Type T1. - input - - Returns - ======= - Y : Var - Type T2. - output - - Notes - ===== - Signature: ``ai.onnx@20::IsNaN``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - - T2: `tensor(bool)` +Returns which elements of the input are NaN. + +Parameters +========== +X + Type T1. + input + +Returns +======= +Y : Var + Type T2. + output + +Notes +===== +Signature: ``ai.onnx@20::IsNaN``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` + - T2: `tensor(bool)` """ - return ( - _IsNaN( - _IsNaN.Attributes(), - _IsNaN.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def reduce_max( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _IsNaN( + _IsNaN.Attributes( + ), _IsNaN.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def reduce_max(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the max of the input tensor's elements along the provided axes. - The resulting tensor has the same rank as the input if ``keepdims`` - equals 1. If ``keepdims`` equals 0, then the resulting tensor has the - reduced dimension pruned. Input tensors of rank zero are valid. - Reduction over an empty set of values yields minus infinity (if - supported by the datatype) or the minimum value of the data type - otherwise. - - If the input data type is Boolean, the comparison should consider - ``False < True``. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@20::ReduceMax``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Computes the max of the input tensor's elements along the provided axes. +The resulting tensor has the same rank as the input if ``keepdims`` +equals 1. If ``keepdims`` equals 0, then the resulting tensor has the +reduced dimension pruned. Input tensors of rank zero are valid. +Reduction over an empty set of values yields minus infinity (if +supported by the datatype) or the minimum value of the data type +otherwise. + +If the input data type is Boolean, the comparison should consider +``False < True``. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@20::ReduceMax``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _ReduceMax( - _ReduceMax.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceMax.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def reduce_min( - data: Var, - axes: Optional[Var] = None, - *, - keepdims: int = 1, - noop_with_empty_axes: int = 0, -) -> Var: + return _ReduceMax( + _ReduceMax.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceMax.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def reduce_min(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: r""" - Computes the min of the input tensor's elements along the provided axes. - The resulting tensor has the same rank as the input if ``keepdims`` - equals 1. If ``keepdims`` equals 0, then the resulting tensor has the - reduced dimension pruned. Input tensors of rank zero are valid. - Reduction over an empty set of values yields plus infinity (if supported - by the datatype) or the maximum value of the data type otherwise. - - If the input data type is Boolean, the comparison should consider - ``False < True``. - - The above behavior is similar to numpy, with the exception that numpy - defaults ``keepdims`` to ``False`` instead of ``True``. - - Parameters - ========== - data - Type T. - An input tensor. - axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). - keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - - Returns - ======= - reduced : Var - Type T. - Reduced output tensor. - - Notes - ===== - Signature: ``ai.onnx@20::ReduceMin``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +Computes the min of the input tensor's elements along the provided axes. +The resulting tensor has the same rank as the input if ``keepdims`` +equals 1. If ``keepdims`` equals 0, then the resulting tensor has the +reduced dimension pruned. Input tensors of rank zero are valid. +Reduction over an empty set of values yields plus infinity (if supported +by the datatype) or the maximum value of the data type otherwise. + +If the input data type is Boolean, the comparison should consider +``False < True``. + +The above behavior is similar to numpy, with the exception that numpy +defaults ``keepdims`` to ``False`` instead of ``True``. + +Parameters +========== +data + Type T. + An input tensor. +axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). +keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. +noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + +Returns +======= +reduced : Var + Type T. + Reduced output tensor. + +Notes +===== +Signature: ``ai.onnx@20::ReduceMin``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _ReduceMin( - _ReduceMin.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64( - noop_with_empty_axes, name="noop_with_empty_axes" - ), - ), - _ReduceMin.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .reduced - ) - - -def regex_full_match( - X: Var, - *, - pattern: Optional[str] = None, -) -> Var: + return _ReduceMin( + _ReduceMin.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), + ), _ReduceMin.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).reduced + + +def regex_full_match(X: Var, *, pattern: Optional[str] = None, ) -> Var: r""" - RegexFullMatch performs a full regex match on each element of the input - tensor. If an element fully matches the regex pattern specified as an - attribute, the corresponding element in the output is True and it is - False otherwise. `RE2 `__ - regex syntax is used. - - Parameters - ========== - X - Type T1. - Tensor with strings to match on. - pattern - Attribute. - Regex pattern to match on. This must be valid RE2 syntax. - - Returns - ======= - Y : Var - Type T2. - Tensor of bools indicating if each input string fully matches the regex - pattern specified. - - Notes - ===== - Signature: ``ai.onnx@20::RegexFullMatch``. - - Type constraints: - - T1: `tensor(string)` - - T2: `tensor(bool)` +RegexFullMatch performs a full regex match on each element of the input +tensor. If an element fully matches the regex pattern specified as an +attribute, the corresponding element in the output is True and it is +False otherwise. `RE2 `__ +regex syntax is used. + +Parameters +========== +X + Type T1. + Tensor with strings to match on. +pattern + Attribute. + Regex pattern to match on. This must be valid RE2 syntax. + +Returns +======= +Y : Var + Type T2. + Tensor of bools indicating if each input string fully matches the regex + pattern specified. + +Notes +===== +Signature: ``ai.onnx@20::RegexFullMatch``. + +Type constraints: + - T1: `tensor(string)` + - T2: `tensor(bool)` """ - return ( - _RegexFullMatch( - _RegexFullMatch.Attributes( - pattern=AttrString.maybe(pattern, name="pattern"), - ), - _RegexFullMatch.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - .Y - ) - - -def string_concat( - X: Var, - Y: Var, -) -> Var: + return _RegexFullMatch( + _RegexFullMatch.Attributes( + pattern=AttrString.maybe(pattern, name="pattern"), + ), _RegexFullMatch.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), ).Y + + +def string_concat(X: Var, Y: Var, ) -> Var: r""" - StringConcat concatenates string tensors elementwise (with NumPy-style - broadcasting support) - - Parameters - ========== - X - Type T. - Tensor to prepend in concatenation - Y - Type T. - Tensor to append in concatenation - - Returns - ======= - Z : Var - Type T. - Concatenated string tensor - - Notes - ===== - Signature: ``ai.onnx@20::StringConcat``. - - Type constraints: - - T: `tensor(string)` +StringConcat concatenates string tensors elementwise (with NumPy-style +broadcasting support) + +Parameters +========== +X + Type T. + Tensor to prepend in concatenation +Y + Type T. + Tensor to append in concatenation + +Returns +======= +Z : Var + Type T. + Concatenated string tensor + +Notes +===== +Signature: ``ai.onnx@20::StringConcat``. + +Type constraints: + - T: `tensor(string)` """ - return ( - _StringConcat( - _StringConcat.Attributes(), - _StringConcat.Inputs( - X=unwrap_vars(X), - Y=unwrap_vars(Y), - ), - ) - .get_output_vars( - X=get_value(X), - Y=get_value(Y), - ) - .Z - ) - - -def string_split( - X: Var, - *, - delimiter: Optional[str] = None, - maxsplit: Optional[int] = None, -) -> tuple[Var, Var]: + return _StringConcat( + _StringConcat.Attributes( + ), _StringConcat.Inputs( + X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( + X=get_value(X), Y=get_value(Y), ).Z + + +def string_split(X: Var, *, delimiter: Optional[str] = None, maxsplit: Optional[int] = None, ) -> tuple[Var, Var]: r""" - StringSplit splits a string tensor's elements into substrings based on a - delimiter attribute and a maxsplit attribute. - - The first output of this operator is a tensor of strings representing - the substrings from splitting each input string on the ``delimiter`` - substring. This tensor has one additional rank compared to the input - tensor in order to store the substrings for each input element (where - the input tensor is not empty). Note that, in order to ensure the same - number of elements are present in the final dimension, this tensor will - pad empty strings as illustrated in the examples below. Consecutive - delimiters are not grouped together and are deemed to delimit empty - strings, except if the ``delimiter`` is unspecified or is the empty - string (""). In the case where the ``delimiter`` is unspecified or the - empty string, consecutive whitespace characters are regarded as a single - separator and leading or trailing whitespace is removed in the output. - - The second output tensor represents the number of substrings generated. - ``maxsplit`` can be used to limit the number of splits performed - after - the ``maxsplit``\ th split if the string is not fully split, the - trailing suffix of input string after the final split point is also - added. For elements where fewer splits are possible than specified in - ``maxsplit``, it has no effect. - - Parameters - ========== - X - Type T1. - Tensor of strings to split. - delimiter - Attribute. - Delimiter to split on. If left unset or set to the empty string (""), - the input is split on consecutive whitespace. - maxsplit - Attribute. - Maximum number of splits (from left to right). If left unset (or if the - number of possible splits are less than maxsplit), it will make as many - splits as possible. Note that the maximum possible number of substrings - returned with ``maxsplit`` specified is ``maxsplit+1`` since the - remaining suffix after the ``maxsplit``\ th split is included in the - output. - - Returns - ======= - Y : Var - Type T2. - Tensor of substrings representing the outcome of splitting the strings - in the input on the delimiter. Note that to ensure the same number of - elements are present in the final rank, this tensor will pad any - necessary empty strings. - Z : Var - Type T3. - The number of substrings generated for each input element. - - Notes - ===== - Signature: ``ai.onnx@20::StringSplit``. - - Type constraints: - - T1: `tensor(string)` - - T2: `tensor(string)` - - T3: `tensor(int64)` +StringSplit splits a string tensor's elements into substrings based on a +delimiter attribute and a maxsplit attribute. + +The first output of this operator is a tensor of strings representing +the substrings from splitting each input string on the ``delimiter`` +substring. This tensor has one additional rank compared to the input +tensor in order to store the substrings for each input element (where +the input tensor is not empty). Note that, in order to ensure the same +number of elements are present in the final dimension, this tensor will +pad empty strings as illustrated in the examples below. Consecutive +delimiters are not grouped together and are deemed to delimit empty +strings, except if the ``delimiter`` is unspecified or is the empty +string (""). In the case where the ``delimiter`` is unspecified or the +empty string, consecutive whitespace characters are regarded as a single +separator and leading or trailing whitespace is removed in the output. + +The second output tensor represents the number of substrings generated. +``maxsplit`` can be used to limit the number of splits performed - after +the ``maxsplit``\ th split if the string is not fully split, the +trailing suffix of input string after the final split point is also +added. For elements where fewer splits are possible than specified in +``maxsplit``, it has no effect. + +Parameters +========== +X + Type T1. + Tensor of strings to split. +delimiter + Attribute. + Delimiter to split on. If left unset or set to the empty string (""), + the input is split on consecutive whitespace. +maxsplit + Attribute. + Maximum number of splits (from left to right). If left unset (or if the + number of possible splits are less than maxsplit), it will make as many + splits as possible. Note that the maximum possible number of substrings + returned with ``maxsplit`` specified is ``maxsplit+1`` since the + remaining suffix after the ``maxsplit``\ th split is included in the + output. + +Returns +======= +Y : Var + Type T2. + Tensor of substrings representing the outcome of splitting the strings + in the input on the delimiter. Note that to ensure the same number of + elements are present in the final rank, this tensor will pad any + necessary empty strings. +Z : Var + Type T3. + The number of substrings generated for each input element. + +Notes +===== +Signature: ``ai.onnx@20::StringSplit``. + +Type constraints: + - T1: `tensor(string)` + - T2: `tensor(string)` + - T3: `tensor(int64)` """ - return ( - _StringSplit( - _StringSplit.Attributes( - delimiter=AttrString.maybe(delimiter, name="delimiter"), - maxsplit=AttrInt64.maybe(maxsplit, name="maxsplit"), - ), - _StringSplit.Inputs( - X=unwrap_vars(X), - ), - ) - .get_output_vars( - X=get_value(X), - ) - ._unpack_to_any() - ) + return _StringSplit( + _StringSplit.Attributes( + delimiter=AttrString.maybe(delimiter, name="delimiter"), + maxsplit=AttrInt64.maybe(maxsplit, name="maxsplit"), + ), _StringSplit.Inputs( + X=unwrap_vars(X), ), ).get_output_vars( + X=get_value(X), )._unpack_to_any() def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -2001,4 +1641,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 52e3027a..b51ae180 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -1,18 +1,21 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: BSD-3-Clause - # ruff: noqa: E741 -- Allow ambiguous variable name -from collections.abc import Iterable, Sequence +import typing +import warnings from dataclasses import dataclass +from collections.abc import Iterable, Sequence from typing import ( + Any, Callable, Optional, + Union, ) from typing import cast as typing_cast import numpy as np import numpy.typing as npt +from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, AttrFloat32, @@ -23,360 +26,187 @@ AttrString, AttrStrings, AttrTensor, + AttrType, ) -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._graph import Graph, subgraph +from spox._internal_op import intro from spox._node import OpType -from spox._standard import StandardNode -from spox._type_system import Tensor, Type +from spox._standard import InferenceError, StandardNode +from spox._type_system import Tensor, Type, Sequence as SpoxSequence from spox._value_prop import PropValueType -from spox._var import Var, VarInfo, get_value, unwrap_vars -from spox.opset.ai.onnx.v20 import ( - _DFT, - _GRU, - _LRN, - _LSTM, - _RNN, - _STFT, - _Abs, - _Acos, - _Acosh, - _Add, - _AffineGrid, - _And, - _ArgMax, - _ArgMin, - _Asin, - _Asinh, - _Atan, - _Atanh, - _AveragePool, - _BatchNormalization, - _Bernoulli, - _BitShift, - _BitwiseAnd, - _BitwiseNot, - _BitwiseOr, - _BitwiseXor, - _BlackmanWindow, - _Ceil, - _Celu, - _CenterCropPad, - _Clip, - _Col2Im, - _Compress, - _Concat, - _ConcatFromSequence, - _Conv, - _ConvInteger, - _ConvTranspose, - _Cos, - _Cosh, - _CumSum, - _DeformConv, - _DepthToSpace, - _Det, - _Div, - _Dropout, - _DynamicQuantizeLinear, - _Einsum, - _Elu, - _Equal, - _Erf, - _Exp, - _Expand, - _EyeLike, - _Floor, - _Gather, - _GatherElements, - _GatherND, - _Gelu, - _Gemm, - _GlobalAveragePool, - _GlobalLpPool, - _GlobalMaxPool, - _Greater, - _GreaterOrEqual, - _GridSample, - _HammingWindow, - _HannWindow, - _Hardmax, - _HardSigmoid, - _HardSwish, - _ImageDecoder, - _InstanceNormalization, - _IsInf, - _IsNaN, - _LayerNormalization, - _LeakyRelu, - _Less, - _LessOrEqual, - _Log, - _LogSoftmax, - _LpNormalization, - _LpPool, - _MatMul, - _MatMulInteger, - _Max, - _MaxPool, - _MaxRoiPool, - _MaxUnpool, - _Mean, - _MeanVarianceNormalization, - _MelWeightMatrix, - _Min, - _Mish, - _Mod, - _Mul, - _Multinomial, - _Neg, - _NegativeLogLikelihoodLoss, - _NonMaxSuppression, - _NonZero, - _Not, - _OneHot, - _Optional, - _OptionalGetElement, - _OptionalHasElement, - _Or, - _Pow, - _PRelu, - _QLinearConv, - _RandomNormal, - _RandomNormalLike, - _RandomUniform, - _RandomUniformLike, - _Range, - _Reciprocal, - _ReduceL1, - _ReduceL2, - _ReduceLogSum, - _ReduceLogSumExp, - _ReduceMax, - _ReduceMean, - _ReduceMin, - _ReduceProd, - _ReduceSum, - _ReduceSumSquare, - _RegexFullMatch, - _Relu, - _Resize, - _ReverseSequence, - _RoiAlign, - _Round, - _ScatterElements, - _ScatterND, - _Selu, - _SequenceAt, - _SequenceConstruct, - _SequenceEmpty, - _SequenceErase, - _SequenceInsert, - _SequenceLength, - _SequenceMap, - _Shrink, - _Sigmoid, - _Sign, - _Sin, - _Sinh, - _Slice, - _Softmax, - _SoftmaxCrossEntropyLoss, - _Softplus, - _Softsign, - _SpaceToDepth, - _Split, - _SplitToSequence, - _Sqrt, - _StringConcat, - _StringNormalizer, - _StringSplit, - _Sub, - _Sum, - _Tan, - _Tanh, - _TfIdfVectorizer, - _ThresholdedRelu, - _Tile, - _TopK, - _Trilu, - _Unique, - _Where, - _Xor, - abs, - acos, - acosh, - add, - affine_grid, - and_, - arg_max, - arg_min, - asin, - asinh, - atan, - atanh, - average_pool, - batch_normalization, - bernoulli, - bit_shift, - bitwise_and, - bitwise_not, - bitwise_or, - bitwise_xor, - blackman_window, - ceil, - celu, - center_crop_pad, - clip, - col2_im, - compress, - concat, - concat_from_sequence, - conv, - conv_integer, - conv_transpose, - cos, - cosh, - cumsum, - deform_conv, - depth_to_space, - det, - dft, - div, - dropout, - dynamic_quantize_linear, - einsum, - elu, - equal, - erf, - exp, - expand, - eye_like, - floor, - gather, - gather_elements, - gather_nd, - gelu, - gemm, - global_average_pool, - global_lp_pool, - global_max_pool, - greater, - greater_or_equal, - grid_sample, - gru, - hamming_window, - hann_window, - hard_sigmoid, - hard_swish, - hardmax, - image_decoder, - instance_normalization, - isinf, - isnan, - layer_normalization, - leaky_relu, - less, - less_or_equal, - log, - log_softmax, - lp_normalization, - lp_pool, - lrn, - lstm, - matmul, - matmul_integer, - max, - max_pool, - max_roi_pool, - max_unpool, - mean, - mean_variance_normalization, - mel_weight_matrix, - min, - mish, - mod, - mul, - multinomial, - neg, - negative_log_likelihood_loss, - non_max_suppression, - non_zero, - not_, - one_hot, - optional, - optional_get_element, - optional_has_element, - or_, - pow, - prelu, - qlinear_conv, - random_normal, - random_normal_like, - random_uniform, - random_uniform_like, - range, - reciprocal, - reduce_l1, - reduce_l2, - reduce_log_sum, - reduce_log_sum_exp, - reduce_max, - reduce_mean, - reduce_min, - reduce_prod, - reduce_sum, - reduce_sum_square, - regex_full_match, - relu, - resize, - reverse_sequence, - rnn, - roi_align, - round, - scatter_elements, - scatter_nd, - selu, - sequence_at, - sequence_construct, - sequence_empty, - sequence_erase, - sequence_insert, - sequence_length, - sequence_map, - shrink, - sigmoid, - sign, - sin, - sinh, - slice, - softmax, - softmax_cross_entropy_loss, - softplus, - softsign, - space_to_depth, - split, - split_to_sequence, - sqrt, - stft, - string_concat, - string_normalizer, - string_split, - sub, - sum, - tan, - tanh, - tf_idf_vectorizer, - thresholded_relu, - tile, - top_k, - trilu, - unique, - where, - xor, -) +from spox.opset.ai.onnx.v20 import _Abs, abs +from spox.opset.ai.onnx.v20 import _Acos, acos +from spox.opset.ai.onnx.v20 import _Acosh, acosh +from spox.opset.ai.onnx.v20 import _Add, add +from spox.opset.ai.onnx.v20 import _AffineGrid, affine_grid +from spox.opset.ai.onnx.v20 import _And, and_ +from spox.opset.ai.onnx.v20 import _ArgMax, arg_max +from spox.opset.ai.onnx.v20 import _ArgMin, arg_min +from spox.opset.ai.onnx.v20 import _Asin, asin +from spox.opset.ai.onnx.v20 import _Asinh, asinh +from spox.opset.ai.onnx.v20 import _Atan, atan +from spox.opset.ai.onnx.v20 import _Atanh, atanh +from spox.opset.ai.onnx.v20 import _AveragePool, average_pool +from spox.opset.ai.onnx.v20 import _BatchNormalization, batch_normalization +from spox.opset.ai.onnx.v20 import _Bernoulli, bernoulli +from spox.opset.ai.onnx.v20 import _BitShift, bit_shift +from spox.opset.ai.onnx.v20 import _BitwiseAnd, bitwise_and +from spox.opset.ai.onnx.v20 import _BitwiseNot, bitwise_not +from spox.opset.ai.onnx.v20 import _BitwiseOr, bitwise_or +from spox.opset.ai.onnx.v20 import _BitwiseXor, bitwise_xor +from spox.opset.ai.onnx.v20 import _BlackmanWindow, blackman_window +from spox.opset.ai.onnx.v20 import _Ceil, ceil +from spox.opset.ai.onnx.v20 import _Celu, celu +from spox.opset.ai.onnx.v20 import _CenterCropPad, center_crop_pad +from spox.opset.ai.onnx.v20 import _Clip, clip +from spox.opset.ai.onnx.v20 import _Col2Im, col2_im +from spox.opset.ai.onnx.v20 import _Compress, compress +from spox.opset.ai.onnx.v20 import _Concat, concat +from spox.opset.ai.onnx.v20 import _ConcatFromSequence, concat_from_sequence +from spox.opset.ai.onnx.v20 import _Conv, conv +from spox.opset.ai.onnx.v20 import _ConvInteger, conv_integer +from spox.opset.ai.onnx.v20 import _ConvTranspose, conv_transpose +from spox.opset.ai.onnx.v20 import _Cos, cos +from spox.opset.ai.onnx.v20 import _Cosh, cosh +from spox.opset.ai.onnx.v20 import _CumSum, cumsum +from spox.opset.ai.onnx.v20 import _DFT, dft +from spox.opset.ai.onnx.v20 import _DeformConv, deform_conv +from spox.opset.ai.onnx.v20 import _DepthToSpace, depth_to_space +from spox.opset.ai.onnx.v20 import _Det, det +from spox.opset.ai.onnx.v20 import _Div, div +from spox.opset.ai.onnx.v20 import _Dropout, dropout +from spox.opset.ai.onnx.v20 import _DynamicQuantizeLinear, dynamic_quantize_linear +from spox.opset.ai.onnx.v20 import _Einsum, einsum +from spox.opset.ai.onnx.v20 import _Elu, elu +from spox.opset.ai.onnx.v20 import _Equal, equal +from spox.opset.ai.onnx.v20 import _Erf, erf +from spox.opset.ai.onnx.v20 import _Exp, exp +from spox.opset.ai.onnx.v20 import _Expand, expand +from spox.opset.ai.onnx.v20 import _EyeLike, eye_like +from spox.opset.ai.onnx.v20 import _Floor, floor +from spox.opset.ai.onnx.v20 import _GRU, gru +from spox.opset.ai.onnx.v20 import _Gather, gather +from spox.opset.ai.onnx.v20 import _GatherElements, gather_elements +from spox.opset.ai.onnx.v20 import _GatherND, gather_nd +from spox.opset.ai.onnx.v20 import _Gelu, gelu +from spox.opset.ai.onnx.v20 import _Gemm, gemm +from spox.opset.ai.onnx.v20 import _GlobalAveragePool, global_average_pool +from spox.opset.ai.onnx.v20 import _GlobalLpPool, global_lp_pool +from spox.opset.ai.onnx.v20 import _GlobalMaxPool, global_max_pool +from spox.opset.ai.onnx.v20 import _Greater, greater +from spox.opset.ai.onnx.v20 import _GreaterOrEqual, greater_or_equal +from spox.opset.ai.onnx.v20 import _GridSample, grid_sample +from spox.opset.ai.onnx.v20 import _HammingWindow, hamming_window +from spox.opset.ai.onnx.v20 import _HannWindow, hann_window +from spox.opset.ai.onnx.v20 import _HardSigmoid, hard_sigmoid +from spox.opset.ai.onnx.v20 import _HardSwish, hard_swish +from spox.opset.ai.onnx.v20 import _Hardmax, hardmax +from spox.opset.ai.onnx.v20 import _ImageDecoder, image_decoder +from spox.opset.ai.onnx.v20 import _InstanceNormalization, instance_normalization +from spox.opset.ai.onnx.v20 import _IsInf, isinf +from spox.opset.ai.onnx.v20 import _IsNaN, isnan +from spox.opset.ai.onnx.v20 import _LRN, lrn +from spox.opset.ai.onnx.v20 import _LSTM, lstm +from spox.opset.ai.onnx.v20 import _LayerNormalization, layer_normalization +from spox.opset.ai.onnx.v20 import _LeakyRelu, leaky_relu +from spox.opset.ai.onnx.v20 import _Less, less +from spox.opset.ai.onnx.v20 import _LessOrEqual, less_or_equal +from spox.opset.ai.onnx.v20 import _Log, log +from spox.opset.ai.onnx.v20 import _LogSoftmax, log_softmax +from spox.opset.ai.onnx.v20 import _LpNormalization, lp_normalization +from spox.opset.ai.onnx.v20 import _LpPool, lp_pool +from spox.opset.ai.onnx.v20 import _MatMul, matmul +from spox.opset.ai.onnx.v20 import _MatMulInteger, matmul_integer +from spox.opset.ai.onnx.v20 import _Max, max +from spox.opset.ai.onnx.v20 import _MaxPool, max_pool +from spox.opset.ai.onnx.v20 import _MaxRoiPool, max_roi_pool +from spox.opset.ai.onnx.v20 import _MaxUnpool, max_unpool +from spox.opset.ai.onnx.v20 import _Mean, mean +from spox.opset.ai.onnx.v20 import _MeanVarianceNormalization, mean_variance_normalization +from spox.opset.ai.onnx.v20 import _MelWeightMatrix, mel_weight_matrix +from spox.opset.ai.onnx.v20 import _Min, min +from spox.opset.ai.onnx.v20 import _Mish, mish +from spox.opset.ai.onnx.v20 import _Mod, mod +from spox.opset.ai.onnx.v20 import _Mul, mul +from spox.opset.ai.onnx.v20 import _Multinomial, multinomial +from spox.opset.ai.onnx.v20 import _Neg, neg +from spox.opset.ai.onnx.v20 import _NegativeLogLikelihoodLoss, negative_log_likelihood_loss +from spox.opset.ai.onnx.v20 import _NonMaxSuppression, non_max_suppression +from spox.opset.ai.onnx.v20 import _NonZero, non_zero +from spox.opset.ai.onnx.v20 import _Not, not_ +from spox.opset.ai.onnx.v20 import _OneHot, one_hot +from spox.opset.ai.onnx.v20 import _Optional, optional +from spox.opset.ai.onnx.v20 import _OptionalGetElement, optional_get_element +from spox.opset.ai.onnx.v20 import _OptionalHasElement, optional_has_element +from spox.opset.ai.onnx.v20 import _Or, or_ +from spox.opset.ai.onnx.v20 import _PRelu, prelu +from spox.opset.ai.onnx.v20 import _Pow, pow +from spox.opset.ai.onnx.v20 import _QLinearConv, qlinear_conv +from spox.opset.ai.onnx.v20 import _RNN, rnn +from spox.opset.ai.onnx.v20 import _RandomNormal, random_normal +from spox.opset.ai.onnx.v20 import _RandomNormalLike, random_normal_like +from spox.opset.ai.onnx.v20 import _RandomUniform, random_uniform +from spox.opset.ai.onnx.v20 import _RandomUniformLike, random_uniform_like +from spox.opset.ai.onnx.v20 import _Range, range +from spox.opset.ai.onnx.v20 import _Reciprocal, reciprocal +from spox.opset.ai.onnx.v20 import _ReduceL1, reduce_l1 +from spox.opset.ai.onnx.v20 import _ReduceL2, reduce_l2 +from spox.opset.ai.onnx.v20 import _ReduceLogSum, reduce_log_sum +from spox.opset.ai.onnx.v20 import _ReduceLogSumExp, reduce_log_sum_exp +from spox.opset.ai.onnx.v20 import _ReduceMax, reduce_max +from spox.opset.ai.onnx.v20 import _ReduceMean, reduce_mean +from spox.opset.ai.onnx.v20 import _ReduceMin, reduce_min +from spox.opset.ai.onnx.v20 import _ReduceProd, reduce_prod +from spox.opset.ai.onnx.v20 import _ReduceSum, reduce_sum +from spox.opset.ai.onnx.v20 import _ReduceSumSquare, reduce_sum_square +from spox.opset.ai.onnx.v20 import _RegexFullMatch, regex_full_match +from spox.opset.ai.onnx.v20 import _Relu, relu +from spox.opset.ai.onnx.v20 import _Resize, resize +from spox.opset.ai.onnx.v20 import _ReverseSequence, reverse_sequence +from spox.opset.ai.onnx.v20 import _RoiAlign, roi_align +from spox.opset.ai.onnx.v20 import _Round, round +from spox.opset.ai.onnx.v20 import _STFT, stft +from spox.opset.ai.onnx.v20 import _ScatterElements, scatter_elements +from spox.opset.ai.onnx.v20 import _ScatterND, scatter_nd +from spox.opset.ai.onnx.v20 import _Selu, selu +from spox.opset.ai.onnx.v20 import _SequenceAt, sequence_at +from spox.opset.ai.onnx.v20 import _SequenceConstruct, sequence_construct +from spox.opset.ai.onnx.v20 import _SequenceEmpty, sequence_empty +from spox.opset.ai.onnx.v20 import _SequenceErase, sequence_erase +from spox.opset.ai.onnx.v20 import _SequenceInsert, sequence_insert +from spox.opset.ai.onnx.v20 import _SequenceLength, sequence_length +from spox.opset.ai.onnx.v20 import _SequenceMap, sequence_map +from spox.opset.ai.onnx.v20 import _Shrink, shrink +from spox.opset.ai.onnx.v20 import _Sigmoid, sigmoid +from spox.opset.ai.onnx.v20 import _Sign, sign +from spox.opset.ai.onnx.v20 import _Sin, sin +from spox.opset.ai.onnx.v20 import _Sinh, sinh +from spox.opset.ai.onnx.v20 import _Slice, slice +from spox.opset.ai.onnx.v20 import _Softmax, softmax +from spox.opset.ai.onnx.v20 import _SoftmaxCrossEntropyLoss, softmax_cross_entropy_loss +from spox.opset.ai.onnx.v20 import _Softplus, softplus +from spox.opset.ai.onnx.v20 import _Softsign, softsign +from spox.opset.ai.onnx.v20 import _SpaceToDepth, space_to_depth +from spox.opset.ai.onnx.v20 import _Split, split +from spox.opset.ai.onnx.v20 import _SplitToSequence, split_to_sequence +from spox.opset.ai.onnx.v20 import _Sqrt, sqrt +from spox.opset.ai.onnx.v20 import _StringConcat, string_concat +from spox.opset.ai.onnx.v20 import _StringNormalizer, string_normalizer +from spox.opset.ai.onnx.v20 import _StringSplit, string_split +from spox.opset.ai.onnx.v20 import _Sub, sub +from spox.opset.ai.onnx.v20 import _Sum, sum +from spox.opset.ai.onnx.v20 import _Tan, tan +from spox.opset.ai.onnx.v20 import _Tanh, tanh +from spox.opset.ai.onnx.v20 import _TfIdfVectorizer, tf_idf_vectorizer +from spox.opset.ai.onnx.v20 import _ThresholdedRelu, thresholded_relu +from spox.opset.ai.onnx.v20 import _Tile, tile +from spox.opset.ai.onnx.v20 import _TopK, top_k +from spox.opset.ai.onnx.v20 import _Trilu, trilu +from spox.opset.ai.onnx.v20 import _Unique, unique +from spox.opset.ai.onnx.v20 import _Where, where +from spox.opset.ai.onnx.v20 import _Xor, xor class _Cast(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -397,7 +227,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _CastLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -418,7 +247,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Constant(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -437,9 +265,7 @@ class Outputs(BaseOutputs): output: VarInfo def propagate_values(self, initializers) -> dict[str, PropValueType]: - ((key, raw),) = ( - (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None - ) + ((key, raw),) = ((k, v.value) for k, v in self.attrs.get_fields().items() if v is not None) if key == "value": value = raw elif key == "value_float": @@ -457,18 +283,14 @@ def propagate_values(self, initializers) -> dict[str, PropValueType]: elif key == "sparse_value": return {} else: - raise RuntimeError( - f"Could not extract the set Constant value attribute, got: {key}" - ) + raise RuntimeError(f"Could not extract the set Constant value attribute, got: {key}") return {"output": value} - op_type = OpType("Constant", "", 21) attrs: Attributes inputs: BaseInputs outputs: Outputs - class _ConstantOfShape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -488,7 +310,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _DequantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -511,7 +332,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Flatten(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -531,7 +351,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _GroupNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -555,7 +374,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Identity(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -575,7 +393,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _If(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -596,7 +413,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Loop(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -618,7 +434,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Pad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -641,7 +456,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _QLinearMatMul(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -668,7 +482,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _QuantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -693,7 +506,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Reshape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -714,7 +526,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Scan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -739,7 +550,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Shape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -760,7 +570,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Size(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -780,7 +589,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Squeeze(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -801,7 +609,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Transpose(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -821,7 +628,6 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - class _Unsqueeze(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -842,1917 +648,1592 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - -def cast( - input: Var, - *, - saturate: int = 1, - to: npt.DTypeLike, -) -> Var: +def cast(input: Var, *, saturate: int = 1, to: npt.DTypeLike, ) -> Var: r""" - The operator casts the elements of a given input tensor to a data type - specified by the 'to' argument and returns an output tensor of the same - size in the converted type. The 'to' argument must be one of the data - types specified in the 'DataType' enum field in the TensorProto message. - - Casting from string tensor in plain (e.g., "3.14" and "1000") and - scientific numeric representations (e.g., "1e-5" and "1E8") to float - types is supported. For example, converting string "100.5" to an integer - may yield result 100. There are some string literals reserved for - special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are - positive infinity, negative infinity, and not-a-number, respectively. - Any string which can exactly match "+INF" in a case-insensitive way - would be mapped to positive infinite. Similarly, this case-insensitive - rule is applied to "INF" and "NaN". When casting from numeric tensors to - string tensors, plain floating-point representation (such as - "314.15926") would be used. Converting non-numerical-literal string such - as "Hello World!" is an undefined behavior. Cases of converting string - representing floating-point arithmetic value, such as "2.718", to INT is - an undefined behavior. - - Conversion from a numerical type to any numerical type is always - allowed. User must be aware of precision loss and value change caused by - range difference between two types. For example, a 64-bit float - 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, - converting an integer 36 to Boolean may produce 1 because we truncate - bits which can't be stored in the targeted type. - - In more detail, the conversion among numerical types should follow these - rules if the destination type is not a float 8 type. - - - Casting from floating point to: - - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. - - - Casting from fixed point to: - - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. - - - Casting from bool to: - - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. - - Float 8 type were introduced to speed up the training of deep models. By - default the conversion of a float *x* obeys to the following rules. - ``[x]`` means the value rounded to the target mantissa width. - - ============== =========== ======== ======== ======== - x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ - ============== =========== ======== ======== ======== - 0 0 0 0 0 - -0 -0 0 -0 0 - NaN NaN NaN NaN NaN - +/- Inf +/- FLT_MAX NaN FLT_MAX NaN - [x] > FLT_MAX FLT_MAX FLT_MAX FLT_MAX FLT_MAX - [x] < -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX - else RNE RNE RNE RNE - ============== =========== ======== ======== ======== - - The behavior changes if the parameter 'saturate' is set to False. The - rules then become: - - ============== ====== ======== ======= ======== - x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ - ============== ====== ======== ======= ======== - 0 0 0 0 0 - -0 -0 0 -0 0 - NaN NaN NaN NaN NaN - +/- Inf NaN NaN +/- Inf NaN - [x] > FLT_MAX NaN NaN Inf NaN - [x] < -FLT_MAX NaN NaN -Inf NaN - else RNE RNE RNE RNE - ============== ====== ======== ======= ======== - - Parameters - ========== - input - Type T1. - Input tensor to be cast. - saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. All cases are fully described in two tables - inserted in the operator description. - to - Attribute. - The data type to which the elements of the input tensor are cast. - Strictly must be one of the types from DataType enum in TensorProto - - Returns - ======= - output : Var - Type T2. - Output tensor with the same shape as input with type specified by the - 'to' argument - - Notes - ===== - Signature: ``ai.onnx@21::Cast``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +The operator casts the elements of a given input tensor to a data type +specified by the 'to' argument and returns an output tensor of the same +size in the converted type. The 'to' argument must be one of the data +types specified in the 'DataType' enum field in the TensorProto message. + +Casting from string tensor in plain (e.g., "3.14" and "1000") and +scientific numeric representations (e.g., "1e-5" and "1E8") to float +types is supported. For example, converting string "100.5" to an integer +may yield result 100. There are some string literals reserved for +special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are +positive infinity, negative infinity, and not-a-number, respectively. +Any string which can exactly match "+INF" in a case-insensitive way +would be mapped to positive infinite. Similarly, this case-insensitive +rule is applied to "INF" and "NaN". When casting from numeric tensors to +string tensors, plain floating-point representation (such as +"314.15926") would be used. Converting non-numerical-literal string such +as "Hello World!" is an undefined behavior. Cases of converting string +representing floating-point arithmetic value, such as "2.718", to INT is +an undefined behavior. + +Conversion from a numerical type to any numerical type is always +allowed. User must be aware of precision loss and value change caused by +range difference between two types. For example, a 64-bit float +3.1415926459 may be round to a 32-bit float 3.141592. Similarly, +converting an integer 36 to Boolean may produce 1 because we truncate +bits which can't be stored in the targeted type. + +In more detail, the conversion among numerical types should follow these +rules if the destination type is not a float 8 type. + +- Casting from floating point to: + + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. + +- Casting from fixed point to: + + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. + +- Casting from bool to: + + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. + +Float 8 type were introduced to speed up the training of deep models. By +default the conversion of a float *x* obeys to the following rules. +``[x]`` means the value rounded to the target mantissa width. + +============== =========== ======== ======== ======== +x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ +============== =========== ======== ======== ======== +0 0 0 0 0 +-0 -0 0 -0 0 +NaN NaN NaN NaN NaN ++/- Inf +/- FLT_MAX NaN FLT_MAX NaN +[x] > FLT_MAX FLT_MAX FLT_MAX FLT_MAX FLT_MAX +[x] < -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX +else RNE RNE RNE RNE +============== =========== ======== ======== ======== + +The behavior changes if the parameter 'saturate' is set to False. The +rules then become: + +============== ====== ======== ======= ======== +x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ +============== ====== ======== ======= ======== +0 0 0 0 0 +-0 -0 0 -0 0 +NaN NaN NaN NaN NaN ++/- Inf NaN NaN +/- Inf NaN +[x] > FLT_MAX NaN NaN Inf NaN +[x] < -FLT_MAX NaN NaN -Inf NaN +else RNE RNE RNE RNE +============== ====== ======== ======= ======== + +Parameters +========== +input + Type T1. + Input tensor to be cast. +saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. All cases are fully described in two tables + inserted in the operator description. +to + Attribute. + The data type to which the elements of the input tensor are cast. + Strictly must be one of the types from DataType enum in TensorProto + +Returns +======= +output : Var + Type T2. + Output tensor with the same shape as input with type specified by the + 'to' argument + +Notes +===== +Signature: ``ai.onnx@21::Cast``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Cast( - _Cast.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - to=AttrDtype(to, name="to"), - ), - _Cast.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Cast( + _Cast.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + to=AttrDtype(to, name="to"), + ), _Cast.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def cast_like( - input: Var, - target_type: Var, - *, - saturate: int = 1, -) -> Var: +def cast_like(input: Var, target_type: Var, *, saturate: int = 1, ) -> Var: r""" - The operator casts the elements of a given input tensor (the first - input) to the same data type as the elements of the second input tensor. - See documentation of the Cast operator for further details. - - Parameters - ========== - input - Type T1. - Input tensor to be cast. - target_type - Type T2. - The (first) input tensor will be cast to produce a tensor of the same - type as this (second input) tensor. - saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. Please refer to operator Cast description for - further details. - - Returns - ======= - output : Var - Type T2. - Output tensor produced by casting the first input tensor to have the - same type as the second input tensor. - - Notes - ===== - Signature: ``ai.onnx@21::CastLike``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +The operator casts the elements of a given input tensor (the first +input) to the same data type as the elements of the second input tensor. +See documentation of the Cast operator for further details. + +Parameters +========== +input + Type T1. + Input tensor to be cast. +target_type + Type T2. + The (first) input tensor will be cast to produce a tensor of the same + type as this (second input) tensor. +saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. Please refer to operator Cast description for + further details. + +Returns +======= +output : Var + Type T2. + Output tensor produced by casting the first input tensor to have the + same type as the second input tensor. + +Notes +===== +Signature: ``ai.onnx@21::CastLike``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _CastLike( - _CastLike.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - ), - _CastLike.Inputs( - input=unwrap_vars(input), - target_type=unwrap_vars(target_type), - ), - ) - .get_output_vars( - input=get_value(input), - target_type=get_value(target_type), - ) - .output - ) + return _CastLike( + _CastLike.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + ), _CastLike.Inputs( + input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), ).get_output_vars( + input=get_value(input), target_type=get_value(target_type), ).output -def constant( - *, - value: Optional[np.ndarray] = None, - value_float: Optional[float] = None, - value_floats: Optional[Iterable[float]] = None, - value_int: Optional[int] = None, - value_ints: Optional[Iterable[int]] = None, - value_string: Optional[str] = None, - value_strings: Optional[Iterable[str]] = None, -) -> Var: +def constant(*, value: Optional[np.ndarray] = None, value_float: Optional[float] = None, value_floats: Optional[Iterable[float]] = None, value_int: Optional[int] = None, value_ints: Optional[Iterable[int]] = None, value_string: Optional[str] = None, value_strings: Optional[Iterable[str]] = None, ) -> Var: r""" - This operator produces a constant tensor. Exactly one of the provided - attributes, either value, sparse_value, or value\_\* must be specified. - - Parameters - ========== - sparse_value - Attribute. - The value for the elements of the output tensor in sparse format. - value - Attribute. - The value for the elements of the output tensor. - value_float - Attribute. - The value for the sole element for the scalar, float32, output tensor. - value_floats - Attribute. - The values for the elements for the 1D, float32, output tensor. - value_int - Attribute. - The value for the sole element for the scalar, int64, output tensor. - value_ints - Attribute. - The values for the elements for the 1D, int64, output tensor. - value_string - Attribute. - The value for the sole element for the scalar, UTF-8 string, output - tensor. - value_strings - Attribute. - The values for the elements for the 1D, UTF-8 string, output tensor. - - Returns - ======= - output : Var - Type T. - Output tensor containing the same value of the provided tensor. - - Notes - ===== - Signature: ``ai.onnx@21::Constant``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +This operator produces a constant tensor. Exactly one of the provided +attributes, either value, sparse_value, or value\_\* must be specified. + +Parameters +========== +sparse_value + Attribute. + The value for the elements of the output tensor in sparse format. +value + Attribute. + The value for the elements of the output tensor. +value_float + Attribute. + The value for the sole element for the scalar, float32, output tensor. +value_floats + Attribute. + The values for the elements for the 1D, float32, output tensor. +value_int + Attribute. + The value for the sole element for the scalar, int64, output tensor. +value_ints + Attribute. + The values for the elements for the 1D, int64, output tensor. +value_string + Attribute. + The value for the sole element for the scalar, UTF-8 string, output + tensor. +value_strings + Attribute. + The values for the elements for the 1D, UTF-8 string, output tensor. + +Returns +======= +output : Var + Type T. + Output tensor containing the same value of the provided tensor. + +Notes +===== +Signature: ``ai.onnx@21::Constant``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), - _Constant.Inputs(), - ) - .get_output_vars() - .output - ) - - -def constant_of_shape( - input: Var, - *, - value: Optional[np.ndarray] = None, -) -> Var: + return _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), _Constant.Inputs( + ), ).get_output_vars( + ).output + + +def constant_of_shape(input: Var, *, value: Optional[np.ndarray] = None, ) -> Var: r""" - Generate a tensor with given value and shape. - - Parameters - ========== - input - Type T1. - 1D tensor. The shape of the expected output tensor. If empty tensor is - given, the output would be a scalar. All values must be >= 0. - value - Attribute. - (Optional) The value of the output elements.Should be a one-element - tensor. If not specified, it defaults to a tensor of value 0 and - datatype float32 - - Returns - ======= - output : Var - Type T2. - Output tensor of shape specified by 'input'.If attribute 'value' is - specified, the value and datatype of the output tensor is taken from - 'value'.If attribute 'value' is not specified, the value in the output - defaults to 0, and the datatype defaults to float32. - - Notes - ===== - Signature: ``ai.onnx@21::ConstantOfShape``. - - Type constraints: - - T1: `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Generate a tensor with given value and shape. + +Parameters +========== +input + Type T1. + 1D tensor. The shape of the expected output tensor. If empty tensor is + given, the output would be a scalar. All values must be >= 0. +value + Attribute. + (Optional) The value of the output elements.Should be a one-element + tensor. If not specified, it defaults to a tensor of value 0 and + datatype float32 + +Returns +======= +output : Var + Type T2. + Output tensor of shape specified by 'input'.If attribute 'value' is + specified, the value and datatype of the output tensor is taken from + 'value'.If attribute 'value' is not specified, the value in the output + defaults to 0, and the datatype defaults to float32. + +Notes +===== +Signature: ``ai.onnx@21::ConstantOfShape``. + +Type constraints: + - T1: `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), - _ConstantOfShape.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), _ConstantOfShape.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def dequantize_linear( - x: Var, - x_scale: Var, - x_zero_point: Optional[Var] = None, - *, - axis: int = 1, - block_size: int = 0, -) -> Var: +def dequantize_linear(x: Var, x_scale: Var, x_zero_point: Optional[Var] = None, *, axis: int = 1, block_size: int = 0, ) -> Var: r""" - The linear dequantization operator. It consumes a quantized tensor, a - scale, and a zero point to compute the full-precision tensor. The - dequantization formula is ``y = (x - x_zero_point) * x_scale``. - ``x_scale`` and ``x_zero_point`` must have the same shape, determining - the quantization's granularity: a scalar for per-tensor/per-layer - quantization, a 1-D tensor for per-axis quantization, or have a rank - identical to the input for blocked quantization. See QuantizeLinear for - details on quantization granularity. - - ``x_zero_point`` and ``x`` must have the same type. ``x`` and ``y`` must - have the same shape. In the case of dequantizing ``int32``, there's no - zero point (zero point is supposed to be 0). ``zero-point`` is usually - not used in the case of float8 types quantization, but the - dequantization formula remains the same for consistency, and ``x_scale`` - still determines the output type. - - Parameters - ========== - x - Type T1. - N-D quantized input tensor to be de-quantized. - x_scale - Type T2. - Scale for input ``x``. For per-tensor/layer dequantization the scale is - a scalar, for per per-axis dequantization it is a 1-D Tensor and for - blocked dequantization it has the same shape as the input, except for - one dimension in which blocking is performed. - x_zero_point - Type T1. - Zero point for input ``x``. Shape must match x_scale. It's optional. - Zero point is 0 when it's not specified. - axis - Attribute. - (Optional) The axis of the dequantizing dimension of the input tensor. - Used for per-axis and blocked quantization. Negative value means - counting dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. - block_size - Attribute. - (Optional) The size of the quantization block (number of times every - scale is replicated). Used only for blocked quantization. The block size - is a positive integer. Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, - ``y_scale`` shape ``(S0, ... Si, ...Sn)`` and ``axis=i``, the accepted - range is ``[ceil(Di/Si), ceil(Di/(Si-1))-1]`` - - Returns - ======= - y : Var - Type T2. - N-D full precision output tensor. It has same shape as input ``x``. - - Notes - ===== - Signature: ``ai.onnx@21::DequantizeLinear``. - - Type constraints: - - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` +The linear dequantization operator. It consumes a quantized tensor, a +scale, and a zero point to compute the full-precision tensor. The +dequantization formula is ``y = (x - x_zero_point) * x_scale``. +``x_scale`` and ``x_zero_point`` must have the same shape, determining +the quantization's granularity: a scalar for per-tensor/per-layer +quantization, a 1-D tensor for per-axis quantization, or have a rank +identical to the input for blocked quantization. See QuantizeLinear for +details on quantization granularity. + +``x_zero_point`` and ``x`` must have the same type. ``x`` and ``y`` must +have the same shape. In the case of dequantizing ``int32``, there's no +zero point (zero point is supposed to be 0). ``zero-point`` is usually +not used in the case of float8 types quantization, but the +dequantization formula remains the same for consistency, and ``x_scale`` +still determines the output type. + +Parameters +========== +x + Type T1. + N-D quantized input tensor to be de-quantized. +x_scale + Type T2. + Scale for input ``x``. For per-tensor/layer dequantization the scale is + a scalar, for per per-axis dequantization it is a 1-D Tensor and for + blocked dequantization it has the same shape as the input, except for + one dimension in which blocking is performed. +x_zero_point + Type T1. + Zero point for input ``x``. Shape must match x_scale. It's optional. + Zero point is 0 when it's not specified. +axis + Attribute. + (Optional) The axis of the dequantizing dimension of the input tensor. + Used for per-axis and blocked quantization. Negative value means + counting dimensions from the back. Accepted range is ``[-r, r-1]`` where + ``r = rank(input)``. +block_size + Attribute. + (Optional) The size of the quantization block (number of times every + scale is replicated). Used only for blocked quantization. The block size + is a positive integer. Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, + ``y_scale`` shape ``(S0, ... Si, ...Sn)`` and ``axis=i``, the accepted + range is ``[ceil(Di/Si), ceil(Di/(Si-1))-1]`` + +Returns +======= +y : Var + Type T2. + N-D full precision output tensor. It has same shape as input ``x``. + +Notes +===== +Signature: ``ai.onnx@21::DequantizeLinear``. + +Type constraints: + - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - return ( - _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - block_size=AttrInt64(block_size, name="block_size"), - ), - _DequantizeLinear.Inputs( - x=unwrap_vars(x), - x_scale=unwrap_vars(x_scale), - x_zero_point=unwrap_vars(x_zero_point), - ), - ) - .get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - ) - .y - ) + return _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + block_size=AttrInt64(block_size, name="block_size"), + ), _DequantizeLinear.Inputs( + x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), ).get_output_vars( + x=get_value(x), x_scale=get_value(x_scale), x_zero_point=get_value(x_zero_point), ).y -def flatten( - input: Var, - *, - axis: int = 1, -) -> Var: +def flatten(input: Var, *, axis: int = 1, ) -> Var: r""" - Flattens the input tensor into a 2D matrix. If input tensor has shape - (d_0, d_1, ... d_n) then the output will have shape (d_0 X d_1 ... - d\_(axis-1), d_axis X d\_(axis+1) ... X dn). - - Parameters - ========== - input - Type T. - A tensor of rank >= axis. - axis - Attribute. - Indicate up to which input dimensions (exclusive) should be flattened to - the outer dimension of the output. The value for axis must be in the - range [-r, r], where r is the rank of the input tensor. Negative value - means counting dimensions from the back. When axis = 0, the shape of the - output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input - tensor is (d_0, d_1, ... d_n). - - Returns - ======= - output : Var - Type T. - A 2D tensor with the contents of the input tensor, with input dimensions - up to axis flattened to the outer dimension of the output and remaining - input dimensions flattened into the inner dimension of the output. - - Notes - ===== - Signature: ``ai.onnx@21::Flatten``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Flattens the input tensor into a 2D matrix. If input tensor has shape +(d_0, d_1, ... d_n) then the output will have shape (d_0 X d_1 ... +d\_(axis-1), d_axis X d\_(axis+1) ... X dn). + +Parameters +========== +input + Type T. + A tensor of rank >= axis. +axis + Attribute. + Indicate up to which input dimensions (exclusive) should be flattened to + the outer dimension of the output. The value for axis must be in the + range [-r, r], where r is the rank of the input tensor. Negative value + means counting dimensions from the back. When axis = 0, the shape of the + output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input + tensor is (d_0, d_1, ... d_n). + +Returns +======= +output : Var + Type T. + A 2D tensor with the contents of the input tensor, with input dimensions + up to axis flattened to the outer dimension of the output and remaining + input dimensions flattened into the inner dimension of the output. + +Notes +===== +Signature: ``ai.onnx@21::Flatten``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Flatten( - _Flatten.Attributes( - axis=AttrInt64(axis, name="axis"), - ), - _Flatten.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Flatten( + _Flatten.Attributes( + axis=AttrInt64(axis, name="axis"), + ), _Flatten.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def group_normalization( - X: Var, - scale: Var, - bias: Var, - *, - epsilon: float = 9.999999747378752e-06, - num_groups: int, - stash_type: int = 1, -) -> Var: +def group_normalization(X: Var, scale: Var, bias: Var, *, epsilon: float = 9.999999747378752e-06, num_groups: int, stash_type: int = 1, ) -> Var: r""" - A GroupNormalization function. Carries out group normalization as - described in the paper https://arxiv.org/abs/1803.08494 - - This operator transforms input according to - - :: - - y = scale * (x - mean) / sqrt(variance + epsilon) + bias, - - where the mean and variance are computed per instance per group of - channels, and ``scale`` and ``bias`` should be specified for each group - of channels. The number of groups ``num_groups`` should be divisible by - the number of channels so that there are an equal number of channels per - group. - - The overall computation has two stages: the first stage normalizes the - elements to have zero mean and unit variance for each instance in each - group, and the second stage scales and shifts the results of the first - stage. The floating-point precision used in the first stage is - determined by the ``stash_type`` attribute. For example, if - ``stash_type`` is 1, the operator casts all input variables to 32-bit - float, performs the computation, and finally casts the normalized - results back to the original type of ``X``. The second stage does not - depend on ``stash_type``. - - When the number of groups is the same as the number of channels, this - operator is equivalent to InstanceNormalization. When there is only one - group, this operator is equivalent to LayerNormalization. - - Parameters - ========== - X - Type T. - Input data tensor. Dimensions for image cases are ``(N x C x H x W)``, - where ``N`` is the batch size, ``C`` is the number of channels, and - ``H`` and ``W`` are the height and width of the data. Statistics are - computed for every group of channels over ``C``, ``H``, and ``W``. For - non-image cases, the dimensions are in the form of - ``(N x C x D1 x D2 ... Dn)``. - scale - Type T. - Scale tensor of shape ``(C)``. - bias - Type T. - Bias tensor of shape ``(C)``. - epsilon - Attribute. - The epsilon value to use to avoid division by zero. - num_groups - Attribute. - The number of groups of channels. It should be a divisor of the number - of channels ``C``. - stash_type - Attribute. - The floating-point precision used in stage one of the computation. - - Returns - ======= - Y : Var - Type T. - The output tensor of the same shape as ``X``. - - Notes - ===== - Signature: ``ai.onnx@21::GroupNormalization``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` +A GroupNormalization function. Carries out group normalization as +described in the paper https://arxiv.org/abs/1803.08494 + +This operator transforms input according to + +:: + + y = scale * (x - mean) / sqrt(variance + epsilon) + bias, + +where the mean and variance are computed per instance per group of +channels, and ``scale`` and ``bias`` should be specified for each group +of channels. The number of groups ``num_groups`` should be divisible by +the number of channels so that there are an equal number of channels per +group. + +The overall computation has two stages: the first stage normalizes the +elements to have zero mean and unit variance for each instance in each +group, and the second stage scales and shifts the results of the first +stage. The floating-point precision used in the first stage is +determined by the ``stash_type`` attribute. For example, if +``stash_type`` is 1, the operator casts all input variables to 32-bit +float, performs the computation, and finally casts the normalized +results back to the original type of ``X``. The second stage does not +depend on ``stash_type``. + +When the number of groups is the same as the number of channels, this +operator is equivalent to InstanceNormalization. When there is only one +group, this operator is equivalent to LayerNormalization. + +Parameters +========== +X + Type T. + Input data tensor. Dimensions for image cases are ``(N x C x H x W)``, + where ``N`` is the batch size, ``C`` is the number of channels, and + ``H`` and ``W`` are the height and width of the data. Statistics are + computed for every group of channels over ``C``, ``H``, and ``W``. For + non-image cases, the dimensions are in the form of + ``(N x C x D1 x D2 ... Dn)``. +scale + Type T. + Scale tensor of shape ``(C)``. +bias + Type T. + Bias tensor of shape ``(C)``. +epsilon + Attribute. + The epsilon value to use to avoid division by zero. +num_groups + Attribute. + The number of groups of channels. It should be a divisor of the number + of channels ``C``. +stash_type + Attribute. + The floating-point precision used in stage one of the computation. + +Returns +======= +Y : Var + Type T. + The output tensor of the same shape as ``X``. + +Notes +===== +Signature: ``ai.onnx@21::GroupNormalization``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return ( - _GroupNormalization( - _GroupNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - num_groups=AttrInt64(num_groups, name="num_groups"), - stash_type=AttrInt64(stash_type, name="stash_type"), - ), - _GroupNormalization.Inputs( - X=unwrap_vars(X), - scale=unwrap_vars(scale), - bias=unwrap_vars(bias), - ), - ) - .get_output_vars( - X=get_value(X), - scale=get_value(scale), - bias=get_value(bias), - ) - .Y - ) + return _GroupNormalization( + _GroupNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + num_groups=AttrInt64(num_groups, name="num_groups"), + stash_type=AttrInt64(stash_type, name="stash_type"), + ), _GroupNormalization.Inputs( + X=unwrap_vars(X), scale=unwrap_vars(scale), bias=unwrap_vars(bias), ), ).get_output_vars( + X=get_value(X), scale=get_value(scale), bias=get_value(bias), ).Y -def identity( - input: Var, -) -> Var: +def identity(input: Var, ) -> Var: r""" - Identity operator - - Parameters - ========== - input - Type V. - Input tensor - - Returns - ======= - output : Var - Type V. - Tensor to copy input into. - - Notes - ===== - Signature: ``ai.onnx@21::Identity``. - - Type constraints: - - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Identity operator + +Parameters +========== +input + Type V. + Input tensor + +Returns +======= +output : Var + Type V. + Tensor to copy input into. + +Notes +===== +Signature: ``ai.onnx@21::Identity``. + +Type constraints: + - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Identity( - _Identity.Attributes(), - _Identity.Inputs( - input=unwrap_vars(input), - ), - ) - .get_output_vars( - input=get_value(input), - ) - .output - ) + return _Identity( + _Identity.Attributes( + ), _Identity.Inputs( + input=unwrap_vars(input), ), ).get_output_vars( + input=get_value(input), ).output -def if_( - cond: Var, - *, - else_branch: Callable[[], Iterable[Var]], - then_branch: Callable[[], Iterable[Var]], -) -> Sequence[Var]: +def if_(cond: Var, *, else_branch: Callable[[], Iterable[Var]], then_branch: Callable[[], Iterable[Var]], ) -> Sequence[Var]: r""" - If conditional - - Parameters - ========== - cond - Type B. - Condition for the if. The tensor must contain a single element. - else_branch - Attribute. - Graph to run if condition is false. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the then_branch. - then_branch - Attribute. - Graph to run if condition is true. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the else_branch. - - Returns - ======= - outputs : Sequence[Var] - Type V. - Values that are live-out to the enclosing scope. The return values in - the ``then_branch`` and ``else_branch`` must be of the same data type. - The ``then_branch`` and ``else_branch`` may produce tensors with the - same element type and different shapes. If corresponding outputs from - the then-branch and the else-branch have static shapes S1 and S2, then - the shape of the corresponding output variable of the if-node (if - present) must be compatible with both S1 and S2 as it represents the - union of both possible shapes.For example, if in a model file, the first - output of ``then_branch`` is typed float tensor with shape [2] and the - first output of ``else_branch`` is another float tensor with shape [3], - If's first output should have (a) no shape set, or (b) a shape of rank 1 - with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank - 1 with a unique ``dim_param``. In contrast, the first output cannot have - the shape [2] since [2] and [3] are not compatible. - - Notes - ===== - Signature: ``ai.onnx@21::If``. - - Type constraints: - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int4))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint4))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int4))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint4))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +If conditional + +Parameters +========== +cond + Type B. + Condition for the if. The tensor must contain a single element. +else_branch + Attribute. + Graph to run if condition is false. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the then_branch. +then_branch + Attribute. + Graph to run if condition is true. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the else_branch. + +Returns +======= +outputs : Sequence[Var] + Type V. + Values that are live-out to the enclosing scope. The return values in + the ``then_branch`` and ``else_branch`` must be of the same data type. + The ``then_branch`` and ``else_branch`` may produce tensors with the + same element type and different shapes. If corresponding outputs from + the then-branch and the else-branch have static shapes S1 and S2, then + the shape of the corresponding output variable of the if-node (if + present) must be compatible with both S1 and S2 as it represents the + union of both possible shapes.For example, if in a model file, the first + output of ``then_branch`` is typed float tensor with shape [2] and the + first output of ``else_branch`` is another float tensor with shape [3], + If's first output should have (a) no shape set, or (b) a shape of rank 1 + with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank + 1 with a unique ``dim_param``. In contrast, the first output cannot have + the shape [2] since [2] and [3] are not compatible. + +Notes +===== +Signature: ``ai.onnx@21::If``. + +Type constraints: + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int4))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint4))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int4))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint4))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - _else_branch_subgraph: Graph = subgraph((), else_branch) - _then_branch_subgraph: Graph = subgraph((), then_branch) - return ( - _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), - _If.Inputs( - cond=unwrap_vars(cond), - ), - out_variadic=len(_else_branch_subgraph.requested_results), - ) - .get_output_vars( - cond=get_value(cond), - ) - .outputs + _else_branch_subgraph: Graph = subgraph( + (), + else_branch ) + _then_branch_subgraph: Graph = subgraph( + (), + then_branch + ) + return _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), _If.Inputs( + cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), ).get_output_vars( + cond=get_value(cond), ).outputs -def loop( - M: Optional[Var] = None, - cond: Optional[Var] = None, - v_initial: Sequence[Var] = (), - *, - body: Callable[..., Iterable[Var]], -) -> Sequence[Var]: +def loop(M: Optional[Var] = None, cond: Optional[Var] = None, v_initial: Sequence[Var] = (), *, body: Callable[..., Iterable[Var]], ) -> Sequence[Var]: r""" - Generic Looping construct. This loop has multiple termination - conditions: - - 1) Trip count. Iteration count specified at runtime. Set by specifying - the input M. Optional. Set to empty string to omit. Note that a - static trip count (specified at graph construction time) can be - specified by passing in a constant node for input M. - 2) Loop termination condition. This is an input to the op that - determines whether to run the first iteration and also a loop-carried - dependency for the body graph. The body graph must yield a value for - the condition variable, whether this input is provided or not. - - This table summarizes the operating modes of this operator with - equivalent C-style code: - - Operator inputs defined as (max_trip_count, condition_var). - - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } - - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } - - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } - - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } - - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } - - *Sample usage - cond as well as trip count* - - :: - - graph predict-net { - %a = Constant[value = ]() - %b = Constant[value = ]() - %keepgoing = Constant[value = ]() - %max_trip_count = Constant[value = ]() - %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) - return - } - - graph body-net ( - %i[INT32, scalar] // iteration number - %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used - %b_in[INT32, scalar] // incoming value of loop-carried-dependency b - ) { - %my_local = Add(%a, %b_in) - %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b - %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition - %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated - return %keepgoing_out, %b_out, %user_defined_val - } - - *Sample equivalent C code* - - :: - - { - /* User-defined code (enclosing scope) */ - int a = 3, b = 6; - bool keepgoing = true; // Analogous to input cond - /* End user-defined code */ - - /* Implicitly-defined code */ - const int max_trip_count = 10; // Analogous to input M - int user_defined_vals[]; // Imagine this is resizable - /* End implicitly-defined code */ - /* initialize loop-carried variables and scan-output variables */ - bool keepgoing_out = keepgoing - int b_out = b - - for (int i=0; i < max_trip_count && keepgoing_out; ++i) { - /* Implicitly-defined code: bind actual parameter values - to formal parameter variables of loop-body */ - bool keepgoing_in = keepgoing_out; - bool b_in = b_out; - - /* User-defined code (loop body) */ - int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine - b_out = a - b_in; - keepgoing_out = my_local > b_out; - user_defined_val = b_in + b_in; // b_in and b_out are different variables - /* End user-defined code */ - - /* Implicitly defined-code */ - user_defined_vals[i] = user_defined_val // accumulate scan-output values - } - // int t = my_local; // Can't do this. my_local is not accessible here. - - // The values below are bound to the output variables of the loop and therefore accessible - // b_out; user_defined_vals; keepgoing_out; - } - - There are several things of note in this code snippet: - - 1) Values from the enclosing scope (i.e. variable "a" here) are in scope - and can be referenced in the inputs of the loop. - 2) Any values computed in the loop body that needs to be used in a - subsequent iteration or after the loop are modelled using a pair of - variables in the loop-body, consisting of an input variable (eg., - b_in) and an output variable (eg., b_out). These are referred to as - loop-carried dependences. The loop operation node supplies the input - value of the input variable for the first iteration, and returns the - output value of the output variable produced by the final iteration. - 3) Scan_output variables are used to implicitly concatenate values - computed across all the iterations. In the above example, the value - of user_defined_val computed over all iterations are concatenated and - returned as the value of user_defined_vals after the loop. - 4) Values created in the body cannot be accessed in the enclosing scope, - except using the mechanism described above. - - Note that the semantics of this op support "diagonal" or "wavefront" - execution. (See Step 3 here for an example: - https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). - Frontends should emit multi-layer RNNs as a series of While operators - (with time being the inner looping dimension), with each successive - layer consuming the scan_outputs from the previous layer, possibly going - through several point-wise operators (e.g. dropout, residual - connections, linear layer). - - The input/output of subgraph (produced by loop node) matching is based - on order instead of name. The implementation will figure out the names - based on this order. - - Parameters - ========== - M - Type I. - A maximum trip-count for the loop specified at runtime. Optional. Pass - empty string to skip. - cond - Type B. - A boolean termination condition. Optional. Pass empty string to skip. - v_initial - Type V. - The initial values of any loop-carried dependencies (values that change - across loop iterations) - body - Attribute. - The graph run each iteration. It has 2+N inputs: (iteration_num, - condition, loop carried dependencies...). It has 1+N+K outputs: - (condition, loop carried dependencies..., scan_outputs...). Each - scan_output is created by concatenating the value of the specified - output value at the end of each iteration of the loop. It is an error if - the dimensions or data type of these scan_outputs change across loop - iterations. - - Returns - ======= - v_final_and_scan_outputs : Sequence[Var] - Type V. - Final N loop carried dependency values then K scan_outputs. Scan outputs - must be Tensors. - - Notes - ===== - Signature: ``ai.onnx@21::Loop``. - - Type constraints: - - I: `tensor(int64)` - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int4))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint4))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int4))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint4))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Generic Looping construct. This loop has multiple termination +conditions: + +1) Trip count. Iteration count specified at runtime. Set by specifying + the input M. Optional. Set to empty string to omit. Note that a + static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. +2) Loop termination condition. This is an input to the op that + determines whether to run the first iteration and also a loop-carried + dependency for the body graph. The body graph must yield a value for + the condition variable, whether this input is provided or not. + +This table summarizes the operating modes of this operator with +equivalent C-style code: + +Operator inputs defined as (max_trip_count, condition_var). + +- input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } + +- input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } + +- input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } + +- input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } + +- input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } + +*Sample usage - cond as well as trip count* + +:: + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + +*Sample equivalent C code* + +:: + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + +There are several things of note in this code snippet: + +1) Values from the enclosing scope (i.e. variable "a" here) are in scope + and can be referenced in the inputs of the loop. +2) Any values computed in the loop body that needs to be used in a + subsequent iteration or after the loop are modelled using a pair of + variables in the loop-body, consisting of an input variable (eg., + b_in) and an output variable (eg., b_out). These are referred to as + loop-carried dependences. The loop operation node supplies the input + value of the input variable for the first iteration, and returns the + output value of the output variable produced by the final iteration. +3) Scan_output variables are used to implicitly concatenate values + computed across all the iterations. In the above example, the value + of user_defined_val computed over all iterations are concatenated and + returned as the value of user_defined_vals after the loop. +4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + +Note that the semantics of this op support "diagonal" or "wavefront" +execution. (See Step 3 here for an example: +https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). +Frontends should emit multi-layer RNNs as a series of While operators +(with time being the inner looping dimension), with each successive +layer consuming the scan_outputs from the previous layer, possibly going +through several point-wise operators (e.g. dropout, residual +connections, linear layer). + +The input/output of subgraph (produced by loop node) matching is based +on order instead of name. The implementation will figure out the names +based on this order. + +Parameters +========== +M + Type I. + A maximum trip-count for the loop specified at runtime. Optional. Pass + empty string to skip. +cond + Type B. + A boolean termination condition. Optional. Pass empty string to skip. +v_initial + Type V. + The initial values of any loop-carried dependencies (values that change + across loop iterations) +body + Attribute. + The graph run each iteration. It has 2+N inputs: (iteration_num, + condition, loop carried dependencies...). It has 1+N+K outputs: + (condition, loop carried dependencies..., scan_outputs...). Each + scan_output is created by concatenating the value of the specified + output value at the end of each iteration of the loop. It is an error if + the dimensions or data type of these scan_outputs change across loop + iterations. + +Returns +======= +v_final_and_scan_outputs : Sequence[Var] + Type V. + Final N loop carried dependency values then K scan_outputs. Scan outputs + must be Tensors. + +Notes +===== +Signature: ``ai.onnx@21::Loop``. + +Type constraints: + - I: `tensor(int64)` + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int4))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint4))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int4))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint4))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ _body_subgraph: Graph = subgraph( - typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))]) - + [var.unwrap_type() for var in v_initial], - body, - ) - return ( - _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), - _Loop.Inputs( - M=unwrap_vars(M), - cond=unwrap_vars(cond), - v_initial=unwrap_vars(v_initial), - ), - out_variadic=len(_body_subgraph.requested_results) - 1, - ) - .get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), - ) - .v_final_and_scan_outputs + typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))])+ [var.unwrap_type() for var in v_initial], + body ) + return _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), _Loop.Inputs( + M=unwrap_vars(M), cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, ).get_output_vars( + M=get_value(M), cond=get_value(cond), v_initial=get_value(v_initial), ).v_final_and_scan_outputs -def pad( - data: Var, - pads: Var, - constant_value: Optional[Var] = None, - axes: Optional[Var] = None, - *, - mode: str = "constant", -) -> Var: +def pad(data: Var, pads: Var, constant_value: Optional[Var] = None, axes: Optional[Var] = None, *, mode: str = "constant", ) -> Var: r""" - Given a tensor containing the data to be padded (``data``), a tensor - containing the number of start and end pad values for axis (``pads``), - (optionally) a ``mode``, and (optionally) ``constant_value``, a padded - tensor (``output``) is generated. +Given a tensor containing the data to be padded (``data``), a tensor +containing the number of start and end pad values for axis (``pads``), +(optionally) a ``mode``, and (optionally) ``constant_value``, a padded +tensor (``output``) is generated. - The three supported ``modes`` are (similar to corresponding modes - supported by ``numpy.pad``): +The three supported ``modes`` are (similar to corresponding modes +supported by ``numpy.pad``): - 1) ``constant``\ (default) - pads with a given constant value as - specified by ``constant_value`` (which defaults to 0, empty string, - or False) +1) ``constant``\ (default) - pads with a given constant value as + specified by ``constant_value`` (which defaults to 0, empty string, + or False) - 2) ``reflect`` - pads with the reflection of the vector mirrored on the - first and last values of the vector along each axis +2) ``reflect`` - pads with the reflection of the vector mirrored on the + first and last values of the vector along each axis - 3) ``edge`` - pads with the edge values of array +3) ``edge`` - pads with the edge values of array - 4) ``wrap`` - wrap-around padding as if the data tensor forms a torus +4) ``wrap`` - wrap-around padding as if the data tensor forms a torus - Example 1 (``constant`` mode): +Example 1 (``constant`` mode): - Insert 0 pads to the beginning of the second dimension. +Insert 0 pads to the beginning of the second dimension. - :: +:: - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] - pads = [0, 2, 0, 0] - - mode = 'constant' - - constant_value = 0.0 - - output = [ - [0.0, 0.0, 1.0, 1.2], - [0.0, 0.0, 2.3, 3.4], - [0.0, 0.0, 4.5, 5.7], - ] - - Example 2 (``reflect`` mode): - - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'reflect' - - output = [ - [1.0, 1.2, 1.0, 1.2], - [2.3, 3.4, 2.3, 3.4], - [4.5, 5.7, 4.5, 5.7], - ] - - Example 3 (``edge`` mode): - - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'edge' - - output = [ - [1.0, 1.0, 1.0, 1.2], - [2.3, 2.3, 2.3, 3.4], - [4.5, 4.5, 4.5, 5.7], - ] - - Example 4 (``wrap`` mode): - - :: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [2, 1, 1, 1] - - mode = 'wrap' - - output = [ - [3.4, 2.3, 3.4, 2.3], - [5.7, 4.5, 5.7, 4.5], - [1.2, 1.0, 1.2, 1.0], - [3.4, 2.3, 3.4, 2.3], - [5.7, 4.5, 5.7, 4.5], - [1.2, 1.0, 1.2, 1.0], - ] - - Parameters - ========== - data - Type T. - Input tensor. - pads - Type tensor(int64). - Tensor of integers indicating the number of padding elements to add or - remove (if negative) at the beginning and end of each axis. For 2D input - tensor, it is the number of pixels. ``pads`` should be a 1D tensor of - shape [2 \* num_axes] where ``num_axes`` refers to the number of - elements in the ``axes`` input or the input rank if ``axes`` are not - provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, - ..., x1_end, x2_end,...], where xi_begin is the number of pad values - added at the beginning of axis ``axes[i]`` and xi_end, the number of pad - values added at the end of axis ``axes[i]``. - constant_value - Type T. - (Optional) A scalar value to be used if the mode chosen is ``constant`` - (by default it is 0, empty string or False). - axes - Type Tind. - 1-D tensor of axes that ``pads`` apply to. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(data). Behavior is undefined if an axis is repeated. If not - provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). - mode - Attribute. - Supported modes: ``constant``\ (default), ``reflect``, ``edge``, - ``wrap`` - - Returns - ======= - output : Var - Type T. - Tensor after padding. - - Notes - ===== - Signature: ``ai.onnx@21::Pad``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + +Example 2 (``reflect`` mode): + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] + +Example 3 (``edge`` mode): + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] + +Example 4 (``wrap`` mode): + +:: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [2, 1, 1, 1] + + mode = 'wrap' + + output = [ + [3.4, 2.3, 3.4, 2.3], + [5.7, 4.5, 5.7, 4.5], + [1.2, 1.0, 1.2, 1.0], + [3.4, 2.3, 3.4, 2.3], + [5.7, 4.5, 5.7, 4.5], + [1.2, 1.0, 1.2, 1.0], + ] + +Parameters +========== +data + Type T. + Input tensor. +pads + Type tensor(int64). + Tensor of integers indicating the number of padding elements to add or + remove (if negative) at the beginning and end of each axis. For 2D input + tensor, it is the number of pixels. ``pads`` should be a 1D tensor of + shape [2 \* num_axes] where ``num_axes`` refers to the number of + elements in the ``axes`` input or the input rank if ``axes`` are not + provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, + ..., x1_end, x2_end,...], where xi_begin is the number of pad values + added at the beginning of axis ``axes[i]`` and xi_end, the number of pad + values added at the end of axis ``axes[i]``. +constant_value + Type T. + (Optional) A scalar value to be used if the mode chosen is ``constant`` + (by default it is 0, empty string or False). +axes + Type Tind. + 1-D tensor of axes that ``pads`` apply to. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(data). Behavior is undefined if an axis is repeated. If not + provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). +mode + Attribute. + Supported modes: ``constant``\ (default), ``reflect``, ``edge``, + ``wrap`` + +Returns +======= +output : Var + Type T. + Tensor after padding. + +Notes +===== +Signature: ``ai.onnx@21::Pad``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return ( - _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), - _Pad.Inputs( - data=unwrap_vars(data), - pads=unwrap_vars(pads), - constant_value=unwrap_vars(constant_value), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), - ) - .output - ) + return _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), _Pad.Inputs( + data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), pads=get_value(pads), constant_value=get_value(constant_value), axes=get_value(axes), ).output -def qlinear_matmul( - a: Var, - a_scale: Var, - a_zero_point: Var, - b: Var, - b_scale: Var, - b_zero_point: Var, - y_scale: Var, - y_zero_point: Var, -) -> Var: +def qlinear_matmul(a: Var, a_scale: Var, a_zero_point: Var, b: Var, b_scale: Var, b_zero_point: Var, y_scale: Var, y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. - It consumes two quantized input tensors, their scales and zero points, - scale and zero point of output, and computes the quantized output. The - quantization formula is y = saturate((x / y_scale) + y_zero_point). For - (x / y_scale), it is rounding to nearest ties to even. Refer to - https://en.wikipedia.org/wiki/Rounding for details. Scale and zero point - must have same shape. They must be either scalar (per tensor) or N-D - tensor (per row for 'a' and per column for 'b'). Scalar refers to per - tensor quantization whereas N-D refers to per row or per column - quantization. If the input is 2D of shape [M, K] then zero point and - scale tensor may be an M element vector [v_1, v_2, ..., v_M] for per row - quantization and K element vector of shape [v_1, v_2, ..., v_K] for per - column quantization. If the input is N-D tensor with shape [D1, D2, M, - K] then zero point and scale tensor may have shape [D1, D2, M, 1] for - per row quantization and shape [D1, D2, 1, K] for per column - quantization. Production must never overflow, and accumulation may - overflow if and only if in 32 bits. - - Parameters - ========== - a - Type T1. - N-dimensional quantized matrix a - a_scale - Type TS. - scale of quantized input a - a_zero_point - Type T1. - zero point of quantized input a - b - Type T2. - N-dimensional quantized matrix b - b_scale - Type TS. - scale of quantized input b - b_zero_point - Type T2. - zero point of quantized input b - y_scale - Type TS. - scale of quantized output y - y_zero_point - Type T3. - zero point of quantized output y - - Returns - ======= - y : Var - Type T3. - Quantized matrix multiply results from a \* b - - Notes - ===== - Signature: ``ai.onnx@21::QLinearMatMul``. - - Type constraints: - - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` - - TS: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` +Matrix product that behaves like numpy.matmul: +https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. +It consumes two quantized input tensors, their scales and zero points, +scale and zero point of output, and computes the quantized output. The +quantization formula is y = saturate((x / y_scale) + y_zero_point). For +(x / y_scale), it is rounding to nearest ties to even. Refer to +https://en.wikipedia.org/wiki/Rounding for details. Scale and zero point +must have same shape. They must be either scalar (per tensor) or N-D +tensor (per row for 'a' and per column for 'b'). Scalar refers to per +tensor quantization whereas N-D refers to per row or per column +quantization. If the input is 2D of shape [M, K] then zero point and +scale tensor may be an M element vector [v_1, v_2, ..., v_M] for per row +quantization and K element vector of shape [v_1, v_2, ..., v_K] for per +column quantization. If the input is N-D tensor with shape [D1, D2, M, +K] then zero point and scale tensor may have shape [D1, D2, M, 1] for +per row quantization and shape [D1, D2, 1, K] for per column +quantization. Production must never overflow, and accumulation may +overflow if and only if in 32 bits. + +Parameters +========== +a + Type T1. + N-dimensional quantized matrix a +a_scale + Type TS. + scale of quantized input a +a_zero_point + Type T1. + zero point of quantized input a +b + Type T2. + N-dimensional quantized matrix b +b_scale + Type TS. + scale of quantized input b +b_zero_point + Type T2. + zero point of quantized input b +y_scale + Type TS. + scale of quantized output y +y_zero_point + Type T3. + zero point of quantized output y + +Returns +======= +y : Var + Type T3. + Quantized matrix multiply results from a \* b + +Notes +===== +Signature: ``ai.onnx@21::QLinearMatMul``. + +Type constraints: + - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` + - TS: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - return ( - _QLinearMatMul( - _QLinearMatMul.Attributes(), - _QLinearMatMul.Inputs( - a=unwrap_vars(a), - a_scale=unwrap_vars(a_scale), - a_zero_point=unwrap_vars(a_zero_point), - b=unwrap_vars(b), - b_scale=unwrap_vars(b_scale), - b_zero_point=unwrap_vars(b_zero_point), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ) - .get_output_vars( - a=get_value(a), - a_scale=get_value(a_scale), - a_zero_point=get_value(a_zero_point), - b=get_value(b), - b_scale=get_value(b_scale), - b_zero_point=get_value(b_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - ) - .y - ) + return _QLinearMatMul( + _QLinearMatMul.Attributes( + ), _QLinearMatMul.Inputs( + a=unwrap_vars(a), a_scale=unwrap_vars(a_scale), a_zero_point=unwrap_vars(a_zero_point), b=unwrap_vars(b), b_scale=unwrap_vars(b_scale), b_zero_point=unwrap_vars(b_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( + a=get_value(a), a_scale=get_value(a_scale), a_zero_point=get_value(a_zero_point), b=get_value(b), b_scale=get_value(b_scale), b_zero_point=get_value(b_zero_point), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y -def quantize_linear( - x: Var, - y_scale: Var, - y_zero_point: Optional[Var] = None, - *, - axis: int = 1, - block_size: int = 0, - output_dtype: int = 0, - saturate: int = 1, -) -> Var: +def quantize_linear(x: Var, y_scale: Var, y_zero_point: Optional[Var] = None, *, axis: int = 1, block_size: int = 0, output_dtype: int = 0, saturate: int = 1, ) -> Var: r""" - The linear quantization operator consumes a high-precision tensor, a - scale, and a zero point to compute the low-precision/quantized tensor. - The scale factor and zero point must have the same shape, determining - the quantization granularity. The quantization formula is - ``y = saturate((x / y_scale) + y_zero_point)``. - - Saturation is done according to: - - - uint16: [0, 65535] - - int16: [-32768, 32767] - - uint8: [0, 255] - - int8: [-128, 127] - - uint4: [0, 15] - - int4: [-8, 7] - - For ``(x / y_scale)``, it rounds to the nearest even. Refer to - https://en.wikipedia.org/wiki/Rounding for details. - - ``y_zero_point`` and ``y`` must have the same type. ``y_zero_point`` is - usually not used for quantization to float8 types, but the quantization - formula remains the same for consistency, and the type of the attribute - ``y_zero_point`` still determines the quantization type. - - There are three supported quantization granularities, determined by the - shape of ``y_scale``. In all cases, ``y_zero_point`` must have the same - shape as ``y_scale``. - - - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. - - Per-axis quantization: The scale must be a 1-D tensor, with the - length of the quantization axis. For an input shape - ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D - tensor of length ``Di``. - - Blocked quantization: The scale's shape is identical to the input's - shape, except for one dimension, in which blocking is performed. - Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block - size ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. - - Parameters - ========== - x - Type T1. - N-D full precision Input tensor to be quantized. - y_scale - Type T1. - Scale for doing quantization to get ``y``. For per-tensor/layer - quantization the scale is a scalar, for per-axis quantization it is a - 1-D Tensor and for blocked quantization it has the same shape as the - input, except for one dimension in which blocking is performed. - y_zero_point - Type T2. - Zero point for doing quantization to get ``y``. Shape must match - ``y_scale``.Default is uint8 with zero point of 0 if it's not specified. - axis - Attribute. - (Optional) The axis of the dequantizing dimension of the input tensor. - Used for per-axis and blocked quantization. Negative value means - counting dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. - block_size - Attribute. - (Optional) The size of the quantization block (number of times every - scale is replicated). Used only for blocked quantization. The block size - is a positive integer. Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, - ``y_scale`` shape ``(S0, ... Si, ...Sn)`` and ``axis=i``, the accepted - range is ``[ceil(Di/Si), ceil(Di/(Si-1))-1]`` - output_dtype - Attribute. - (Optional) The output data type. If not supplied, the output data type - is inferred from ``y_zero_point`` data type (``T2``). If neither - ``output_dtype`` nor ``y_zero_point`` are supplied, output data type is - uint8. If both ``output_dtype`` and ``y_zero_point`` are specified, - ``output_dtype`` must be ``T2``. - saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. All cases are fully described in two tables - inserted in the operator description. - - Returns - ======= - y : Var - Type T2. - N-D quantized output tensor. It has same shape as input ``x``. - - Notes - ===== - Signature: ``ai.onnx@21::QuantizeLinear``. - - Type constraints: - - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` +The linear quantization operator consumes a high-precision tensor, a +scale, and a zero point to compute the low-precision/quantized tensor. +The scale factor and zero point must have the same shape, determining +the quantization granularity. The quantization formula is +``y = saturate((x / y_scale) + y_zero_point)``. + +Saturation is done according to: + +- uint16: [0, 65535] +- int16: [-32768, 32767] +- uint8: [0, 255] +- int8: [-128, 127] +- uint4: [0, 15] +- int4: [-8, 7] + +For ``(x / y_scale)``, it rounds to the nearest even. Refer to +https://en.wikipedia.org/wiki/Rounding for details. + +``y_zero_point`` and ``y`` must have the same type. ``y_zero_point`` is +usually not used for quantization to float8 types, but the quantization +formula remains the same for consistency, and the type of the attribute +``y_zero_point`` still determines the quantization type. + +There are three supported quantization granularities, determined by the +shape of ``y_scale``. In all cases, ``y_zero_point`` must have the same +shape as ``y_scale``. + +- Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. +- Per-axis quantization: The scale must be a 1-D tensor, with the + length of the quantization axis. For an input shape + ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D + tensor of length ``Di``. +- Blocked quantization: The scale's shape is identical to the input's + shape, except for one dimension, in which blocking is performed. + Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block + size ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. + +Parameters +========== +x + Type T1. + N-D full precision Input tensor to be quantized. +y_scale + Type T1. + Scale for doing quantization to get ``y``. For per-tensor/layer + quantization the scale is a scalar, for per-axis quantization it is a + 1-D Tensor and for blocked quantization it has the same shape as the + input, except for one dimension in which blocking is performed. +y_zero_point + Type T2. + Zero point for doing quantization to get ``y``. Shape must match + ``y_scale``.Default is uint8 with zero point of 0 if it's not specified. +axis + Attribute. + (Optional) The axis of the dequantizing dimension of the input tensor. + Used for per-axis and blocked quantization. Negative value means + counting dimensions from the back. Accepted range is ``[-r, r-1]`` where + ``r = rank(input)``. +block_size + Attribute. + (Optional) The size of the quantization block (number of times every + scale is replicated). Used only for blocked quantization. The block size + is a positive integer. Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, + ``y_scale`` shape ``(S0, ... Si, ...Sn)`` and ``axis=i``, the accepted + range is ``[ceil(Di/Si), ceil(Di/(Si-1))-1]`` +output_dtype + Attribute. + (Optional) The output data type. If not supplied, the output data type + is inferred from ``y_zero_point`` data type (``T2``). If neither + ``output_dtype`` nor ``y_zero_point`` are supplied, output data type is + uint8. If both ``output_dtype`` and ``y_zero_point`` are specified, + ``output_dtype`` must be ``T2``. +saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. All cases are fully described in two tables + inserted in the operator description. + +Returns +======= +y : Var + Type T2. + N-D quantized output tensor. It has same shape as input ``x``. + +Notes +===== +Signature: ``ai.onnx@21::QuantizeLinear``. + +Type constraints: + - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` + - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` """ - return ( - _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - block_size=AttrInt64(block_size, name="block_size"), - output_dtype=AttrInt64(output_dtype, name="output_dtype"), - saturate=AttrInt64(saturate, name="saturate"), - ), - _QuantizeLinear.Inputs( - x=unwrap_vars(x), - y_scale=unwrap_vars(y_scale), - y_zero_point=unwrap_vars(y_zero_point), - ), - ) - .get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - ) - .y - ) - - -def reshape( - data: Var, - shape: Var, - *, - allowzero: int = 0, -) -> Var: + return _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + block_size=AttrInt64(block_size, name="block_size"), + output_dtype=AttrInt64(output_dtype, name="output_dtype"), + saturate=AttrInt64(saturate, name="saturate"), + ), _QuantizeLinear.Inputs( + x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( + x=get_value(x), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y + + +def reshape(data: Var, shape: Var, *, allowzero: int = 0, ) -> Var: r""" - Reshape the input tensor similar to numpy.reshape. First input is the - data tensor, second input is a shape tensor which specifies the output - shape. It outputs the reshaped tensor. At most one dimension of the new - shape can be -1. In this case, the value is inferred from the size of - the tensor and the remaining dimensions. A dimension could also be 0, in - which case the actual dimension value is unchanged (i.e. taken from the - input tensor). If 'allowzero' is set, and the new shape includes 0, the - dimension will be set explicitly to zero (i.e. not taken from input - tensor). Shape (second input) could be an empty shape, which means - converting to a scalar. The input tensor's shape and the output tensor's - shape are required to have the same number of elements. - - If the attribute 'allowzero' is set, it is invalid for the specified - shape to contain both a zero value and -1, as the value of the dimension - corresponding to -1 cannot be determined uniquely. - - Parameters - ========== - data - Type T. - An input tensor. - shape - Type tensor(int64). - Specified shape for output. - allowzero - Attribute. - (Optional) By default, when any value in the 'shape' input is equal to - zero the corresponding dimension value is copied from the input tensor - dynamically. allowzero=1 indicates that if any value in the 'shape' - input is set to zero, the zero value is honored, similar to NumPy. - - Returns - ======= - reshaped : Var - Type T. - Reshaped data. - - Notes - ===== - Signature: ``ai.onnx@21::Reshape``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Reshape the input tensor similar to numpy.reshape. First input is the +data tensor, second input is a shape tensor which specifies the output +shape. It outputs the reshaped tensor. At most one dimension of the new +shape can be -1. In this case, the value is inferred from the size of +the tensor and the remaining dimensions. A dimension could also be 0, in +which case the actual dimension value is unchanged (i.e. taken from the +input tensor). If 'allowzero' is set, and the new shape includes 0, the +dimension will be set explicitly to zero (i.e. not taken from input +tensor). Shape (second input) could be an empty shape, which means +converting to a scalar. The input tensor's shape and the output tensor's +shape are required to have the same number of elements. + +If the attribute 'allowzero' is set, it is invalid for the specified +shape to contain both a zero value and -1, as the value of the dimension +corresponding to -1 cannot be determined uniquely. + +Parameters +========== +data + Type T. + An input tensor. +shape + Type tensor(int64). + Specified shape for output. +allowzero + Attribute. + (Optional) By default, when any value in the 'shape' input is equal to + zero the corresponding dimension value is copied from the input tensor + dynamically. allowzero=1 indicates that if any value in the 'shape' + input is set to zero, the zero value is honored, similar to NumPy. + +Returns +======= +reshaped : Var + Type T. + Reshaped data. + +Notes +===== +Signature: ``ai.onnx@21::Reshape``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), - _Reshape.Inputs( - data=unwrap_vars(data), - shape=unwrap_vars(shape), - ), - ) - .get_output_vars( - data=get_value(data), - shape=get_value(shape), - ) - .reshaped - ) + return _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), _Reshape.Inputs( + data=unwrap_vars(data), shape=unwrap_vars(shape), ), ).get_output_vars( + data=get_value(data), shape=get_value(shape), ).reshaped -def scan( - initial_state_and_scan_inputs: Sequence[Var], - *, - body: Callable[..., Iterable[Var]], - num_scan_inputs: int, - scan_input_axes: Optional[Iterable[int]] = None, - scan_input_directions: Optional[Iterable[int]] = None, - scan_output_axes: Optional[Iterable[int]] = None, - scan_output_directions: Optional[Iterable[int]] = None, -) -> Sequence[Var]: +def scan(initial_state_and_scan_inputs: Sequence[Var], *, body: Callable[..., Iterable[Var]], num_scan_inputs: int, scan_input_axes: Optional[Iterable[int]] = None, scan_input_directions: Optional[Iterable[int]] = None, scan_output_axes: Optional[Iterable[int]] = None, scan_output_directions: Optional[Iterable[int]] = None, ) -> Sequence[Var]: r""" - Scan can be used to iterate over one or more scan_input tensors, - constructing zero or more scan_output tensors. It combines ideas from - general recurrences, functional programming constructs such as scan, - fold, map, and zip, and is intended to enable generalizations of - RNN-like constructs for sequence-to-sequence processing. Other tensors - (referred to as state_variables here) can be used to carry a state when - iterating from one element to another (similar to hidden-state in RNNs, - also referred to as loop-carried dependences in the context of loops). - Many common usages involve a single scan_input tensor (where - functionality similar to scan, fold and map can be obtained). When more - than one scan_input is used, a behavior similar to zip is obtained. - - The attribute body must be a graph, specifying the computation to be - performed in every iteration. It takes as input the current values of - the state_variables and the current iterated element of the scan_inputs. - It must return the (updated) values of the state_variables and zero or - more scan_output_element tensors. The values of the scan_output_element - tensors are concatenated over all the iterations to produce the - scan_output values of the scan construct (similar to the concatenated - intermediate hidden-state values of RNN-like constructs). All the output - tensors (state_variables as well as scan_output_element tensors) are - required to have the same shape in each iteration of the loop (a - restriction imposed to enable efficient memory allocation). - - Note that the iterated element passed to the body subgraph does not have - a sequence axis. It will have a rank one less than the rank of the - corresponding scan_input. - - The scan operation returns the final values of the state_variables as - well as the scan_outputs. - - The optional attribute scan_input_directions specifies the direction - (forward or backward) for each scan input. If this attribute is omitted, - all sequences are scanned in the forward direction. A bidirectional scan - may be performed by specifying the same tensor input twice in the - scan_inputs, once with a forward direction, and once with a backward - direction. - - The scan_output of the operation is produced by concatenating the - scan_output_element values produced by the body in each iteration. The - optional attribute scan_output_directions specifies the direction in - which scan_output is constructed (by appending or prepending the - scan_output_element to scan_output in each iteration) for each - scan_output. If this attribute is omitted, the scan_output_element is - appended to the scan_output in each iteration. - - The optional attribute scan_input_axes specifies the axis to be scanned - for each scan_input. If omitted, every scan_input will be scanned in - axis 0. For example, if axis 0 is the batch axis and axis 1 is the time - axis (to be scanned), specify an axis value of 1. Note that scanning a - non-zero axis may be less efficient than scanning axis zero. - - The optional attribute scan_output_axes specifies the axis along which - the scan_outputs are accumulated for each scan_output. For example, if - axis 1 is the time axis (to be scanned) for both inputs and outputs, - specify a scan_input axis and scan_output axis value of 1. - - Note that because of the ONNX restriction that only the last parameter - of an operator can be variadic, the initial-states and scan-inputs are - listed together as one input parameter. Similarly, the final-states and - scan-outputs are listed together as one output parameter. The attribute - num_scan_inputs indicates the number M of scan-inputs. - - The behavior of - - :: - - Scan < - num_scan_inputs = m, - body = loop-body, - scan_input_axes = [axis_1, ..., axis_m] - > (init_1, ..., init_n, scan_1, ..., scan_m) - - is equivalent to the following pseudo-code: - - :: - - // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i - // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. - sequence_length = scan_1.shape[axis_1]; - - // initialize state-variables - st_1 = init_1; ... st_n = init_n; - // initialize scan-output variables: [] denotes an empty tensor - scan_out_1 = []; ...; scan_out_k = []; - // identify number of iterations: - - // execute loop - for (int t = 0; t < sequence_length; ++t) { - // generate the scan-input elements: the notation T[t] indicates the sub-tensor - // of rank one less than T obtained by indexing T at position t along axis k. - si_1 = scan_1[t]; - ... ; - si_m = scan_m[t]; - // execute loop-body - st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) - // accumulate the scan-output elements - scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); - } - - return st_1, ..., st_n, scan_out_1, ..., scan_out_k; - - *Sample usage: Encoding RNN using a Scan* - - The following example shows how a simple RNN over an input tensor %X, - with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi - and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. - Note that the loop-body is a nested graph, and it directly computes %Wi, - %Ri, %Wbi, and %Rbi (typically constants or initializers in the body - graph). If these values are computed in the outer graph, they need to be - passed in as extra state_variables. - - :: - - graph rnn-encoding { - %H_0 = ... - %X = ... - %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) - return %Y, %Y_h - } - - graph rnn-cell-1 ( - %H_tminus1[FLOAT, tensor] - %X_t[FLOAT, tensor] - ) { - %Wi = ... - %Ri = ... - %Wbi = ... - %Rbi = ... - %t1 = X_t * (Wi^T) - %t2 = H_tminus1*(Ri^T) - %t3 = Add(%t1, %t2) - %t4 = Add(%t3, %Wbi) - %t5 = Add(%t4, %Rbi) - %Ht = Tanh(%t5) - %Accumulate = Identity(%Ht) - return %Ht, %Accumulate - } - - Parameters - ========== - initial_state_and_scan_inputs - Type V. - Initial values of the loop's N state variables followed by M scan_inputs - body - Attribute. - The graph run each iteration. It has N+M inputs: (loop state - variables..., scan_input_elts...). It has N+K outputs: (loop state - variables..., scan_output_elts...). Each scan_output is created by - concatenating the value of the specified scan_output_elt value at the - end of each iteration of the loop. It is an error if the dimensions of - these values change across loop iterations. - num_scan_inputs - Attribute. - An attribute specifying the number of scan_inputs M. - scan_input_axes - Attribute. - An optional list of M flags. The i-th element of the list specifies the - axis to be scanned (the sequence axis) for the i-th scan_input. If - omitted, 0 will be used as the scan axis for every scan_input. Negative - value for an axis means counting dimensions from the back. Accepted - range is [-r, r-1] where r = rank(input). - scan_input_directions - Attribute. - An optional list of M flags. The i-th element of the list specifies the - direction to be scanned for the i-th scan_input tensor: 0 indicates - forward direction and 1 indicates reverse direction. If omitted, all - scan_input tensors will be scanned in the forward direction. - scan_output_axes - Attribute. - An optional list of K flags. The i-th element of the list specifies the - axis for the i-th scan_output. The scan outputs are accumulated along - the specified axis. If omitted, 0 will be used as the scan axis for - every scan_output. Negative value for an axis means counting dimensions - from the back. Accepted range is [-r, r-1]. - scan_output_directions - Attribute. - An optional list of K flags, one for each scan_output. The i-th element - of the list specifies whether the i-th scan_output should be constructed - by appending or prepending a new value in each iteration: 0 indicates - appending and 1 indicates prepending. If omitted, all scan_output - tensors will be produced by appending a value in each iteration. - - Returns - ======= - final_state_and_scan_outputs : Sequence[Var] - Type V. - Final values of the loop's N state variables followed by K scan_outputs - - Notes - ===== - Signature: ``ai.onnx@21::Scan``. - - Type constraints: - - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Scan can be used to iterate over one or more scan_input tensors, +constructing zero or more scan_output tensors. It combines ideas from +general recurrences, functional programming constructs such as scan, +fold, map, and zip, and is intended to enable generalizations of +RNN-like constructs for sequence-to-sequence processing. Other tensors +(referred to as state_variables here) can be used to carry a state when +iterating from one element to another (similar to hidden-state in RNNs, +also referred to as loop-carried dependences in the context of loops). +Many common usages involve a single scan_input tensor (where +functionality similar to scan, fold and map can be obtained). When more +than one scan_input is used, a behavior similar to zip is obtained. + +The attribute body must be a graph, specifying the computation to be +performed in every iteration. It takes as input the current values of +the state_variables and the current iterated element of the scan_inputs. +It must return the (updated) values of the state_variables and zero or +more scan_output_element tensors. The values of the scan_output_element +tensors are concatenated over all the iterations to produce the +scan_output values of the scan construct (similar to the concatenated +intermediate hidden-state values of RNN-like constructs). All the output +tensors (state_variables as well as scan_output_element tensors) are +required to have the same shape in each iteration of the loop (a +restriction imposed to enable efficient memory allocation). + +Note that the iterated element passed to the body subgraph does not have +a sequence axis. It will have a rank one less than the rank of the +corresponding scan_input. + +The scan operation returns the final values of the state_variables as +well as the scan_outputs. + +The optional attribute scan_input_directions specifies the direction +(forward or backward) for each scan input. If this attribute is omitted, +all sequences are scanned in the forward direction. A bidirectional scan +may be performed by specifying the same tensor input twice in the +scan_inputs, once with a forward direction, and once with a backward +direction. + +The scan_output of the operation is produced by concatenating the +scan_output_element values produced by the body in each iteration. The +optional attribute scan_output_directions specifies the direction in +which scan_output is constructed (by appending or prepending the +scan_output_element to scan_output in each iteration) for each +scan_output. If this attribute is omitted, the scan_output_element is +appended to the scan_output in each iteration. + +The optional attribute scan_input_axes specifies the axis to be scanned +for each scan_input. If omitted, every scan_input will be scanned in +axis 0. For example, if axis 0 is the batch axis and axis 1 is the time +axis (to be scanned), specify an axis value of 1. Note that scanning a +non-zero axis may be less efficient than scanning axis zero. + +The optional attribute scan_output_axes specifies the axis along which +the scan_outputs are accumulated for each scan_output. For example, if +axis 1 is the time axis (to be scanned) for both inputs and outputs, +specify a scan_input axis and scan_output axis value of 1. + +Note that because of the ONNX restriction that only the last parameter +of an operator can be variadic, the initial-states and scan-inputs are +listed together as one input parameter. Similarly, the final-states and +scan-outputs are listed together as one output parameter. The attribute +num_scan_inputs indicates the number M of scan-inputs. + +The behavior of + +:: + + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) + +is equivalent to the following pseudo-code: + +:: + + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + +*Sample usage: Encoding RNN using a Scan* + +The following example shows how a simple RNN over an input tensor %X, +with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi +and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. +Note that the loop-body is a nested graph, and it directly computes %Wi, +%Ri, %Wbi, and %Rbi (typically constants or initializers in the body +graph). If these values are computed in the outer graph, they need to be +passed in as extra state_variables. + +:: + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + +Parameters +========== +initial_state_and_scan_inputs + Type V. + Initial values of the loop's N state variables followed by M scan_inputs +body + Attribute. + The graph run each iteration. It has N+M inputs: (loop state + variables..., scan_input_elts...). It has N+K outputs: (loop state + variables..., scan_output_elts...). Each scan_output is created by + concatenating the value of the specified scan_output_elt value at the + end of each iteration of the loop. It is an error if the dimensions of + these values change across loop iterations. +num_scan_inputs + Attribute. + An attribute specifying the number of scan_inputs M. +scan_input_axes + Attribute. + An optional list of M flags. The i-th element of the list specifies the + axis to be scanned (the sequence axis) for the i-th scan_input. If + omitted, 0 will be used as the scan axis for every scan_input. Negative + value for an axis means counting dimensions from the back. Accepted + range is [-r, r-1] where r = rank(input). +scan_input_directions + Attribute. + An optional list of M flags. The i-th element of the list specifies the + direction to be scanned for the i-th scan_input tensor: 0 indicates + forward direction and 1 indicates reverse direction. If omitted, all + scan_input tensors will be scanned in the forward direction. +scan_output_axes + Attribute. + An optional list of K flags. The i-th element of the list specifies the + axis for the i-th scan_output. The scan outputs are accumulated along + the specified axis. If omitted, 0 will be used as the scan axis for + every scan_output. Negative value for an axis means counting dimensions + from the back. Accepted range is [-r, r-1]. +scan_output_directions + Attribute. + An optional list of K flags, one for each scan_output. The i-th element + of the list specifies whether the i-th scan_output should be constructed + by appending or prepending a new value in each iteration: 0 indicates + appending and 1 indicates prepending. If omitted, all scan_output + tensors will be produced by appending a value in each iteration. + +Returns +======= +final_state_and_scan_outputs : Sequence[Var] + Type V. + Final values of the loop's N state variables followed by K scan_outputs + +Notes +===== +Signature: ``ai.onnx@21::Scan``. + +Type constraints: + - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ _body_subgraph: Graph = subgraph( - [ - Tensor( - var.unwrap_tensor().dtype, - (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape), - ) - for var in initial_state_and_scan_inputs[:num_scan_inputs] - ] - + [ - Tensor(var.unwrap_tensor().dtype) - for var in initial_state_and_scan_inputs[num_scan_inputs:] - ], - body, - ) - return ( - _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe( - scan_input_axes, name="scan_input_axes" - ), - scan_input_directions=AttrInt64s.maybe( - scan_input_directions, name="scan_input_directions" - ), - scan_output_axes=AttrInt64s.maybe( - scan_output_axes, name="scan_output_axes" - ), - scan_output_directions=AttrInt64s.maybe( - scan_output_directions, name="scan_output_directions" - ), - ), - _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars( - initial_state_and_scan_inputs - ), - ), - out_variadic=len(_body_subgraph.requested_results), - ) - .get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), - ) - .final_state_and_scan_outputs + [Tensor(var.unwrap_tensor().dtype, (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape)) for var in initial_state_and_scan_inputs[:num_scan_inputs]] + [Tensor(var.unwrap_tensor().dtype) for var in initial_state_and_scan_inputs[num_scan_inputs:]], + body ) - - -def shape( - data: Var, - *, - end: Optional[int] = None, - start: int = 0, -) -> Var: + return _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), + scan_input_directions=AttrInt64s.maybe(scan_input_directions, name="scan_input_directions"), + scan_output_axes=AttrInt64s.maybe(scan_output_axes, name="scan_output_axes"), + scan_output_directions=AttrInt64s.maybe(scan_output_directions, name="scan_output_directions"), + ), _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), ).final_state_and_scan_outputs + + +def shape(data: Var, *, end: Optional[int] = None, start: int = 0, ) -> Var: r""" - Takes a tensor as input and outputs an 1D int64 tensor containing the - shape of the input tensor. Optional attributes start and end can be used - to compute a slice of the input tensor's shape. If start axis is - omitted, the slice starts from axis 0. The end axis, if specified, is - exclusive (and the returned value will not include the size of that - axis). If the end axis is omitted, the axes upto the last one will be - included. Negative axes indicate counting back from the last axis. Note - that axes will be clamped to the range [0, r-1], where r is the rank of - the input tensor if they are out-of-range (after adding r in the case of - negative axis). Thus, specifying any end value > r is equivalent to - specifying an end value of r, and specifying any start value < -r is - equivalent to specifying a start value of 0. - - Examples: - - :: - - Input tensor with shape: [2, 3, 4] - No attributes specified. - Output: [2, 3, 4] - - :: - - Input tensor with shape: [2, 3, 4] - start: -1 - Output: [4] - - :: - - Input tensor with shape: [2, 3, 4] - end: -1 - Output: [2, 3] - - :: - - Input tensor with shape: [2, 3, 4] - start: 1 - end: 2 - Output: [3] - - Parameters - ========== - data - Type T. - An input tensor. - end - Attribute. - (Optional) Ending axis for slicing the shape. Negative value means - counting dimensions from the back. If omitted, sizes of all axes upto - (including) the last one will be included. - start - Attribute. - (Optional) Starting axis for slicing the shape. Default value is - 0.Negative value means counting dimensions from the back. - - Returns - ======= - shape : Var - Type T1. - Shape of the input tensor - - Notes - ===== - Signature: ``ai.onnx@21::Shape``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` +Takes a tensor as input and outputs an 1D int64 tensor containing the +shape of the input tensor. Optional attributes start and end can be used +to compute a slice of the input tensor's shape. If start axis is +omitted, the slice starts from axis 0. The end axis, if specified, is +exclusive (and the returned value will not include the size of that +axis). If the end axis is omitted, the axes upto the last one will be +included. Negative axes indicate counting back from the last axis. Note +that axes will be clamped to the range [0, r-1], where r is the rank of +the input tensor if they are out-of-range (after adding r in the case of +negative axis). Thus, specifying any end value > r is equivalent to +specifying an end value of r, and specifying any start value < -r is +equivalent to specifying a start value of 0. + +Examples: + +:: + + Input tensor with shape: [2, 3, 4] + No attributes specified. + Output: [2, 3, 4] + +:: + + Input tensor with shape: [2, 3, 4] + start: -1 + Output: [4] + +:: + + Input tensor with shape: [2, 3, 4] + end: -1 + Output: [2, 3] + +:: + + Input tensor with shape: [2, 3, 4] + start: 1 + end: 2 + Output: [3] + +Parameters +========== +data + Type T. + An input tensor. +end + Attribute. + (Optional) Ending axis for slicing the shape. Negative value means + counting dimensions from the back. If omitted, sizes of all axes upto + (including) the last one will be included. +start + Attribute. + (Optional) Starting axis for slicing the shape. Default value is + 0.Negative value means counting dimensions from the back. + +Returns +======= +shape : Var + Type T1. + Shape of the input tensor + +Notes +===== +Signature: ``ai.onnx@21::Shape``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` """ - return ( - _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), - _Shape.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .shape - ) + return _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), _Shape.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).shape -def size( - data: Var, -) -> Var: +def size(data: Var, ) -> Var: r""" - Takes a tensor as input and outputs a int64 scalar that equals to the - total number of elements of the input tensor. - - Parameters - ========== - data - Type T. - An input tensor. - - Returns - ======= - size : Var - Type T1. - Total number of elements of the input tensor - - Notes - ===== - Signature: ``ai.onnx@21::Size``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` +Takes a tensor as input and outputs a int64 scalar that equals to the +total number of elements of the input tensor. + +Parameters +========== +data + Type T. + An input tensor. + +Returns +======= +size : Var + Type T1. + Total number of elements of the input tensor + +Notes +===== +Signature: ``ai.onnx@21::Size``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` """ - return ( - _Size( - _Size.Attributes(), - _Size.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .size - ) + return _Size( + _Size.Attributes( + ), _Size.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).size -def squeeze( - data: Var, - axes: Optional[Var] = None, -) -> Var: +def squeeze(data: Var, axes: Optional[Var] = None, ) -> Var: r""" - Remove single-dimensional entries from the shape of a tensor. Takes an - input ``axes`` with a list of axes to squeeze. If ``axes`` is not - provided, all the single dimensions will be removed from the shape. If - an axis is selected with shape entry not equal to one, an error is - raised. - - Parameters - ========== - data - Type T. - Tensors with at least max(dims) dimensions. - axes - Type tensor(int64). - List of integers indicating the dimensions to squeeze. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(data). - - Returns - ======= - squeezed : Var - Type T. - Reshaped tensor with same data as input. - - Notes - ===== - Signature: ``ai.onnx@21::Squeeze``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Remove single-dimensional entries from the shape of a tensor. Takes an +input ``axes`` with a list of axes to squeeze. If ``axes`` is not +provided, all the single dimensions will be removed from the shape. If +an axis is selected with shape entry not equal to one, an error is +raised. + +Parameters +========== +data + Type T. + Tensors with at least max(dims) dimensions. +axes + Type tensor(int64). + List of integers indicating the dimensions to squeeze. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(data). + +Returns +======= +squeezed : Var + Type T. + Reshaped tensor with same data as input. + +Notes +===== +Signature: ``ai.onnx@21::Squeeze``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Squeeze( - _Squeeze.Attributes(), - _Squeeze.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .squeezed - ) + return _Squeeze( + _Squeeze.Attributes( + ), _Squeeze.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).squeezed -def transpose( - data: Var, - *, - perm: Optional[Iterable[int]] = None, -) -> Var: +def transpose(data: Var, *, perm: Optional[Iterable[int]] = None, ) -> Var: r""" - Transpose the input tensor similar to numpy.transpose. For example, when - perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output - shape will be (2, 1, 3). - - Parameters - ========== - data - Type T. - An input tensor. - perm - Attribute. - A list of integers. By default, reverse the dimensions, otherwise - permute the axes according to the values given. Its length must be equal - to the rank of the input. - - Returns - ======= - transposed : Var - Type T. - Transposed output. - - Notes - ===== - Signature: ``ai.onnx@21::Transpose``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Transpose the input tensor similar to numpy.transpose. For example, when +perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output +shape will be (2, 1, 3). + +Parameters +========== +data + Type T. + An input tensor. +perm + Attribute. + A list of integers. By default, reverse the dimensions, otherwise + permute the axes according to the values given. Its length must be equal + to the rank of the input. + +Returns +======= +transposed : Var + Type T. + Transposed output. + +Notes +===== +Signature: ``ai.onnx@21::Transpose``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Transpose( - _Transpose.Attributes( - perm=AttrInt64s.maybe(perm, name="perm"), - ), - _Transpose.Inputs( - data=unwrap_vars(data), - ), - ) - .get_output_vars( - data=get_value(data), - ) - .transposed - ) + return _Transpose( + _Transpose.Attributes( + perm=AttrInt64s.maybe(perm, name="perm"), + ), _Transpose.Inputs( + data=unwrap_vars(data), ), ).get_output_vars( + data=get_value(data), ).transposed -def unsqueeze( - data: Var, - axes: Var, -) -> Var: +def unsqueeze(data: Var, axes: Var, ) -> Var: r""" - Insert single-dimensional entries to the shape of an input tensor - (``data``). Takes one required input ``axes`` - which contains a list of - dimension indices and this operator will insert a dimension of value - ``1`` into the corresponding index of the output tensor (``expanded``). - - For example, given an input tensor (``data``) of shape [3, 4, 5], then - Unsqueeze(data, axes=[0, 4]) outputs a tensor (``expanded``) containing - same data as ``data`` but with shape [1, 3, 4, 5, 1]. - - The input ``axes`` should not contain any duplicate entries. It is an - error if it contains duplicates. The rank of the output tensor - (``output_rank``) is the rank of the input tensor (``data``) plus the - number of values in ``axes``. Each value in ``axes`` should be within - the (inclusive) range [-output_rank , output_rank - 1]. The order of - values in ``axes`` does not matter and can come in any order. - - Parameters - ========== - data - Type T. - Original tensor - axes - Type tensor(int64). - List of integers indicating the dimensions to be inserted. Negative - value means counting dimensions from the back. Accepted range is [-r, - r-1] where r = rank(expanded). - - Returns - ======= - expanded : Var - Type T. - Reshaped tensor with same data as input. - - Notes - ===== - Signature: ``ai.onnx@21::Unsqueeze``. - - Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` +Insert single-dimensional entries to the shape of an input tensor +(``data``). Takes one required input ``axes`` - which contains a list of +dimension indices and this operator will insert a dimension of value +``1`` into the corresponding index of the output tensor (``expanded``). + +For example, given an input tensor (``data``) of shape [3, 4, 5], then +Unsqueeze(data, axes=[0, 4]) outputs a tensor (``expanded``) containing +same data as ``data`` but with shape [1, 3, 4, 5, 1]. + +The input ``axes`` should not contain any duplicate entries. It is an +error if it contains duplicates. The rank of the output tensor +(``output_rank``) is the rank of the input tensor (``data``) plus the +number of values in ``axes``. Each value in ``axes`` should be within +the (inclusive) range [-output_rank , output_rank - 1]. The order of +values in ``axes`` does not matter and can come in any order. + +Parameters +========== +data + Type T. + Original tensor +axes + Type tensor(int64). + List of integers indicating the dimensions to be inserted. Negative + value means counting dimensions from the back. Accepted range is [-r, + r-1] where r = rank(expanded). + +Returns +======= +expanded : Var + Type T. + Reshaped tensor with same data as input. + +Notes +===== +Signature: ``ai.onnx@21::Unsqueeze``. + +Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return ( - _Unsqueeze( - _Unsqueeze.Attributes(), - _Unsqueeze.Inputs( - data=unwrap_vars(data), - axes=unwrap_vars(axes), - ), - ) - .get_output_vars( - data=get_value(data), - axes=get_value(axes), - ) - .expanded - ) + return _Unsqueeze( + _Unsqueeze.Attributes( + ), _Unsqueeze.Inputs( + data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( + data=get_value(data), axes=get_value(axes), ).expanded def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -3154,4 +2635,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/tests/test_custom_operator.py b/tests/test_custom_operator.py index fc102a8e..ae149742 100644 --- a/tests/test_custom_operator.py +++ b/tests/test_custom_operator.py @@ -44,7 +44,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: # This is technically optional, but using an operator without type inference may be inconvenient. if self.inputs.X.type is None: return {} diff --git a/tests/test_function.py b/tests/test_function.py index ce6ec4ca..7405ede7 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -44,7 +44,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: + def constructor(self, attrs: dict[str, Attr], inputs: Inputs.Vars) -> Outputs: # FIXME: At some point, attribute references should be properly type-hinted. a = op.constant( value_float=_Ref( diff --git a/tools/templates/class.jinja2 b/tools/templates/class.jinja2 index f5d6a4fa..b362e963 100644 --- a/tools/templates/class.jinja2 +++ b/tools/templates/class.jinja2 @@ -47,7 +47,7 @@ class _{{ schema.name }}(StandardNode): {% endif %} {% if type_inference %} - def infer_output_types(self) -> dict[str, Type]: + def infer_output_types(self, initializers={}) -> dict[str, Type]: {% filter indent(width=8) %} {%+ include type_inference %} {% endfilter %} From 27c562e0142394e20f87cea14f9e578b1a95f45f Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Tue, 5 Nov 2024 22:53:28 +0200 Subject: [PATCH 10/29] Fix passing --- src/spox/_fields.py | 19 +- src/spox/_function.py | 6 +- src/spox/_internal_op.py | 4 +- src/spox/_node.py | 10 +- src/spox/_standard.py | 34 +- src/spox/opset/ai/onnx/ml/v3.py | 2634 ++-- src/spox/opset/ai/onnx/ml/v4.py | 306 +- src/spox/opset/ai/onnx/ml/v5.py | 372 +- src/spox/opset/ai/onnx/v17.py | 23066 +++++++++++++++++------------- src/spox/opset/ai/onnx/v18.py | 4196 +++--- src/spox/opset/ai/onnx/v19.py | 3973 ++--- src/spox/opset/ai/onnx/v20.py | 2236 +-- src/spox/opset/ai/onnx/v21.py | 3887 ++--- 13 files changed, 22964 insertions(+), 17779 deletions(-) diff --git a/src/spox/_fields.py b/src/spox/_fields.py index 03ae7419..e350f965 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -6,8 +6,7 @@ import warnings from collections.abc import Iterable, Iterator, Sequence from dataclasses import dataclass -from typing import Any, Optional, Union -from typing_extensions import Self +from typing import Any, Generic, Optional, TypeVar, Union from ._attributes import Attr from ._exceptions import InferenceWarning @@ -158,13 +157,16 @@ def fully_typed(self) -> bool: ) +TypeBaseVars = TypeVar("TypeBaseVars", bound=BaseVars) + + @dataclass -class BaseInputs(BaseVarInfos, metaclass=BaseVarsMeta): +class BaseInputs(BaseVarInfos, Generic[TypeBaseVars], metaclass=BaseVarsMeta): @dataclass class Vars(BaseVars): pass - def vars(self, prop_values) -> Vars: + def vars(self, prop_values) -> TypeBaseVars: vars_structure: dict[str, Union[Var, Sequence[Var]]] = {} for field in dataclasses.fields(self): @@ -189,10 +191,11 @@ def vars(self, prop_values) -> Vars: vars_structure[field.name] = vars - return self.Vars(**vars_structure) + return self.__class__.Vars(**vars_structure) # type: ignore + @dataclass -class BaseOutputs(BaseVarInfos, metaclass=BaseVarsMeta): +class BaseOutputs(BaseVarInfos, Generic[TypeBaseVars], metaclass=BaseVarsMeta): @dataclass class Vars(BaseVars): pass @@ -201,7 +204,7 @@ def _propagate_vars( self, prop_values={}, flatten_variadic=False, - ): + ) -> TypeBaseVars: def _create_var(key, var_info): ret = Var(var_info, None) @@ -234,4 +237,4 @@ def _create_var(key, var_info): _create_var(f"{key}_{i}", v) for i, v in enumerate(var_info) ] - return ret_dict + return self.__class__.Vars(**ret_dict) # type: ignore diff --git a/src/spox/_function.py b/src/spox/_function.py index 98654111..57c18f7d 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -81,7 +81,7 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: self.func_inputs = self.Inputs(**self.func_args) # type: ignore self.func_outputs = self.constructor(self.func_attrs, self.func_inputs) self.func_graph = _graph.results( - **self.func_outputs._propagate_vars() + **self.func_outputs._propagate_vars(initializers).get_vars() ).with_arguments(*func_args_var.values()) return { @@ -147,7 +147,9 @@ class Attributes(BaseAttributes): op_type = OpType(name, domain, version) def constructor(self, attrs, inputs): - return self.Outputs(*unwrap_vars(fun(*wrap_vars(inputs.get_fields().values())))) + return self.Outputs( + *unwrap_vars(fun(*wrap_vars(inputs.get_fields().values()))) + ) return _Func diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index 7ed71b01..cc3bc7a8 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -73,11 +73,11 @@ class Attributes(BaseAttributes): default: Optional[AttrTensor] = None @dataclass - class Inputs(BaseInputs): + class Inputs(BaseInputs["Argument.Outputs.Vars"]): pass @dataclass - class Outputs(BaseOutputs): + class Outputs(BaseOutputs["Argument.Outputs.Vars"]): arg: VarInfo attrs: Attributes diff --git a/src/spox/_node.py b/src/spox/_node.py index de40b7d7..06c3a323 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -226,7 +226,9 @@ def infer_output_types(self, initializers) -> dict[str, Type]: def inference(self, infer_types: bool = True, initializers={}): # Type inference routine - call infer_output_types if required # and check if it provides the expected outputs. - out_types = self.infer_output_types(initializers=initializers) if infer_types else {} + out_types = ( + self.infer_output_types(initializers=initializers) if infer_types else {} + ) for key, var in self.outputs.get_vars().items(): if var.type is None: # If no existing type from init_output_vars @@ -236,10 +238,8 @@ def inference(self, infer_types: bool = True, initializers={}): def get_output_vars(self, flatten_variadic=False, **initializers): # After typing everything, try to get values for outputs out_values = self.propagate_values(initializers) - return type(self.outputs).Vars( - **self.outputs._propagate_vars( - out_values, flatten_variadic=flatten_variadic - ) + return self.outputs._propagate_vars( + out_values, flatten_variadic=flatten_variadic ) def validate_types(self) -> None: diff --git a/src/spox/_standard.py b/src/spox/_standard.py index 9767fb4a..37affd3b 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -3,14 +3,13 @@ """Module implementing a base for standard ONNX operators, which use the functionality of ONNX node-level inference.""" +from collections.abc import Iterable from typing import TYPE_CHECKING, Callable import onnx -from onnx.numpy_helper import from_array import onnx.reference import onnx.shape_inference from onnx.defs import OpSchema -import numpy as np from . import _value_prop from ._exceptions import InferenceError @@ -19,8 +18,8 @@ from ._scope import Scope from ._shape import SimpleShape from ._type_system import Optional, Sequence, Tensor, Type -from ._value_prop import PropValueType from ._utils import from_array +from ._value_prop import PropValue, PropValueType if TYPE_CHECKING: from ._graph import Graph @@ -51,7 +50,11 @@ def min_output(self) -> int: return self.schema.min_output def to_singleton_onnx_model( - self, *, dummy_outputs: bool = True, with_dummy_subgraphs: bool = True, prop_values={} + self, + *, + dummy_outputs: bool = True, + with_dummy_subgraphs: bool = True, + prop_values={}, ) -> tuple[onnx.ModelProto, Scope]: """ Build a singleton model consisting of just this StandardNode. Used for type inference. @@ -100,11 +103,26 @@ def out_value_info(curr_key, curr_var): ] # Initializers, passed in to allow partial data propagation # - used so that operators like Reshape are aware of constant shapes - initializers = [ + # TODO: fix this + initializers_from_array = [ from_array(prop.value, name) # type: ignore for name, prop in prop_values.items() - if prop is not None and isinstance(prop.value, np.ndarray) + if isinstance(prop, PropValue) + and prop.value is not None + and not isinstance(prop.type, Sequence) ] + + initializers_from_sequence = [ + from_array(prop.value, f"{name}_{i}") # type: ignore + for name, prop_list in prop_values.items() + if isinstance(prop_list, list) + for i, prop in enumerate(prop_list) + if prop is not None and not isinstance(prop.value, Iterable) + ] + + initializers = initializers_from_array + initializers.extend(initializers_from_sequence) + # Graph and model graph = onnx.helper.make_graph( [node_proto], @@ -168,7 +186,9 @@ def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: if next(iter(self.subgraphs), None) is not None: # Cannot do propagation with subgraphs implicitly for performance - should be reimplemented return {} - model, scope = self.to_singleton_onnx_model(with_dummy_subgraphs=False, prop_values=initializers) + model, scope = self.to_singleton_onnx_model( + with_dummy_subgraphs=False, prop_values=initializers + ) wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() input_feed = { scope.var[var_info]: wrap_feed(initializers[name]) diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index 22fac5aa..536abd53 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -1,39 +1,29 @@ +# Copyright (c) QuantCo 2023-2024 +# SPDX-License-Identifier: BSD-3-Clause + # ruff: noqa: E741 -- Allow ambiguous variable name -import typing -import warnings -from dataclasses import dataclass from collections.abc import Iterable, Sequence +from dataclasses import dataclass from typing import ( - Any, - Callable, Optional, - Union, ) -from typing import cast as typing_cast import numpy as np -import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( - AttrDtype, AttrFloat32, AttrFloat32s, - AttrGraph, AttrInt64, AttrInt64s, AttrString, AttrStrings, AttrTensor, - AttrType, ) -from spox._graph import Graph, subgraph -from spox._internal_op import intro +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence -from spox._value_prop import PropValueType +from spox._type_system import Tensor, Type +from spox._var import Var, VarInfo, get_value, unwrap_vars class _ArrayFeatureExtractor(StandardNode): @@ -64,12 +54,14 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: return {"Z": Tensor(xt.dtype, (1, yt.shape[-1]))} shape = tuple(list(xt.shape[:-1]) + [yt.shape[-1]]) # type: ignore return {"Z": Tensor(xt.dtype, shape)} + op_type = OpType("ArrayFeatureExtractor", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs + class _Binarizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -85,12 +77,14 @@ class Outputs(BaseOutputs): def infer_output_types(self, initializers={}) -> dict[str, Type]: return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {} + op_type = OpType("Binarizer", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs + class _CastMap(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -112,6 +106,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _CategoryMapper(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -139,12 +134,14 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: t = self.inputs.X.unwrap_tensor() (elem_type,) = {np.int64, np.str_} - {t.dtype.type} # type: ignore return {"Y": Tensor(elem_type, t.shape)} + op_type = OpType("CategoryMapper", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs + class _DictVectorizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -165,6 +162,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _FeatureVectorizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -184,6 +182,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Imputer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -206,12 +205,20 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: t = self.inputs.X.unwrap_tensor() # We verify if the attributes are set correctly and matching the input elem type cases = { - np.int64: (self.attrs.imputed_value_int64s, self.attrs.replaced_value_int64), - np.float32: (self.attrs.imputed_value_floats, self.attrs.replaced_value_float) + np.int64: ( + self.attrs.imputed_value_int64s, + self.attrs.replaced_value_int64, + ), + np.float32: ( + self.attrs.imputed_value_floats, + self.attrs.replaced_value_float, + ), } for key, (imp, rep) in cases.items(): if t.dtype.type is key: - if not all(imp1 is None for key1, (imp1, rep1) in cases.items() if key != key1): + if not all( + imp1 is None for key1, (imp1, rep1) in cases.items() if key != key1 + ): raise InferenceError("Only one input imputed type may be set.") break else: @@ -222,14 +229,18 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: sim = t.shape last = sim[-1] if sim else 1 if isinstance(last, int) and len(imp.value) not in {1, last}: - raise InferenceError(f"Mismatched expected ({len(imp.value)}) and actual ({last}) feature count.") + raise InferenceError( + f"Mismatched expected ({len(imp.value)}) and actual ({last}) feature count." + ) return {"Y": t} + op_type = OpType("Imputer", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs + class _LabelEncoder(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -257,6 +268,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LinearClassifier(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -282,6 +294,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LinearRegressor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -311,12 +324,14 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: return {"Y": Tensor(np.float32, (1, 1))} else: raise InferenceError("Input shape must be at most a matrix.") + op_type = OpType("LinearRegressor", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs + class _Normalizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -332,14 +347,18 @@ class Outputs(BaseOutputs): def infer_output_types(self, initializers={}) -> dict[str, Type]: if self.attrs.norm.value not in ("MAX", "L1", "L2"): - raise InferenceError(f"Unknown normalisation method `{self.attrs.norm.value}`") + raise InferenceError( + f"Unknown normalisation method `{self.attrs.norm.value}`" + ) return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {} + op_type = OpType("Normalizer", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs + class _OneHotEncoder(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -367,15 +386,15 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: "Either `cats_int64s` or `cats_strings` attributes must be set." ) shape = (*self.inputs.X.unwrap_tensor().shape, n_encodings) # type: ignore - return { - "Y": Tensor(dtype=np.float32, shape=shape) - } + return {"Y": Tensor(dtype=np.float32, shape=shape)} + op_type = OpType("OneHotEncoder", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs + class _SVMClassifier(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -406,6 +425,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SVMRegressor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -432,6 +452,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Scaler(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -456,16 +477,22 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: # If the number of features is known (last row, we can check this here) last = t.shape[-1] if t.shape else 1 if isinstance(last, int) and len(sc.value) not in {1, last}: - raise InferenceError(f"Mismatched expected ({len(sc.value)}) and actual ({last}) feature count for scale.") + raise InferenceError( + f"Mismatched expected ({len(sc.value)}) and actual ({last}) feature count for scale." + ) if isinstance(last, int) and len(off.value) not in {1, last}: - raise InferenceError(f"Mismatched expected ({len(off.value)}) and actual ({last}) feature count for offset.") + raise InferenceError( + f"Mismatched expected ({len(off.value)}) and actual ({last}) feature count for offset." + ) return {"Y": Tensor(np.float32, t.shape)} + op_type = OpType("Scaler", "ai.onnx.ml", 1) attrs: Attributes inputs: Inputs outputs: Outputs + class _TreeEnsembleClassifier(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -516,19 +543,21 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: ) if self.inputs.fully_typed: shape = self.inputs.X.unwrap_tensor().shape - assert shape is not None # already checked with fully_typed + assert shape is not None # already checked with fully_typed if len(shape) != 2: raise InferenceError("Expected input to be a matrix.") n = shape[0] else: n = None return {"Y": Tensor(y_type, (n,)), "Z": Tensor(np.float32, (n, e))} + op_type = OpType("TreeEnsembleClassifier", "ai.onnx.ml", 3) attrs: Attributes inputs: Inputs outputs: Outputs + class _TreeEnsembleRegressor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -574,12 +603,14 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: n = None e = self.attrs.n_targets.value if self.attrs.n_targets is not None else None return {"Y": Tensor(np.float32, (n, e))} + op_type = OpType("TreeEnsembleRegressor", "ai.onnx.ml", 3) attrs: Attributes inputs: Inputs outputs: Outputs + class _ZipMap(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -600,1137 +631,1518 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs -def array_feature_extractor(X: Var, Y: Var, ) -> Var: - r""" -Select elements of the input tensor based on the indices passed. The -indices are applied to the last axes of the tensor. - -Parameters -========== -X - Type T. - Data to be selected -Y - Type tensor(int64). - The indices, based on 0 as the first index of any dimension. - -Returns -======= -Z : Var - Type T. - Selected output data as an array - -Notes -===== -Signature: ``ai.onnx.ml@1::ArrayFeatureExtractor``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` - """ - return _ArrayFeatureExtractor( - _ArrayFeatureExtractor.Attributes( - ), _ArrayFeatureExtractor.Inputs( - X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( - X=get_value(X), Y=get_value(Y), ).Z - -def binarizer(X: Var, *, threshold: float = 0.0, ) -> Var: +def array_feature_extractor( + X: Var, + Y: Var, +) -> Var: r""" -Maps the values of the input tensor to either 0 or 1, element-wise, -based on the outcome of a comparison against a threshold value. - -Parameters -========== -X - Type T. - Data to be binarized -threshold - Attribute. - Values greater than this are mapped to 1, others to 0. - -Returns -======= -Y : Var - Type T. - Binarized output data - -Notes -===== -Signature: ``ai.onnx.ml@1::Binarizer``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + Select elements of the input tensor based on the indices passed. The + indices are applied to the last axes of the tensor. + + Parameters + ========== + X + Type T. + Data to be selected + Y + Type tensor(int64). + The indices, based on 0 as the first index of any dimension. + + Returns + ======= + Z : Var + Type T. + Selected output data as an array + + Notes + ===== + Signature: ``ai.onnx.ml@1::ArrayFeatureExtractor``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - return _Binarizer( - _Binarizer.Attributes( - threshold=AttrFloat32(threshold, name="threshold"), - ), _Binarizer.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _ArrayFeatureExtractor( + _ArrayFeatureExtractor.Attributes(), + _ArrayFeatureExtractor.Inputs( + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + X=get_value(X), + Y=get_value(Y), + ) + .Z + ) -def cast_map(X: Var, *, cast_to: str = "TO_FLOAT", map_form: str = "DENSE", max_map: int = 1, ) -> Var: +def binarizer( + X: Var, + *, + threshold: float = 0.0, +) -> Var: r""" -Converts a map to a tensor.The map key must be an int64 and the values -will be ordered in ascending order based on this key.The operator -supports dense packing or sparse packing. If using sparse packing, the -key cannot exceed the max_map-1 value. - -Parameters -========== -X - Type T1. - The input map that is to be cast to a tensor -cast_to - Attribute. - A string indicating the desired element type of the output tensor, one - of 'TO_FLOAT', 'TO_STRING', 'TO_INT64'. -map_form - Attribute. - Indicates whether to only output as many values as are in the input - (dense), or position the input based on using the key of the map as the - index of the output (sparse).One of 'DENSE', 'SPARSE'. -max_map - Attribute. - If the value of map_form is 'SPARSE,' this attribute indicates the total - length of the output tensor. - -Returns -======= -Y : Var - Type T2. - A tensor representing the same data as the input map, ordered by their - keys - -Notes -===== -Signature: ``ai.onnx.ml@1::CastMap``. - -Type constraints: - - T1: `map(int64,tensor(float))`, `map(int64,tensor(string))` - - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` + Maps the values of the input tensor to either 0 or 1, element-wise, + based on the outcome of a comparison against a threshold value. + + Parameters + ========== + X + Type T. + Data to be binarized + threshold + Attribute. + Values greater than this are mapped to 1, others to 0. + + Returns + ======= + Y : Var + Type T. + Binarized output data + + Notes + ===== + Signature: ``ai.onnx.ml@1::Binarizer``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _CastMap( - _CastMap.Attributes( - cast_to=AttrString(cast_to, name="cast_to"), - map_form=AttrString(map_form, name="map_form"), - max_map=AttrInt64(max_map, name="max_map"), - ), _CastMap.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _Binarizer( + _Binarizer.Attributes( + threshold=AttrFloat32(threshold, name="threshold"), + ), + _Binarizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def category_mapper(X: Var, *, cats_int64s: Optional[Iterable[int]] = None, cats_strings: Optional[Iterable[str]] = None, default_int64: int = -1, default_string: str = "_Unused", ) -> Var: +def cast_map( + X: Var, + *, + cast_to: str = "TO_FLOAT", + map_form: str = "DENSE", + max_map: int = 1, +) -> Var: r""" -Converts strings to integers and vice versa. Two sequences of equal -length are used to map between integers and strings, with strings and -integers at the same index detailing the mapping. Each operator converts -either integers to strings or strings to integers, depending on which -default value attribute is provided. Only one default value attribute -should be defined. If the string default value is set, it will convert -integers to strings. If the int default value is set, it will convert -strings to integers. - -Parameters -========== -X - Type T1. - Input data -cats_int64s - Attribute. - The integers of the map. This sequence must be the same length as the - 'cats_strings' sequence. -cats_strings - Attribute. - The strings of the map. This sequence must be the same length as the - 'cats_int64s' sequence -default_int64 - Attribute. - An integer to use when an input string value is not found in the map.One - and only one of the 'default\_\*' attributes must be defined. -default_string - Attribute. - A string to use when an input integer value is not found in the map.One - and only one of the 'default\_\*' attributes must be defined. - -Returns -======= -Y : Var - Type T2. - Output data. If strings are input, the output values are integers, and - vice versa. - -Notes -===== -Signature: ``ai.onnx.ml@1::CategoryMapper``. - -Type constraints: - - T1: `tensor(int64)`, `tensor(string)` - - T2: `tensor(int64)`, `tensor(string)` + Converts a map to a tensor.The map key must be an int64 and the values + will be ordered in ascending order based on this key.The operator + supports dense packing or sparse packing. If using sparse packing, the + key cannot exceed the max_map-1 value. + + Parameters + ========== + X + Type T1. + The input map that is to be cast to a tensor + cast_to + Attribute. + A string indicating the desired element type of the output tensor, one + of 'TO_FLOAT', 'TO_STRING', 'TO_INT64'. + map_form + Attribute. + Indicates whether to only output as many values as are in the input + (dense), or position the input based on using the key of the map as the + index of the output (sparse).One of 'DENSE', 'SPARSE'. + max_map + Attribute. + If the value of map_form is 'SPARSE,' this attribute indicates the total + length of the output tensor. + + Returns + ======= + Y : Var + Type T2. + A tensor representing the same data as the input map, ordered by their + keys + + Notes + ===== + Signature: ``ai.onnx.ml@1::CastMap``. + + Type constraints: + - T1: `map(int64,tensor(float))`, `map(int64,tensor(string))` + - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return _CategoryMapper( - _CategoryMapper.Attributes( - cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), - cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - ), _CategoryMapper.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def dict_vectorizer(X: Var, *, int64_vocabulary: Optional[Iterable[int]] = None, string_vocabulary: Optional[Iterable[str]] = None, ) -> Var: + return ( + _CastMap( + _CastMap.Attributes( + cast_to=AttrString(cast_to, name="cast_to"), + map_form=AttrString(map_form, name="map_form"), + max_map=AttrInt64(max_map, name="max_map"), + ), + _CastMap.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def category_mapper( + X: Var, + *, + cats_int64s: Optional[Iterable[int]] = None, + cats_strings: Optional[Iterable[str]] = None, + default_int64: int = -1, + default_string: str = "_Unused", +) -> Var: r""" -Uses an index mapping to convert a dictionary to an array. Given a -dictionary, each key is looked up in the vocabulary attribute -corresponding to the key type. The index into the vocabulary array at -which the key is found is then used to index the output 1-D tensor 'Y' -and insert into it the value found in the dictionary 'X'. The key type -of the input map must correspond to the element type of the defined -vocabulary attribute. Therefore, the output array will be equal in -length to the index mapping vector parameter. All keys in the input -dictionary must be present in the index mapping vector. For each item in -the input dictionary, insert its value in the output array. Any keys not -present in the input dictionary, will be zero in the output array. For -example: if the ``string_vocabulary`` parameter is set to -``["a", "c", "b", "z"]``, then an input of ``{"a": 4, "c": 8}`` will -produce an output of ``[4, 8, 0, 0]``. - -Parameters -========== -X - Type T1. - A dictionary. -int64_vocabulary - Attribute. - An integer vocabulary array.One and only one of the vocabularies must be - defined. -string_vocabulary - Attribute. - A string vocabulary array.One and only one of the vocabularies must be - defined. - -Returns -======= -Y : Var - Type T2. - A 1-D tensor holding values from the input dictionary. - -Notes -===== -Signature: ``ai.onnx.ml@1::DictVectorizer``. - -Type constraints: - - T1: `map(int64,tensor(double))`, `map(int64,tensor(float))`, `map(int64,tensor(string))`, `map(string,tensor(double))`, `map(string,tensor(float))`, `map(string,tensor(int64))` - - T2: `tensor(double)`, `tensor(float)`, `tensor(int64)`, `tensor(string)` + Converts strings to integers and vice versa. Two sequences of equal + length are used to map between integers and strings, with strings and + integers at the same index detailing the mapping. Each operator converts + either integers to strings or strings to integers, depending on which + default value attribute is provided. Only one default value attribute + should be defined. If the string default value is set, it will convert + integers to strings. If the int default value is set, it will convert + strings to integers. + + Parameters + ========== + X + Type T1. + Input data + cats_int64s + Attribute. + The integers of the map. This sequence must be the same length as the + 'cats_strings' sequence. + cats_strings + Attribute. + The strings of the map. This sequence must be the same length as the + 'cats_int64s' sequence + default_int64 + Attribute. + An integer to use when an input string value is not found in the map.One + and only one of the 'default\_\*' attributes must be defined. + default_string + Attribute. + A string to use when an input integer value is not found in the map.One + and only one of the 'default\_\*' attributes must be defined. + + Returns + ======= + Y : Var + Type T2. + Output data. If strings are input, the output values are integers, and + vice versa. + + Notes + ===== + Signature: ``ai.onnx.ml@1::CategoryMapper``. + + Type constraints: + - T1: `tensor(int64)`, `tensor(string)` + - T2: `tensor(int64)`, `tensor(string)` """ - return _DictVectorizer( - _DictVectorizer.Attributes( - int64_vocabulary=AttrInt64s.maybe(int64_vocabulary, name="int64_vocabulary"), - string_vocabulary=AttrStrings.maybe(string_vocabulary, name="string_vocabulary"), - ), _DictVectorizer.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _CategoryMapper( + _CategoryMapper.Attributes( + cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), + cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + ), + _CategoryMapper.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def feature_vectorizer(X: Sequence[Var], *, inputdimensions: Optional[Iterable[int]] = None, ) -> Var: +def dict_vectorizer( + X: Var, + *, + int64_vocabulary: Optional[Iterable[int]] = None, + string_vocabulary: Optional[Iterable[str]] = None, +) -> Var: r""" -Concatenates input tensors into one continuous output. All input shapes -are 2-D and are concatenated along the second dimension. 1-D tensors are -treated as [1,C]. Inputs are copied to the output maintaining the order -of the input arguments. All inputs must be integers or floats, while the -output will be all floating point values. - -Parameters -========== -X - Type T1. - An ordered collection of tensors, all with the same element type. -inputdimensions - Attribute. - The size of each input in the input list - -Returns -======= -Y : Var - Type tensor(float). - The output array, elements ordered as the inputs. - -Notes -===== -Signature: ``ai.onnx.ml@1::FeatureVectorizer``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + Uses an index mapping to convert a dictionary to an array. Given a + dictionary, each key is looked up in the vocabulary attribute + corresponding to the key type. The index into the vocabulary array at + which the key is found is then used to index the output 1-D tensor 'Y' + and insert into it the value found in the dictionary 'X'. The key type + of the input map must correspond to the element type of the defined + vocabulary attribute. Therefore, the output array will be equal in + length to the index mapping vector parameter. All keys in the input + dictionary must be present in the index mapping vector. For each item in + the input dictionary, insert its value in the output array. Any keys not + present in the input dictionary, will be zero in the output array. For + example: if the ``string_vocabulary`` parameter is set to + ``["a", "c", "b", "z"]``, then an input of ``{"a": 4, "c": 8}`` will + produce an output of ``[4, 8, 0, 0]``. + + Parameters + ========== + X + Type T1. + A dictionary. + int64_vocabulary + Attribute. + An integer vocabulary array.One and only one of the vocabularies must be + defined. + string_vocabulary + Attribute. + A string vocabulary array.One and only one of the vocabularies must be + defined. + + Returns + ======= + Y : Var + Type T2. + A 1-D tensor holding values from the input dictionary. + + Notes + ===== + Signature: ``ai.onnx.ml@1::DictVectorizer``. + + Type constraints: + - T1: `map(int64,tensor(double))`, `map(int64,tensor(float))`, `map(int64,tensor(string))`, `map(string,tensor(double))`, `map(string,tensor(float))`, `map(string,tensor(int64))` + - T2: `tensor(double)`, `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return _FeatureVectorizer( - _FeatureVectorizer.Attributes( - inputdimensions=AttrInt64s.maybe(inputdimensions, name="inputdimensions"), - ), _FeatureVectorizer.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _DictVectorizer( + _DictVectorizer.Attributes( + int64_vocabulary=AttrInt64s.maybe( + int64_vocabulary, name="int64_vocabulary" + ), + string_vocabulary=AttrStrings.maybe( + string_vocabulary, name="string_vocabulary" + ), + ), + _DictVectorizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def imputer(X: Var, *, imputed_value_floats: Optional[Iterable[float]] = None, imputed_value_int64s: Optional[Iterable[int]] = None, replaced_value_float: float = 0.0, replaced_value_int64: int = 0, ) -> Var: +def feature_vectorizer( + X: Sequence[Var], + *, + inputdimensions: Optional[Iterable[int]] = None, +) -> Var: r""" -Replaces inputs that equal one value with another, leaving all other -elements alone. This operator is typically used to replace missing -values in situations where they have a canonical representation, such as --1, 0, NaN, or some extreme value. One and only one of -imputed_value_floats or imputed_value_int64s should be defined -- floats -if the input tensor holds floats, integers if the input tensor holds -integers. The imputed values must all fit within the width of the tensor -element type. One and only one of the replaced_value_float or -replaced_value_int64 should be defined, which one depends on whether -floats or integers are being processed. The imputed_value attribute -length can be 1 element, or it can have one element per input feature.In -other words, if the input tensor has the shape [\*,F], then the length -of the attribute array may be 1 or F. If it is 1, then it is broadcast -along the last dimension and applied to each feature. - -Parameters -========== -X - Type T. - Data to be processed. -imputed_value_floats - Attribute. - Value(s) to change to -imputed_value_int64s - Attribute. - Value(s) to change to. -replaced_value_float - Attribute. - A value that needs replacing. -replaced_value_int64 - Attribute. - A value that needs replacing. - -Returns -======= -Y : Var - Type T. - Imputed output data - -Notes -===== -Signature: ``ai.onnx.ml@1::Imputer``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + Concatenates input tensors into one continuous output. All input shapes + are 2-D and are concatenated along the second dimension. 1-D tensors are + treated as [1,C]. Inputs are copied to the output maintaining the order + of the input arguments. All inputs must be integers or floats, while the + output will be all floating point values. + + Parameters + ========== + X + Type T1. + An ordered collection of tensors, all with the same element type. + inputdimensions + Attribute. + The size of each input in the input list + + Returns + ======= + Y : Var + Type tensor(float). + The output array, elements ordered as the inputs. + + Notes + ===== + Signature: ``ai.onnx.ml@1::FeatureVectorizer``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _Imputer( - _Imputer.Attributes( - imputed_value_floats=AttrFloat32s.maybe(imputed_value_floats, name="imputed_value_floats"), - imputed_value_int64s=AttrInt64s.maybe(imputed_value_int64s, name="imputed_value_int64s"), - replaced_value_float=AttrFloat32(replaced_value_float, name="replaced_value_float"), - replaced_value_int64=AttrInt64(replaced_value_int64, name="replaced_value_int64"), - ), _Imputer.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def label_encoder(X: Var, *, default_float: float = -0.0, default_int64: int = -1, default_string: str = "_Unused", keys_floats: Optional[Iterable[float]] = None, keys_int64s: Optional[Iterable[int]] = None, keys_strings: Optional[Iterable[str]] = None, values_floats: Optional[Iterable[float]] = None, values_int64s: Optional[Iterable[int]] = None, values_strings: Optional[Iterable[str]] = None, ) -> Var: + return ( + _FeatureVectorizer( + _FeatureVectorizer.Attributes( + inputdimensions=AttrInt64s.maybe( + inputdimensions, name="inputdimensions" + ), + ), + _FeatureVectorizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def imputer( + X: Var, + *, + imputed_value_floats: Optional[Iterable[float]] = None, + imputed_value_int64s: Optional[Iterable[int]] = None, + replaced_value_float: float = 0.0, + replaced_value_int64: int = 0, +) -> Var: r""" -Maps each element in the input tensor to another value. The mapping is -determined by the two parallel attributes, 'keys\_\ *' and 'values\_*' -attribute. The i-th value in the specified 'keys\_\ *' attribute would -be mapped to the i-th value in the specified 'values\_*' attribute. It -implies that input's element type and the element type of the specified -'keys\_\ *' should be identical while the output type is identical to -the specified 'values\_*' attribute. If an input element can not be -found in the specified 'keys\_\ *' attribute, the 'default\_*' that -matches the specified 'values\_\ *' attribute may be used as its output -value. Let's consider an example which maps a string tensor to an -integer tensor. Assume and 'keys_strings' is ["Amy", "Sally"], -'values_int64s' is [5, 6], and 'default_int64' is '-1'. The input -["Dori", "Amy", "Amy", "Sally", "Sally"] would be mapped to [-1, 5, 5, -6, 6]. Since this operator is an one-to-one mapping, its input and -output shapes are the same. Notice that only one of -'keys\_*'/'values\_\ *' can be set. For key look-up, bit-wise comparison -is used so even a float NaN can be mapped to a value in 'values\_*' -attribute. - -Parameters -========== -X - Type T1. - Input data. It can be either tensor or scalar. -default_float - Attribute. - A float. -default_int64 - Attribute. - An integer. -default_string - Attribute. - A string. -keys_floats - Attribute. - A list of floats. -keys_int64s - Attribute. - A list of ints. -keys_strings - Attribute. - A list of strings. One and only one of 'keys\_\*'s should be set. -values_floats - Attribute. - A list of floats. -values_int64s - Attribute. - A list of ints. -values_strings - Attribute. - A list of strings. One and only one of 'value\_\*'s should be set. - -Returns -======= -Y : Var - Type T2. - Output data. - -Notes -===== -Signature: ``ai.onnx.ml@2::LabelEncoder``. - -Type constraints: - - T1: `tensor(float)`, `tensor(int64)`, `tensor(string)` - - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` + Replaces inputs that equal one value with another, leaving all other + elements alone. This operator is typically used to replace missing + values in situations where they have a canonical representation, such as + -1, 0, NaN, or some extreme value. One and only one of + imputed_value_floats or imputed_value_int64s should be defined -- floats + if the input tensor holds floats, integers if the input tensor holds + integers. The imputed values must all fit within the width of the tensor + element type. One and only one of the replaced_value_float or + replaced_value_int64 should be defined, which one depends on whether + floats or integers are being processed. The imputed_value attribute + length can be 1 element, or it can have one element per input feature.In + other words, if the input tensor has the shape [\*,F], then the length + of the attribute array may be 1 or F. If it is 1, then it is broadcast + along the last dimension and applied to each feature. + + Parameters + ========== + X + Type T. + Data to be processed. + imputed_value_floats + Attribute. + Value(s) to change to + imputed_value_int64s + Attribute. + Value(s) to change to. + replaced_value_float + Attribute. + A value that needs replacing. + replaced_value_int64 + Attribute. + A value that needs replacing. + + Returns + ======= + Y : Var + Type T. + Imputed output data + + Notes + ===== + Signature: ``ai.onnx.ml@1::Imputer``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _LabelEncoder( - _LabelEncoder.Attributes( - default_float=AttrFloat32(default_float, name="default_float"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), - keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), - keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), - values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), - values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), - values_strings=AttrStrings.maybe(values_strings, name="values_strings"), - ), _LabelEncoder.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def linear_classifier(X: Var, *, classlabels_ints: Optional[Iterable[int]] = None, classlabels_strings: Optional[Iterable[str]] = None, coefficients: Iterable[float], intercepts: Optional[Iterable[float]] = None, multi_class: int = 0, post_transform: str = "NONE", ) -> tuple[Var, Var]: + return ( + _Imputer( + _Imputer.Attributes( + imputed_value_floats=AttrFloat32s.maybe( + imputed_value_floats, name="imputed_value_floats" + ), + imputed_value_int64s=AttrInt64s.maybe( + imputed_value_int64s, name="imputed_value_int64s" + ), + replaced_value_float=AttrFloat32( + replaced_value_float, name="replaced_value_float" + ), + replaced_value_int64=AttrInt64( + replaced_value_int64, name="replaced_value_int64" + ), + ), + _Imputer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def label_encoder( + X: Var, + *, + default_float: float = -0.0, + default_int64: int = -1, + default_string: str = "_Unused", + keys_floats: Optional[Iterable[float]] = None, + keys_int64s: Optional[Iterable[int]] = None, + keys_strings: Optional[Iterable[str]] = None, + values_floats: Optional[Iterable[float]] = None, + values_int64s: Optional[Iterable[int]] = None, + values_strings: Optional[Iterable[str]] = None, +) -> Var: r""" -Linear classifier - -Parameters -========== -X - Type T1. - Data to be classified. -classlabels_ints - Attribute. - Class labels when using integer labels. One and only one 'classlabels' - attribute must be defined. -classlabels_strings - Attribute. - Class labels when using string labels. One and only one 'classlabels' - attribute must be defined. -coefficients - Attribute. - A collection of weights of the model(s). -intercepts - Attribute. - A collection of intercepts. -multi_class - Attribute. - Indicates whether to do OvR or multinomial (0=OvR is the default). -post_transform - Attribute. - Indicates the transform to apply to the scores vector.One of 'NONE,' - 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' - -Returns -======= -Y : Var - Type T2. - Classification outputs (one class per example). -Z : Var - Type tensor(float). - Classification scores ([N,E] - one score for each class and example - -Notes -===== -Signature: ``ai.onnx.ml@1::LinearClassifier``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - - T2: `tensor(int64)`, `tensor(string)` + Maps each element in the input tensor to another value. The mapping is + determined by the two parallel attributes, 'keys\_\ *' and 'values\_*' + attribute. The i-th value in the specified 'keys\_\ *' attribute would + be mapped to the i-th value in the specified 'values\_*' attribute. It + implies that input's element type and the element type of the specified + 'keys\_\ *' should be identical while the output type is identical to + the specified 'values\_*' attribute. If an input element can not be + found in the specified 'keys\_\ *' attribute, the 'default\_*' that + matches the specified 'values\_\ *' attribute may be used as its output + value. Let's consider an example which maps a string tensor to an + integer tensor. Assume and 'keys_strings' is ["Amy", "Sally"], + 'values_int64s' is [5, 6], and 'default_int64' is '-1'. The input + ["Dori", "Amy", "Amy", "Sally", "Sally"] would be mapped to [-1, 5, 5, + 6, 6]. Since this operator is an one-to-one mapping, its input and + output shapes are the same. Notice that only one of + 'keys\_*'/'values\_\ *' can be set. For key look-up, bit-wise comparison + is used so even a float NaN can be mapped to a value in 'values\_*' + attribute. + + Parameters + ========== + X + Type T1. + Input data. It can be either tensor or scalar. + default_float + Attribute. + A float. + default_int64 + Attribute. + An integer. + default_string + Attribute. + A string. + keys_floats + Attribute. + A list of floats. + keys_int64s + Attribute. + A list of ints. + keys_strings + Attribute. + A list of strings. One and only one of 'keys\_\*'s should be set. + values_floats + Attribute. + A list of floats. + values_int64s + Attribute. + A list of ints. + values_strings + Attribute. + A list of strings. One and only one of 'value\_\*'s should be set. + + Returns + ======= + Y : Var + Type T2. + Output data. + + Notes + ===== + Signature: ``ai.onnx.ml@2::LabelEncoder``. + + Type constraints: + - T1: `tensor(float)`, `tensor(int64)`, `tensor(string)` + - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - return _LinearClassifier( - _LinearClassifier.Attributes( - classlabels_ints=AttrInt64s.maybe(classlabels_ints, name="classlabels_ints"), - classlabels_strings=AttrStrings.maybe(classlabels_strings, name="classlabels_strings"), - coefficients=AttrFloat32s(coefficients, name="coefficients"), - intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), - multi_class=AttrInt64(multi_class, name="multi_class"), - post_transform=AttrString(post_transform, name="post_transform"), - ), _LinearClassifier.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), )._unpack_to_any() - - -def linear_regressor(X: Var, *, coefficients: Optional[Iterable[float]] = None, intercepts: Optional[Iterable[float]] = None, post_transform: str = "NONE", targets: int = 1, ) -> Var: + return ( + _LabelEncoder( + _LabelEncoder.Attributes( + default_float=AttrFloat32(default_float, name="default_float"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), + keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), + keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), + values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), + values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), + values_strings=AttrStrings.maybe(values_strings, name="values_strings"), + ), + _LabelEncoder.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def linear_classifier( + X: Var, + *, + classlabels_ints: Optional[Iterable[int]] = None, + classlabels_strings: Optional[Iterable[str]] = None, + coefficients: Iterable[float], + intercepts: Optional[Iterable[float]] = None, + multi_class: int = 0, + post_transform: str = "NONE", +) -> tuple[Var, Var]: r""" -Generalized linear regression evaluation. If targets is set to 1 -(default) then univariate regression is performed. If targets is set to -M then M sets of coefficients must be passed in as a sequence and M -results will be output for each input n in N. The coefficients array is -of length n, and the coefficients for each target are contiguous. -Intercepts are optional but if provided must match the number of -targets. - -Parameters -========== -X - Type T. - Data to be regressed. -coefficients - Attribute. - Weights of the model(s). -intercepts - Attribute. - Weights of the intercepts, if used. -post_transform - Attribute. - Indicates the transform to apply to the regression output vector.One of - 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' -targets - Attribute. - The total number of regression targets, 1 if not defined. - -Returns -======= -Y : Var - Type tensor(float). - Regression outputs (one per target, per example). - -Notes -===== -Signature: ``ai.onnx.ml@1::LinearRegressor``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + Linear classifier + + Parameters + ========== + X + Type T1. + Data to be classified. + classlabels_ints + Attribute. + Class labels when using integer labels. One and only one 'classlabels' + attribute must be defined. + classlabels_strings + Attribute. + Class labels when using string labels. One and only one 'classlabels' + attribute must be defined. + coefficients + Attribute. + A collection of weights of the model(s). + intercepts + Attribute. + A collection of intercepts. + multi_class + Attribute. + Indicates whether to do OvR or multinomial (0=OvR is the default). + post_transform + Attribute. + Indicates the transform to apply to the scores vector.One of 'NONE,' + 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' + + Returns + ======= + Y : Var + Type T2. + Classification outputs (one class per example). + Z : Var + Type tensor(float). + Classification scores ([N,E] - one score for each class and example + + Notes + ===== + Signature: ``ai.onnx.ml@1::LinearClassifier``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + - T2: `tensor(int64)`, `tensor(string)` """ - return _LinearRegressor( - _LinearRegressor.Attributes( - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), - post_transform=AttrString(post_transform, name="post_transform"), - targets=AttrInt64(targets, name="targets"), - ), _LinearRegressor.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def normalizer(X: Var, *, norm: str = "MAX", ) -> Var: + return ( + _LinearClassifier( + _LinearClassifier.Attributes( + classlabels_ints=AttrInt64s.maybe( + classlabels_ints, name="classlabels_ints" + ), + classlabels_strings=AttrStrings.maybe( + classlabels_strings, name="classlabels_strings" + ), + coefficients=AttrFloat32s(coefficients, name="coefficients"), + intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), + multi_class=AttrInt64(multi_class, name="multi_class"), + post_transform=AttrString(post_transform, name="post_transform"), + ), + _LinearClassifier.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) + + +def linear_regressor( + X: Var, + *, + coefficients: Optional[Iterable[float]] = None, + intercepts: Optional[Iterable[float]] = None, + post_transform: str = "NONE", + targets: int = 1, +) -> Var: r""" -Normalize the input. There are three normalization modes, which have the -corresponding formulas, defined using element-wise infix operators '/' -and '^' and tensor-wide functions 'max' and 'sum': Max: Y = X / max(X) -L1: Y = X / sum(X) L2: Y = sqrt(X^2 / sum(X^2)} In all modes, if the -divisor is zero, Y == X. For batches, that is, [N,C] tensors, -normalization is done along the C axis. In other words, each row of the -batch is normalized independently. - -Parameters -========== -X - Type T. - Data to be encoded, a tensor of shape [N,C] or [C] -norm - Attribute. - One of 'MAX,' 'L1,' 'L2' - -Returns -======= -Y : Var - Type tensor(float). - Encoded output data - -Notes -===== -Signature: ``ai.onnx.ml@1::Normalizer``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + Generalized linear regression evaluation. If targets is set to 1 + (default) then univariate regression is performed. If targets is set to + M then M sets of coefficients must be passed in as a sequence and M + results will be output for each input n in N. The coefficients array is + of length n, and the coefficients for each target are contiguous. + Intercepts are optional but if provided must match the number of + targets. + + Parameters + ========== + X + Type T. + Data to be regressed. + coefficients + Attribute. + Weights of the model(s). + intercepts + Attribute. + Weights of the intercepts, if used. + post_transform + Attribute. + Indicates the transform to apply to the regression output vector.One of + 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' + targets + Attribute. + The total number of regression targets, 1 if not defined. + + Returns + ======= + Y : Var + Type tensor(float). + Regression outputs (one per target, per example). + + Notes + ===== + Signature: ``ai.onnx.ml@1::LinearRegressor``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _Normalizer( - _Normalizer.Attributes( - norm=AttrString(norm, name="norm"), - ), _Normalizer.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _LinearRegressor( + _LinearRegressor.Attributes( + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + intercepts=AttrFloat32s.maybe(intercepts, name="intercepts"), + post_transform=AttrString(post_transform, name="post_transform"), + targets=AttrInt64(targets, name="targets"), + ), + _LinearRegressor.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def one_hot_encoder(X: Var, *, cats_int64s: Optional[Iterable[int]] = None, cats_strings: Optional[Iterable[str]] = None, zeros: int = 1, ) -> Var: +def normalizer( + X: Var, + *, + norm: str = "MAX", +) -> Var: r""" -Replace each input element with an array of ones and zeros, where a -single one is placed at the index of the category that was passed in. -The total category count will determine the size of the extra dimension -of the output array Y. For example, if we pass a tensor with a single -value of 4, and a category count of 8, the output will be a tensor with -``[0,0,0,0,1,0,0,0]``. This operator assumes every input feature is from -the same set of categories. If the input is a tensor of float, int32, or -double, the data will be cast to integers and the cats_int64s category -list will be used for the lookups. - -Parameters -========== -X - Type T. - Data to be encoded. -cats_int64s - Attribute. - List of categories, ints.One and only one of the 'cats\_\*' attributes - must be defined. -cats_strings - Attribute. - List of categories, strings.One and only one of the 'cats\_\*' - attributes must be defined. -zeros - Attribute. - If true and category is not present, will return all zeros; if false and - a category if not found, the operator will fail. - -Returns -======= -Y : Var - Type tensor(float). - Encoded output data, having one more dimension than X. - -Notes -===== -Signature: ``ai.onnx.ml@1::OneHotEncoder``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` + Normalize the input. There are three normalization modes, which have the + corresponding formulas, defined using element-wise infix operators '/' + and '^' and tensor-wide functions 'max' and 'sum': Max: Y = X / max(X) + L1: Y = X / sum(X) L2: Y = sqrt(X^2 / sum(X^2)} In all modes, if the + divisor is zero, Y == X. For batches, that is, [N,C] tensors, + normalization is done along the C axis. In other words, each row of the + batch is normalized independently. + + Parameters + ========== + X + Type T. + Data to be encoded, a tensor of shape [N,C] or [C] + norm + Attribute. + One of 'MAX,' 'L1,' 'L2' + + Returns + ======= + Y : Var + Type tensor(float). + Encoded output data + + Notes + ===== + Signature: ``ai.onnx.ml@1::Normalizer``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _OneHotEncoder( - _OneHotEncoder.Attributes( - cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), - cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), - zeros=AttrInt64(zeros, name="zeros"), - ), _OneHotEncoder.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _Normalizer( + _Normalizer.Attributes( + norm=AttrString(norm, name="norm"), + ), + _Normalizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def svmclassifier(X: Var, *, classlabels_ints: Optional[Iterable[int]] = None, classlabels_strings: Optional[Iterable[str]] = None, coefficients: Optional[Iterable[float]] = None, kernel_params: Optional[Iterable[float]] = None, kernel_type: str = "LINEAR", post_transform: str = "NONE", prob_a: Optional[Iterable[float]] = None, prob_b: Optional[Iterable[float]] = None, rho: Optional[Iterable[float]] = None, support_vectors: Optional[Iterable[float]] = None, vectors_per_class: Optional[Iterable[int]] = None, ) -> tuple[Var, Var]: +def one_hot_encoder( + X: Var, + *, + cats_int64s: Optional[Iterable[int]] = None, + cats_strings: Optional[Iterable[str]] = None, + zeros: int = 1, +) -> Var: r""" -Support Vector Machine classifier - -Parameters -========== -X - Type T1. - Data to be classified. -classlabels_ints - Attribute. - Class labels if using integer labels.One and only one of the - 'classlabels\_\*' attributes must be defined. -classlabels_strings - Attribute. - Class labels if using string labels.One and only one of the - 'classlabels\_\*' attributes must be defined. -coefficients - Attribute. - -kernel_params - Attribute. - List of 3 elements containing gamma, coef0, and degree, in that order. - Zero if unused for the kernel. -kernel_type - Attribute. - The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'. -post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' - 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' -prob_a - Attribute. - First set of probability coefficients. -prob_b - Attribute. - Second set of probability coefficients. This array must be same size as - prob_a.If these are provided then output Z are probability estimates, - otherwise they are raw scores. -rho - Attribute. - -support_vectors - Attribute. - -vectors_per_class - Attribute. - - -Returns -======= -Y : Var - Type T2. - Classification outputs (one class per example). -Z : Var - Type tensor(float). - Class scores (one per class per example), if prob_a and prob_b are - provided they are probabilities for each class, otherwise they are raw - scores. - -Notes -===== -Signature: ``ai.onnx.ml@1::SVMClassifier``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - - T2: `tensor(int64)`, `tensor(string)` + Replace each input element with an array of ones and zeros, where a + single one is placed at the index of the category that was passed in. + The total category count will determine the size of the extra dimension + of the output array Y. For example, if we pass a tensor with a single + value of 4, and a category count of 8, the output will be a tensor with + ``[0,0,0,0,1,0,0,0]``. This operator assumes every input feature is from + the same set of categories. If the input is a tensor of float, int32, or + double, the data will be cast to integers and the cats_int64s category + list will be used for the lookups. + + Parameters + ========== + X + Type T. + Data to be encoded. + cats_int64s + Attribute. + List of categories, ints.One and only one of the 'cats\_\*' attributes + must be defined. + cats_strings + Attribute. + List of categories, strings.One and only one of the 'cats\_\*' + attributes must be defined. + zeros + Attribute. + If true and category is not present, will return all zeros; if false and + a category if not found, the operator will fail. + + Returns + ======= + Y : Var + Type tensor(float). + Encoded output data, having one more dimension than X. + + Notes + ===== + Signature: ``ai.onnx.ml@1::OneHotEncoder``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - return _SVMClassifier( - _SVMClassifier.Attributes( - classlabels_ints=AttrInt64s.maybe(classlabels_ints, name="classlabels_ints"), - classlabels_strings=AttrStrings.maybe(classlabels_strings, name="classlabels_strings"), - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), - kernel_type=AttrString(kernel_type, name="kernel_type"), - post_transform=AttrString(post_transform, name="post_transform"), - prob_a=AttrFloat32s.maybe(prob_a, name="prob_a"), - prob_b=AttrFloat32s.maybe(prob_b, name="prob_b"), - rho=AttrFloat32s.maybe(rho, name="rho"), - support_vectors=AttrFloat32s.maybe(support_vectors, name="support_vectors"), - vectors_per_class=AttrInt64s.maybe(vectors_per_class, name="vectors_per_class"), - ), _SVMClassifier.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), )._unpack_to_any() - - -def svmregressor(X: Var, *, coefficients: Optional[Iterable[float]] = None, kernel_params: Optional[Iterable[float]] = None, kernel_type: str = "LINEAR", n_supports: int = 0, one_class: int = 0, post_transform: str = "NONE", rho: Optional[Iterable[float]] = None, support_vectors: Optional[Iterable[float]] = None, ) -> Var: + return ( + _OneHotEncoder( + _OneHotEncoder.Attributes( + cats_int64s=AttrInt64s.maybe(cats_int64s, name="cats_int64s"), + cats_strings=AttrStrings.maybe(cats_strings, name="cats_strings"), + zeros=AttrInt64(zeros, name="zeros"), + ), + _OneHotEncoder.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def svmclassifier( + X: Var, + *, + classlabels_ints: Optional[Iterable[int]] = None, + classlabels_strings: Optional[Iterable[str]] = None, + coefficients: Optional[Iterable[float]] = None, + kernel_params: Optional[Iterable[float]] = None, + kernel_type: str = "LINEAR", + post_transform: str = "NONE", + prob_a: Optional[Iterable[float]] = None, + prob_b: Optional[Iterable[float]] = None, + rho: Optional[Iterable[float]] = None, + support_vectors: Optional[Iterable[float]] = None, + vectors_per_class: Optional[Iterable[int]] = None, +) -> tuple[Var, Var]: r""" -Support Vector Machine regression prediction and one-class SVM anomaly -detection. - -Parameters -========== -X - Type T. - Data to be regressed. -coefficients - Attribute. - Support vector coefficients. -kernel_params - Attribute. - List of 3 elements containing gamma, coef0, and degree, in that order. - Zero if unused for the kernel. -kernel_type - Attribute. - The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'. -n_supports - Attribute. - The number of support vectors. -one_class - Attribute. - Flag indicating whether the regression is a one-class SVM or not. -post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' - 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.' -rho - Attribute. - -support_vectors - Attribute. - Chosen support vectors - -Returns -======= -Y : Var - Type tensor(float). - Regression outputs (one score per target per example). - -Notes -===== -Signature: ``ai.onnx.ml@1::SVMRegressor``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + Support Vector Machine classifier + + Parameters + ========== + X + Type T1. + Data to be classified. + classlabels_ints + Attribute. + Class labels if using integer labels.One and only one of the + 'classlabels\_\*' attributes must be defined. + classlabels_strings + Attribute. + Class labels if using string labels.One and only one of the + 'classlabels\_\*' attributes must be defined. + coefficients + Attribute. + + kernel_params + Attribute. + List of 3 elements containing gamma, coef0, and degree, in that order. + Zero if unused for the kernel. + kernel_type + Attribute. + The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'. + post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' + 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' + prob_a + Attribute. + First set of probability coefficients. + prob_b + Attribute. + Second set of probability coefficients. This array must be same size as + prob_a.If these are provided then output Z are probability estimates, + otherwise they are raw scores. + rho + Attribute. + + support_vectors + Attribute. + + vectors_per_class + Attribute. + + + Returns + ======= + Y : Var + Type T2. + Classification outputs (one class per example). + Z : Var + Type tensor(float). + Class scores (one per class per example), if prob_a and prob_b are + provided they are probabilities for each class, otherwise they are raw + scores. + + Notes + ===== + Signature: ``ai.onnx.ml@1::SVMClassifier``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + - T2: `tensor(int64)`, `tensor(string)` """ - return _SVMRegressor( - _SVMRegressor.Attributes( - coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), - kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), - kernel_type=AttrString(kernel_type, name="kernel_type"), - n_supports=AttrInt64(n_supports, name="n_supports"), - one_class=AttrInt64(one_class, name="one_class"), - post_transform=AttrString(post_transform, name="post_transform"), - rho=AttrFloat32s.maybe(rho, name="rho"), - support_vectors=AttrFloat32s.maybe(support_vectors, name="support_vectors"), - ), _SVMRegressor.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def scaler(X: Var, *, offset: Optional[Iterable[float]] = None, scale: Optional[Iterable[float]] = None, ) -> Var: + return ( + _SVMClassifier( + _SVMClassifier.Attributes( + classlabels_ints=AttrInt64s.maybe( + classlabels_ints, name="classlabels_ints" + ), + classlabels_strings=AttrStrings.maybe( + classlabels_strings, name="classlabels_strings" + ), + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), + kernel_type=AttrString(kernel_type, name="kernel_type"), + post_transform=AttrString(post_transform, name="post_transform"), + prob_a=AttrFloat32s.maybe(prob_a, name="prob_a"), + prob_b=AttrFloat32s.maybe(prob_b, name="prob_b"), + rho=AttrFloat32s.maybe(rho, name="rho"), + support_vectors=AttrFloat32s.maybe( + support_vectors, name="support_vectors" + ), + vectors_per_class=AttrInt64s.maybe( + vectors_per_class, name="vectors_per_class" + ), + ), + _SVMClassifier.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) + + +def svmregressor( + X: Var, + *, + coefficients: Optional[Iterable[float]] = None, + kernel_params: Optional[Iterable[float]] = None, + kernel_type: str = "LINEAR", + n_supports: int = 0, + one_class: int = 0, + post_transform: str = "NONE", + rho: Optional[Iterable[float]] = None, + support_vectors: Optional[Iterable[float]] = None, +) -> Var: r""" -Rescale input data, for example to standardize features by removing the -mean and scaling to unit variance. - -Parameters -========== -X - Type T. - Data to be scaled. -offset - Attribute. - First, offset by this.Can be length of features in an [N,F] tensor or - length 1, in which case it applies to all features, regardless of - dimension count. -scale - Attribute. - Second, multiply by this.Can be length of features in an [N,F] tensor or - length 1, in which case it applies to all features, regardless of - dimension count.Must be same length as 'offset' - -Returns -======= -Y : Var - Type tensor(float). - Scaled output data. - -Notes -===== -Signature: ``ai.onnx.ml@1::Scaler``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + Support Vector Machine regression prediction and one-class SVM anomaly + detection. + + Parameters + ========== + X + Type T. + Data to be regressed. + coefficients + Attribute. + Support vector coefficients. + kernel_params + Attribute. + List of 3 elements containing gamma, coef0, and degree, in that order. + Zero if unused for the kernel. + kernel_type + Attribute. + The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'. + n_supports + Attribute. + The number of support vectors. + one_class + Attribute. + Flag indicating whether the regression is a one-class SVM or not. + post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' + 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.' + rho + Attribute. + + support_vectors + Attribute. + Chosen support vectors + + Returns + ======= + Y : Var + Type tensor(float). + Regression outputs (one score per target per example). + + Notes + ===== + Signature: ``ai.onnx.ml@1::SVMRegressor``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _Scaler( - _Scaler.Attributes( - offset=AttrFloat32s.maybe(offset, name="offset"), - scale=AttrFloat32s.maybe(scale, name="scale"), - ), _Scaler.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _SVMRegressor( + _SVMRegressor.Attributes( + coefficients=AttrFloat32s.maybe(coefficients, name="coefficients"), + kernel_params=AttrFloat32s.maybe(kernel_params, name="kernel_params"), + kernel_type=AttrString(kernel_type, name="kernel_type"), + n_supports=AttrInt64(n_supports, name="n_supports"), + one_class=AttrInt64(one_class, name="one_class"), + post_transform=AttrString(post_transform, name="post_transform"), + rho=AttrFloat32s.maybe(rho, name="rho"), + support_vectors=AttrFloat32s.maybe( + support_vectors, name="support_vectors" + ), + ), + _SVMRegressor.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def tree_ensemble_classifier(X: Var, *, base_values: Optional[Iterable[float]] = None, base_values_as_tensor: Optional[np.ndarray] = None, class_ids: Optional[Iterable[int]] = None, class_nodeids: Optional[Iterable[int]] = None, class_treeids: Optional[Iterable[int]] = None, class_weights: Optional[Iterable[float]] = None, class_weights_as_tensor: Optional[np.ndarray] = None, classlabels_int64s: Optional[Iterable[int]] = None, classlabels_strings: Optional[Iterable[str]] = None, nodes_falsenodeids: Optional[Iterable[int]] = None, nodes_featureids: Optional[Iterable[int]] = None, nodes_hitrates: Optional[Iterable[float]] = None, nodes_hitrates_as_tensor: Optional[np.ndarray] = None, nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, nodes_modes: Optional[Iterable[str]] = None, nodes_nodeids: Optional[Iterable[int]] = None, nodes_treeids: Optional[Iterable[int]] = None, nodes_truenodeids: Optional[Iterable[int]] = None, nodes_values: Optional[Iterable[float]] = None, nodes_values_as_tensor: Optional[np.ndarray] = None, post_transform: str = "NONE", ) -> tuple[Var, Var]: +def scaler( + X: Var, + *, + offset: Optional[Iterable[float]] = None, + scale: Optional[Iterable[float]] = None, +) -> Var: r""" -Tree Ensemble classifier. Returns the top class for each of N inputs. -The attributes named 'nodes_X' form a sequence of tuples, associated by -index into the sequences, which must all be of equal length. These -tuples define the nodes. Similarly, all fields prefixed with 'class\_' -are tuples of votes at the leaves. A leaf may have multiple votes, where -each vote is weighted by the associated class_weights index. One and -only one of classlabels_strings or classlabels_int64s will be defined. -The class_ids are indices into this list. All fields ending with -\_as_tensor can be used instead of the same parameter without the suffix -if the element type is double and not float. - -Parameters -========== -X - Type T1. - Input of shape [N,F] -base_values - Attribute. - Base values for classification, added to final class score; the size - must be the same as the classes or can be left unassigned (assumed 0) -base_values_as_tensor - Attribute. - Base values for classification, added to final class score; the size - must be the same as the classes or can be left unassigned (assumed 0) -class_ids - Attribute. - The index of the class list that each weight is for. -class_nodeids - Attribute. - node id that this weight is for. -class_treeids - Attribute. - The id of the tree that this node is in. -class_weights - Attribute. - The weight for the class in class_id. -class_weights_as_tensor - Attribute. - The weight for the class in class_id. -classlabels_int64s - Attribute. - Class labels if using integer labels.One and only one of the - 'classlabels\_\*' attributes must be defined. -classlabels_strings - Attribute. - Class labels if using string labels.One and only one of the - 'classlabels\_\*' attributes must be defined. -nodes_falsenodeids - Attribute. - Child node if expression is false. -nodes_featureids - Attribute. - Feature id for each node. -nodes_hitrates - Attribute. - Popularity of each node, used for performance and may be omitted. -nodes_hitrates_as_tensor - Attribute. - Popularity of each node, used for performance and may be omitted. -nodes_missing_value_tracks_true - Attribute. - For each node, define what to do in the presence of a missing value: if - a value is missing (NaN), use the 'true' or 'false' branch based on the - value in this array.This attribute may be left undefined, and the - default value is false (0) for all nodes. -nodes_modes - Attribute. - The node kind, that is, the comparison to make at the node. There is no - comparison to make at a leaf node.One of 'BRANCH_LEQ', 'BRANCH_LT', - 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF' -nodes_nodeids - Attribute. - Node id for each node. Ids may restart at zero for each tree, but it not - required to. -nodes_treeids - Attribute. - Tree id for each node. -nodes_truenodeids - Attribute. - Child node if expression is true. -nodes_values - Attribute. - Thresholds to do the splitting on for each node. -nodes_values_as_tensor - Attribute. - Thresholds to do the splitting on for each node. -post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' - 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.' - -Returns -======= -Y : Var - Type T2. - N, Top class for each point -Z : Var - Type tensor(float). - The class score for each class, for each point, a tensor of shape [N,E]. - -Notes -===== -Signature: ``ai.onnx.ml@3::TreeEnsembleClassifier``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - - T2: `tensor(int64)`, `tensor(string)` + Rescale input data, for example to standardize features by removing the + mean and scaling to unit variance. + + Parameters + ========== + X + Type T. + Data to be scaled. + offset + Attribute. + First, offset by this.Can be length of features in an [N,F] tensor or + length 1, in which case it applies to all features, regardless of + dimension count. + scale + Attribute. + Second, multiply by this.Can be length of features in an [N,F] tensor or + length 1, in which case it applies to all features, regardless of + dimension count.Must be same length as 'offset' + + Returns + ======= + Y : Var + Type tensor(float). + Scaled output data. + + Notes + ===== + Signature: ``ai.onnx.ml@1::Scaler``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - return _TreeEnsembleClassifier( - _TreeEnsembleClassifier.Attributes( - base_values=AttrFloat32s.maybe(base_values, name="base_values"), - base_values_as_tensor=AttrTensor.maybe(base_values_as_tensor, name="base_values_as_tensor"), - class_ids=AttrInt64s.maybe(class_ids, name="class_ids"), - class_nodeids=AttrInt64s.maybe(class_nodeids, name="class_nodeids"), - class_treeids=AttrInt64s.maybe(class_treeids, name="class_treeids"), - class_weights=AttrFloat32s.maybe(class_weights, name="class_weights"), - class_weights_as_tensor=AttrTensor.maybe(class_weights_as_tensor, name="class_weights_as_tensor"), - classlabels_int64s=AttrInt64s.maybe(classlabels_int64s, name="classlabels_int64s"), - classlabels_strings=AttrStrings.maybe(classlabels_strings, name="classlabels_strings"), - nodes_falsenodeids=AttrInt64s.maybe(nodes_falsenodeids, name="nodes_falsenodeids"), - nodes_featureids=AttrInt64s.maybe(nodes_featureids, name="nodes_featureids"), - nodes_hitrates=AttrFloat32s.maybe(nodes_hitrates, name="nodes_hitrates"), - nodes_hitrates_as_tensor=AttrTensor.maybe(nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor"), - nodes_missing_value_tracks_true=AttrInt64s.maybe(nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true"), - nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), - nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), - nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), - nodes_truenodeids=AttrInt64s.maybe(nodes_truenodeids, name="nodes_truenodeids"), - nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), - nodes_values_as_tensor=AttrTensor.maybe(nodes_values_as_tensor, name="nodes_values_as_tensor"), - post_transform=AttrString(post_transform, name="post_transform"), - ), _TreeEnsembleClassifier.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), )._unpack_to_any() - - -def tree_ensemble_regressor(X: Var, *, aggregate_function: str = "SUM", base_values: Optional[Iterable[float]] = None, base_values_as_tensor: Optional[np.ndarray] = None, n_targets: Optional[int] = None, nodes_falsenodeids: Optional[Iterable[int]] = None, nodes_featureids: Optional[Iterable[int]] = None, nodes_hitrates: Optional[Iterable[float]] = None, nodes_hitrates_as_tensor: Optional[np.ndarray] = None, nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, nodes_modes: Optional[Iterable[str]] = None, nodes_nodeids: Optional[Iterable[int]] = None, nodes_treeids: Optional[Iterable[int]] = None, nodes_truenodeids: Optional[Iterable[int]] = None, nodes_values: Optional[Iterable[float]] = None, nodes_values_as_tensor: Optional[np.ndarray] = None, post_transform: str = "NONE", target_ids: Optional[Iterable[int]] = None, target_nodeids: Optional[Iterable[int]] = None, target_treeids: Optional[Iterable[int]] = None, target_weights: Optional[Iterable[float]] = None, target_weights_as_tensor: Optional[np.ndarray] = None, ) -> Var: + return ( + _Scaler( + _Scaler.Attributes( + offset=AttrFloat32s.maybe(offset, name="offset"), + scale=AttrFloat32s.maybe(scale, name="scale"), + ), + _Scaler.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def tree_ensemble_classifier( + X: Var, + *, + base_values: Optional[Iterable[float]] = None, + base_values_as_tensor: Optional[np.ndarray] = None, + class_ids: Optional[Iterable[int]] = None, + class_nodeids: Optional[Iterable[int]] = None, + class_treeids: Optional[Iterable[int]] = None, + class_weights: Optional[Iterable[float]] = None, + class_weights_as_tensor: Optional[np.ndarray] = None, + classlabels_int64s: Optional[Iterable[int]] = None, + classlabels_strings: Optional[Iterable[str]] = None, + nodes_falsenodeids: Optional[Iterable[int]] = None, + nodes_featureids: Optional[Iterable[int]] = None, + nodes_hitrates: Optional[Iterable[float]] = None, + nodes_hitrates_as_tensor: Optional[np.ndarray] = None, + nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, + nodes_modes: Optional[Iterable[str]] = None, + nodes_nodeids: Optional[Iterable[int]] = None, + nodes_treeids: Optional[Iterable[int]] = None, + nodes_truenodeids: Optional[Iterable[int]] = None, + nodes_values: Optional[Iterable[float]] = None, + nodes_values_as_tensor: Optional[np.ndarray] = None, + post_transform: str = "NONE", +) -> tuple[Var, Var]: r""" -Tree Ensemble regressor. Returns the regressed values for each input in -N. All args with nodes\_ are fields of a tuple of tree nodes, and it is -assumed they are the same length, and an index i will decode the tuple -across these inputs. Each node id can appear only once for each tree id. -All fields prefixed with target\_ are tuples of votes at the leaves. A -leaf may have multiple votes, where each vote is weighted by the -associated target_weights index. All fields ending with \_as_tensor can -be used instead of the same parameter without the suffix if the element -type is double and not float. All trees must have their node ids start -at 0 and increment by 1. Mode enum is BRANCH_LEQ, BRANCH_LT, BRANCH_GTE, -BRANCH_GT, BRANCH_EQ, BRANCH_NEQ, LEAF - -Parameters -========== -X - Type T. - Input of shape [N,F] -aggregate_function - Attribute. - Defines how to aggregate leaf values within a target. One of 'AVERAGE,' - 'SUM,' 'MIN,' 'MAX.' -base_values - Attribute. - Base values for regression, added to final prediction after applying - aggregate_function; the size must be the same as the classes or can be - left unassigned (assumed 0) -base_values_as_tensor - Attribute. - Base values for regression, added to final prediction after applying - aggregate_function; the size must be the same as the classes or can be - left unassigned (assumed 0) -n_targets - Attribute. - The total number of targets. -nodes_falsenodeids - Attribute. - Child node if expression is false -nodes_featureids - Attribute. - Feature id for each node. -nodes_hitrates - Attribute. - Popularity of each node, used for performance and may be omitted. -nodes_hitrates_as_tensor - Attribute. - Popularity of each node, used for performance and may be omitted. -nodes_missing_value_tracks_true - Attribute. - For each node, define what to do in the presence of a NaN: use the - 'true' (if the attribute value is 1) or 'false' (if the attribute value - is 0) branch based on the value in this array.This attribute may be left - undefined and the default value is false (0) for all nodes. -nodes_modes - Attribute. - The node kind, that is, the comparison to make at the node. There is no - comparison to make at a leaf node.One of 'BRANCH_LEQ', 'BRANCH_LT', - 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF' -nodes_nodeids - Attribute. - Node id for each node. Node ids must restart at zero for each tree and - increase sequentially. -nodes_treeids - Attribute. - Tree id for each node. -nodes_truenodeids - Attribute. - Child node if expression is true -nodes_values - Attribute. - Thresholds to do the splitting on for each node. -nodes_values_as_tensor - Attribute. - Thresholds to do the splitting on for each node. -post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' - 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' -target_ids - Attribute. - The index of the target that each weight is for -target_nodeids - Attribute. - The node id of each weight -target_treeids - Attribute. - The id of the tree that each node is in. -target_weights - Attribute. - The weight for each target -target_weights_as_tensor - Attribute. - The weight for each target - -Returns -======= -Y : Var - Type tensor(float). - N classes - -Notes -===== -Signature: ``ai.onnx.ml@3::TreeEnsembleRegressor``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + Tree Ensemble classifier. Returns the top class for each of N inputs. + The attributes named 'nodes_X' form a sequence of tuples, associated by + index into the sequences, which must all be of equal length. These + tuples define the nodes. Similarly, all fields prefixed with 'class\_' + are tuples of votes at the leaves. A leaf may have multiple votes, where + each vote is weighted by the associated class_weights index. One and + only one of classlabels_strings or classlabels_int64s will be defined. + The class_ids are indices into this list. All fields ending with + \_as_tensor can be used instead of the same parameter without the suffix + if the element type is double and not float. + + Parameters + ========== + X + Type T1. + Input of shape [N,F] + base_values + Attribute. + Base values for classification, added to final class score; the size + must be the same as the classes or can be left unassigned (assumed 0) + base_values_as_tensor + Attribute. + Base values for classification, added to final class score; the size + must be the same as the classes or can be left unassigned (assumed 0) + class_ids + Attribute. + The index of the class list that each weight is for. + class_nodeids + Attribute. + node id that this weight is for. + class_treeids + Attribute. + The id of the tree that this node is in. + class_weights + Attribute. + The weight for the class in class_id. + class_weights_as_tensor + Attribute. + The weight for the class in class_id. + classlabels_int64s + Attribute. + Class labels if using integer labels.One and only one of the + 'classlabels\_\*' attributes must be defined. + classlabels_strings + Attribute. + Class labels if using string labels.One and only one of the + 'classlabels\_\*' attributes must be defined. + nodes_falsenodeids + Attribute. + Child node if expression is false. + nodes_featureids + Attribute. + Feature id for each node. + nodes_hitrates + Attribute. + Popularity of each node, used for performance and may be omitted. + nodes_hitrates_as_tensor + Attribute. + Popularity of each node, used for performance and may be omitted. + nodes_missing_value_tracks_true + Attribute. + For each node, define what to do in the presence of a missing value: if + a value is missing (NaN), use the 'true' or 'false' branch based on the + value in this array.This attribute may be left undefined, and the + default value is false (0) for all nodes. + nodes_modes + Attribute. + The node kind, that is, the comparison to make at the node. There is no + comparison to make at a leaf node.One of 'BRANCH_LEQ', 'BRANCH_LT', + 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF' + nodes_nodeids + Attribute. + Node id for each node. Ids may restart at zero for each tree, but it not + required to. + nodes_treeids + Attribute. + Tree id for each node. + nodes_truenodeids + Attribute. + Child node if expression is true. + nodes_values + Attribute. + Thresholds to do the splitting on for each node. + nodes_values_as_tensor + Attribute. + Thresholds to do the splitting on for each node. + post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' + 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.' + + Returns + ======= + Y : Var + Type T2. + N, Top class for each point + Z : Var + Type tensor(float). + The class score for each class, for each point, a tensor of shape [N,E]. + + Notes + ===== + Signature: ``ai.onnx.ml@3::TreeEnsembleClassifier``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + - T2: `tensor(int64)`, `tensor(string)` """ - return _TreeEnsembleRegressor( - _TreeEnsembleRegressor.Attributes( - aggregate_function=AttrString(aggregate_function, name="aggregate_function"), - base_values=AttrFloat32s.maybe(base_values, name="base_values"), - base_values_as_tensor=AttrTensor.maybe(base_values_as_tensor, name="base_values_as_tensor"), - n_targets=AttrInt64.maybe(n_targets, name="n_targets"), - nodes_falsenodeids=AttrInt64s.maybe(nodes_falsenodeids, name="nodes_falsenodeids"), - nodes_featureids=AttrInt64s.maybe(nodes_featureids, name="nodes_featureids"), - nodes_hitrates=AttrFloat32s.maybe(nodes_hitrates, name="nodes_hitrates"), - nodes_hitrates_as_tensor=AttrTensor.maybe(nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor"), - nodes_missing_value_tracks_true=AttrInt64s.maybe(nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true"), - nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), - nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), - nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), - nodes_truenodeids=AttrInt64s.maybe(nodes_truenodeids, name="nodes_truenodeids"), - nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), - nodes_values_as_tensor=AttrTensor.maybe(nodes_values_as_tensor, name="nodes_values_as_tensor"), - post_transform=AttrString(post_transform, name="post_transform"), - target_ids=AttrInt64s.maybe(target_ids, name="target_ids"), - target_nodeids=AttrInt64s.maybe(target_nodeids, name="target_nodeids"), - target_treeids=AttrInt64s.maybe(target_treeids, name="target_treeids"), - target_weights=AttrFloat32s.maybe(target_weights, name="target_weights"), - target_weights_as_tensor=AttrTensor.maybe(target_weights_as_tensor, name="target_weights_as_tensor"), - ), _TreeEnsembleRegressor.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def zip_map(X: Var, *, classlabels_int64s: Optional[Iterable[int]] = None, classlabels_strings: Optional[Iterable[str]] = None, ) -> Var: + return ( + _TreeEnsembleClassifier( + _TreeEnsembleClassifier.Attributes( + base_values=AttrFloat32s.maybe(base_values, name="base_values"), + base_values_as_tensor=AttrTensor.maybe( + base_values_as_tensor, name="base_values_as_tensor" + ), + class_ids=AttrInt64s.maybe(class_ids, name="class_ids"), + class_nodeids=AttrInt64s.maybe(class_nodeids, name="class_nodeids"), + class_treeids=AttrInt64s.maybe(class_treeids, name="class_treeids"), + class_weights=AttrFloat32s.maybe(class_weights, name="class_weights"), + class_weights_as_tensor=AttrTensor.maybe( + class_weights_as_tensor, name="class_weights_as_tensor" + ), + classlabels_int64s=AttrInt64s.maybe( + classlabels_int64s, name="classlabels_int64s" + ), + classlabels_strings=AttrStrings.maybe( + classlabels_strings, name="classlabels_strings" + ), + nodes_falsenodeids=AttrInt64s.maybe( + nodes_falsenodeids, name="nodes_falsenodeids" + ), + nodes_featureids=AttrInt64s.maybe( + nodes_featureids, name="nodes_featureids" + ), + nodes_hitrates=AttrFloat32s.maybe( + nodes_hitrates, name="nodes_hitrates" + ), + nodes_hitrates_as_tensor=AttrTensor.maybe( + nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor" + ), + nodes_missing_value_tracks_true=AttrInt64s.maybe( + nodes_missing_value_tracks_true, + name="nodes_missing_value_tracks_true", + ), + nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), + nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), + nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), + nodes_truenodeids=AttrInt64s.maybe( + nodes_truenodeids, name="nodes_truenodeids" + ), + nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), + nodes_values_as_tensor=AttrTensor.maybe( + nodes_values_as_tensor, name="nodes_values_as_tensor" + ), + post_transform=AttrString(post_transform, name="post_transform"), + ), + _TreeEnsembleClassifier.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) + + +def tree_ensemble_regressor( + X: Var, + *, + aggregate_function: str = "SUM", + base_values: Optional[Iterable[float]] = None, + base_values_as_tensor: Optional[np.ndarray] = None, + n_targets: Optional[int] = None, + nodes_falsenodeids: Optional[Iterable[int]] = None, + nodes_featureids: Optional[Iterable[int]] = None, + nodes_hitrates: Optional[Iterable[float]] = None, + nodes_hitrates_as_tensor: Optional[np.ndarray] = None, + nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, + nodes_modes: Optional[Iterable[str]] = None, + nodes_nodeids: Optional[Iterable[int]] = None, + nodes_treeids: Optional[Iterable[int]] = None, + nodes_truenodeids: Optional[Iterable[int]] = None, + nodes_values: Optional[Iterable[float]] = None, + nodes_values_as_tensor: Optional[np.ndarray] = None, + post_transform: str = "NONE", + target_ids: Optional[Iterable[int]] = None, + target_nodeids: Optional[Iterable[int]] = None, + target_treeids: Optional[Iterable[int]] = None, + target_weights: Optional[Iterable[float]] = None, + target_weights_as_tensor: Optional[np.ndarray] = None, +) -> Var: + r""" + Tree Ensemble regressor. Returns the regressed values for each input in + N. All args with nodes\_ are fields of a tuple of tree nodes, and it is + assumed they are the same length, and an index i will decode the tuple + across these inputs. Each node id can appear only once for each tree id. + All fields prefixed with target\_ are tuples of votes at the leaves. A + leaf may have multiple votes, where each vote is weighted by the + associated target_weights index. All fields ending with \_as_tensor can + be used instead of the same parameter without the suffix if the element + type is double and not float. All trees must have their node ids start + at 0 and increment by 1. Mode enum is BRANCH_LEQ, BRANCH_LT, BRANCH_GTE, + BRANCH_GT, BRANCH_EQ, BRANCH_NEQ, LEAF + + Parameters + ========== + X + Type T. + Input of shape [N,F] + aggregate_function + Attribute. + Defines how to aggregate leaf values within a target. One of 'AVERAGE,' + 'SUM,' 'MIN,' 'MAX.' + base_values + Attribute. + Base values for regression, added to final prediction after applying + aggregate_function; the size must be the same as the classes or can be + left unassigned (assumed 0) + base_values_as_tensor + Attribute. + Base values for regression, added to final prediction after applying + aggregate_function; the size must be the same as the classes or can be + left unassigned (assumed 0) + n_targets + Attribute. + The total number of targets. + nodes_falsenodeids + Attribute. + Child node if expression is false + nodes_featureids + Attribute. + Feature id for each node. + nodes_hitrates + Attribute. + Popularity of each node, used for performance and may be omitted. + nodes_hitrates_as_tensor + Attribute. + Popularity of each node, used for performance and may be omitted. + nodes_missing_value_tracks_true + Attribute. + For each node, define what to do in the presence of a NaN: use the + 'true' (if the attribute value is 1) or 'false' (if the attribute value + is 0) branch based on the value in this array.This attribute may be left + undefined and the default value is false (0) for all nodes. + nodes_modes + Attribute. + The node kind, that is, the comparison to make at the node. There is no + comparison to make at a leaf node.One of 'BRANCH_LEQ', 'BRANCH_LT', + 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF' + nodes_nodeids + Attribute. + Node id for each node. Node ids must restart at zero for each tree and + increase sequentially. + nodes_treeids + Attribute. + Tree id for each node. + nodes_truenodeids + Attribute. + Child node if expression is true + nodes_values + Attribute. + Thresholds to do the splitting on for each node. + nodes_values_as_tensor + Attribute. + Thresholds to do the splitting on for each node. + post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE,' 'SOFTMAX,' + 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT' + target_ids + Attribute. + The index of the target that each weight is for + target_nodeids + Attribute. + The node id of each weight + target_treeids + Attribute. + The id of the tree that each node is in. + target_weights + Attribute. + The weight for each target + target_weights_as_tensor + Attribute. + The weight for each target + + Returns + ======= + Y : Var + Type tensor(float). + N classes + + Notes + ===== + Signature: ``ai.onnx.ml@3::TreeEnsembleRegressor``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` + """ + return ( + _TreeEnsembleRegressor( + _TreeEnsembleRegressor.Attributes( + aggregate_function=AttrString( + aggregate_function, name="aggregate_function" + ), + base_values=AttrFloat32s.maybe(base_values, name="base_values"), + base_values_as_tensor=AttrTensor.maybe( + base_values_as_tensor, name="base_values_as_tensor" + ), + n_targets=AttrInt64.maybe(n_targets, name="n_targets"), + nodes_falsenodeids=AttrInt64s.maybe( + nodes_falsenodeids, name="nodes_falsenodeids" + ), + nodes_featureids=AttrInt64s.maybe( + nodes_featureids, name="nodes_featureids" + ), + nodes_hitrates=AttrFloat32s.maybe( + nodes_hitrates, name="nodes_hitrates" + ), + nodes_hitrates_as_tensor=AttrTensor.maybe( + nodes_hitrates_as_tensor, name="nodes_hitrates_as_tensor" + ), + nodes_missing_value_tracks_true=AttrInt64s.maybe( + nodes_missing_value_tracks_true, + name="nodes_missing_value_tracks_true", + ), + nodes_modes=AttrStrings.maybe(nodes_modes, name="nodes_modes"), + nodes_nodeids=AttrInt64s.maybe(nodes_nodeids, name="nodes_nodeids"), + nodes_treeids=AttrInt64s.maybe(nodes_treeids, name="nodes_treeids"), + nodes_truenodeids=AttrInt64s.maybe( + nodes_truenodeids, name="nodes_truenodeids" + ), + nodes_values=AttrFloat32s.maybe(nodes_values, name="nodes_values"), + nodes_values_as_tensor=AttrTensor.maybe( + nodes_values_as_tensor, name="nodes_values_as_tensor" + ), + post_transform=AttrString(post_transform, name="post_transform"), + target_ids=AttrInt64s.maybe(target_ids, name="target_ids"), + target_nodeids=AttrInt64s.maybe(target_nodeids, name="target_nodeids"), + target_treeids=AttrInt64s.maybe(target_treeids, name="target_treeids"), + target_weights=AttrFloat32s.maybe( + target_weights, name="target_weights" + ), + target_weights_as_tensor=AttrTensor.maybe( + target_weights_as_tensor, name="target_weights_as_tensor" + ), + ), + _TreeEnsembleRegressor.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def zip_map( + X: Var, + *, + classlabels_int64s: Optional[Iterable[int]] = None, + classlabels_strings: Optional[Iterable[str]] = None, +) -> Var: r""" -Creates a map from the input and the attributes. The values are provided -by the input tensor, while the keys are specified by the attributes. -Must provide keys in either classlabels_strings or classlabels_int64s -(but not both). The columns of the tensor correspond one-by-one to the -keys specified by the attributes. There must be as many columns as keys. - -Parameters -========== -X - Type tensor(float). - The input values -classlabels_int64s - Attribute. - The keys when using int keys.One and only one of the 'classlabels\_\*' - attributes must be defined. -classlabels_strings - Attribute. - The keys when using string keys.One and only one of the - 'classlabels\_\*' attributes must be defined. - -Returns -======= -Z : Var - Type T. - The output map - -Notes -===== -Signature: ``ai.onnx.ml@1::ZipMap``. - -Type constraints: - - T: `seq(map(int64,tensor(float)))`, `seq(map(string,tensor(float)))` + Creates a map from the input and the attributes. The values are provided + by the input tensor, while the keys are specified by the attributes. + Must provide keys in either classlabels_strings or classlabels_int64s + (but not both). The columns of the tensor correspond one-by-one to the + keys specified by the attributes. There must be as many columns as keys. + + Parameters + ========== + X + Type tensor(float). + The input values + classlabels_int64s + Attribute. + The keys when using int keys.One and only one of the 'classlabels\_\*' + attributes must be defined. + classlabels_strings + Attribute. + The keys when using string keys.One and only one of the + 'classlabels\_\*' attributes must be defined. + + Returns + ======= + Z : Var + Type T. + The output map + + Notes + ===== + Signature: ``ai.onnx.ml@1::ZipMap``. + + Type constraints: + - T: `seq(map(int64,tensor(float)))`, `seq(map(string,tensor(float)))` """ - return _ZipMap( - _ZipMap.Attributes( - classlabels_int64s=AttrInt64s.maybe(classlabels_int64s, name="classlabels_int64s"), - classlabels_strings=AttrStrings.maybe(classlabels_strings, name="classlabels_strings"), - ), _ZipMap.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Z + return ( + _ZipMap( + _ZipMap.Attributes( + classlabels_int64s=AttrInt64s.maybe( + classlabels_int64s, name="classlabels_int64s" + ), + classlabels_strings=AttrStrings.maybe( + classlabels_strings, name="classlabels_strings" + ), + ), + _ZipMap.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Z + ) _OPERATORS = { @@ -1775,4 +2187,4 @@ def zip_map(X: Var, *, classlabels_int64s: Optional[Iterable[int]] = None, "ZipMap": zip_map, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index 998b6afc..2e4871c8 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -1,58 +1,66 @@ +# Copyright (c) QuantCo 2023-2024 +# SPDX-License-Identifier: BSD-3-Clause + # ruff: noqa: E741 -- Allow ambiguous variable name -import typing -import warnings +from collections.abc import Iterable from dataclasses import dataclass -from collections.abc import Iterable, Sequence from typing import ( - Any, - Callable, Optional, - Union, ) -from typing import cast as typing_cast import numpy as np -import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( - AttrDtype, AttrFloat32, AttrFloat32s, - AttrGraph, AttrInt64, AttrInt64s, AttrString, AttrStrings, AttrTensor, - AttrType, ) -from spox._graph import Graph, subgraph -from spox._internal_op import intro +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType -from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence -from spox._value_prop import PropValueType - - -from spox.opset.ai.onnx.ml.v3 import _ArrayFeatureExtractor, array_feature_extractor -from spox.opset.ai.onnx.ml.v3 import _Binarizer, binarizer -from spox.opset.ai.onnx.ml.v3 import _CastMap, cast_map -from spox.opset.ai.onnx.ml.v3 import _CategoryMapper, category_mapper -from spox.opset.ai.onnx.ml.v3 import _DictVectorizer, dict_vectorizer -from spox.opset.ai.onnx.ml.v3 import _FeatureVectorizer, feature_vectorizer -from spox.opset.ai.onnx.ml.v3 import _Imputer, imputer -from spox.opset.ai.onnx.ml.v3 import _LinearClassifier, linear_classifier -from spox.opset.ai.onnx.ml.v3 import _LinearRegressor, linear_regressor -from spox.opset.ai.onnx.ml.v3 import _Normalizer, normalizer -from spox.opset.ai.onnx.ml.v3 import _OneHotEncoder, one_hot_encoder -from spox.opset.ai.onnx.ml.v3 import _SVMClassifier, svmclassifier -from spox.opset.ai.onnx.ml.v3 import _SVMRegressor, svmregressor -from spox.opset.ai.onnx.ml.v3 import _Scaler, scaler -from spox.opset.ai.onnx.ml.v3 import _TreeEnsembleClassifier, tree_ensemble_classifier -from spox.opset.ai.onnx.ml.v3 import _TreeEnsembleRegressor, tree_ensemble_regressor -from spox.opset.ai.onnx.ml.v3 import _ZipMap, zip_map +from spox._standard import StandardNode +from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox.opset.ai.onnx.ml.v3 import ( + _ArrayFeatureExtractor, + _Binarizer, + _CastMap, + _CategoryMapper, + _DictVectorizer, + _FeatureVectorizer, + _Imputer, + _LinearClassifier, + _LinearRegressor, + _Normalizer, + _OneHotEncoder, + _Scaler, + _SVMClassifier, + _SVMRegressor, + _TreeEnsembleClassifier, + _TreeEnsembleRegressor, + _ZipMap, + array_feature_extractor, + binarizer, + cast_map, + category_mapper, + dict_vectorizer, + feature_vectorizer, + imputer, + linear_classifier, + linear_regressor, + normalizer, + one_hot_encoder, + scaler, + svmclassifier, + svmregressor, + tree_ensemble_classifier, + tree_ensemble_regressor, + zip_map, +) + + class _LabelEncoder(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -83,107 +91,131 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs -def label_encoder(X: Var, *, default_float: float = -0.0, default_int64: int = -1, default_string: str = "_Unused", default_tensor: Optional[np.ndarray] = None, keys_floats: Optional[Iterable[float]] = None, keys_int64s: Optional[Iterable[int]] = None, keys_strings: Optional[Iterable[str]] = None, keys_tensor: Optional[np.ndarray] = None, values_floats: Optional[Iterable[float]] = None, values_int64s: Optional[Iterable[int]] = None, values_strings: Optional[Iterable[str]] = None, values_tensor: Optional[np.ndarray] = None, ) -> Var: + +def label_encoder( + X: Var, + *, + default_float: float = -0.0, + default_int64: int = -1, + default_string: str = "_Unused", + default_tensor: Optional[np.ndarray] = None, + keys_floats: Optional[Iterable[float]] = None, + keys_int64s: Optional[Iterable[int]] = None, + keys_strings: Optional[Iterable[str]] = None, + keys_tensor: Optional[np.ndarray] = None, + values_floats: Optional[Iterable[float]] = None, + values_int64s: Optional[Iterable[int]] = None, + values_strings: Optional[Iterable[str]] = None, + values_tensor: Optional[np.ndarray] = None, +) -> Var: r""" -Maps each element in the input tensor to another value. The mapping is -determined by the two parallel attributes, 'keys\_\ *' and 'values\_*' -attribute. The i-th value in the specified 'keys\_\ *' attribute would -be mapped to the i-th value in the specified 'values\_*' attribute. It -implies that input's element type and the element type of the specified -'keys\_\ *' should be identical while the output type is identical to -the specified 'values\_*' attribute. Note that the 'keys\_\ *' and -'values\_*' attributes must have the same length. If an input element -can not be found in the specified 'keys\_\ *' attribute, the -'default\_*' that matches the specified 'values\_\ *' attribute may be -used as its output value. The type of the 'default\_*' attribute must -match the 'values\_\ *' attribute chosen. Let's consider an example -which maps a string tensor to an integer tensor. Assume and -'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6], and -'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally", -"Sally"] would be mapped to [-1, 5, 5, 6, 6]. Since this operator is an -one-to-one mapping, its input and output shapes are the same. Notice -that only one of 'keys\_*'/'values\_\*' can be set. Float keys with -value 'NaN' match any input 'NaN' value regardless of bit value. If a -key is repeated, the last key takes precedence. - -Parameters -========== -X - Type T1. - Input data. It must have the same element type as the keys\_\* attribute - set. -default_float - Attribute. - A float. -default_int64 - Attribute. - An integer. -default_string - Attribute. - A string. -default_tensor - Attribute. - A default tensor. {"*Unused"} if values*\ \* has string type, {-1} if - values\_\* has integral type, and {-0.f} if values\_\* has float type. -keys_floats - Attribute. - A list of floats. -keys_int64s - Attribute. - A list of ints. -keys_strings - Attribute. - A list of strings. -keys_tensor - Attribute. - Keys encoded as a 1D tensor. One and only one of 'keys\_\*'s should be - set. -values_floats - Attribute. - A list of floats. -values_int64s - Attribute. - A list of ints. -values_strings - Attribute. - A list of strings. -values_tensor - Attribute. - Values encoded as a 1D tensor. One and only one of 'values\_\*'s should - be set. - -Returns -======= -Y : Var - Type T2. - Output data. This tensor's element type is based on the values\_\* - attribute set. - -Notes -===== -Signature: ``ai.onnx.ml@4::LabelEncoder``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` + Maps each element in the input tensor to another value. The mapping is + determined by the two parallel attributes, 'keys\_\ *' and 'values\_*' + attribute. The i-th value in the specified 'keys\_\ *' attribute would + be mapped to the i-th value in the specified 'values\_*' attribute. It + implies that input's element type and the element type of the specified + 'keys\_\ *' should be identical while the output type is identical to + the specified 'values\_*' attribute. Note that the 'keys\_\ *' and + 'values\_*' attributes must have the same length. If an input element + can not be found in the specified 'keys\_\ *' attribute, the + 'default\_*' that matches the specified 'values\_\ *' attribute may be + used as its output value. The type of the 'default\_*' attribute must + match the 'values\_\ *' attribute chosen. Let's consider an example + which maps a string tensor to an integer tensor. Assume and + 'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6], and + 'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally", + "Sally"] would be mapped to [-1, 5, 5, 6, 6]. Since this operator is an + one-to-one mapping, its input and output shapes are the same. Notice + that only one of 'keys\_*'/'values\_\*' can be set. Float keys with + value 'NaN' match any input 'NaN' value regardless of bit value. If a + key is repeated, the last key takes precedence. + + Parameters + ========== + X + Type T1. + Input data. It must have the same element type as the keys\_\* attribute + set. + default_float + Attribute. + A float. + default_int64 + Attribute. + An integer. + default_string + Attribute. + A string. + default_tensor + Attribute. + A default tensor. {"*Unused"} if values*\ \* has string type, {-1} if + values\_\* has integral type, and {-0.f} if values\_\* has float type. + keys_floats + Attribute. + A list of floats. + keys_int64s + Attribute. + A list of ints. + keys_strings + Attribute. + A list of strings. + keys_tensor + Attribute. + Keys encoded as a 1D tensor. One and only one of 'keys\_\*'s should be + set. + values_floats + Attribute. + A list of floats. + values_int64s + Attribute. + A list of ints. + values_strings + Attribute. + A list of strings. + values_tensor + Attribute. + Values encoded as a 1D tensor. One and only one of 'values\_\*'s should + be set. + + Returns + ======= + Y : Var + Type T2. + Output data. This tensor's element type is based on the values\_\* + attribute set. + + Notes + ===== + Signature: ``ai.onnx.ml@4::LabelEncoder``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - return _LabelEncoder( - _LabelEncoder.Attributes( - default_float=AttrFloat32(default_float, name="default_float"), - default_int64=AttrInt64(default_int64, name="default_int64"), - default_string=AttrString(default_string, name="default_string"), - default_tensor=AttrTensor.maybe(default_tensor, name="default_tensor"), - keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), - keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), - keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), - keys_tensor=AttrTensor.maybe(keys_tensor, name="keys_tensor"), - values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), - values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), - values_strings=AttrStrings.maybe(values_strings, name="values_strings"), - values_tensor=AttrTensor.maybe(values_tensor, name="values_tensor"), - ), _LabelEncoder.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _LabelEncoder( + _LabelEncoder.Attributes( + default_float=AttrFloat32(default_float, name="default_float"), + default_int64=AttrInt64(default_int64, name="default_int64"), + default_string=AttrString(default_string, name="default_string"), + default_tensor=AttrTensor.maybe(default_tensor, name="default_tensor"), + keys_floats=AttrFloat32s.maybe(keys_floats, name="keys_floats"), + keys_int64s=AttrInt64s.maybe(keys_int64s, name="keys_int64s"), + keys_strings=AttrStrings.maybe(keys_strings, name="keys_strings"), + keys_tensor=AttrTensor.maybe(keys_tensor, name="keys_tensor"), + values_floats=AttrFloat32s.maybe(values_floats, name="values_floats"), + values_int64s=AttrInt64s.maybe(values_int64s, name="values_int64s"), + values_strings=AttrStrings.maybe(values_strings, name="values_strings"), + values_tensor=AttrTensor.maybe(values_tensor, name="values_tensor"), + ), + _LabelEncoder.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) _OPERATORS = { @@ -228,4 +260,4 @@ def label_encoder(X: Var, *, default_float: float = -0.0, default_int64: "ZipMap": zip_map, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index c1c90c3e..c35f6c9a 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -1,57 +1,60 @@ +# Copyright (c) QuantCo 2023-2024 +# SPDX-License-Identifier: BSD-3-Clause + # ruff: noqa: E741 -- Allow ambiguous variable name -import typing -import warnings +from collections.abc import Iterable from dataclasses import dataclass -from collections.abc import Iterable, Sequence from typing import ( - Any, - Callable, Optional, - Union, ) -from typing import cast as typing_cast import numpy as np -import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( - AttrDtype, - AttrFloat32, - AttrFloat32s, - AttrGraph, AttrInt64, AttrInt64s, - AttrString, - AttrStrings, AttrTensor, - AttrType, ) -from spox._graph import Graph, subgraph -from spox._internal_op import intro +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType -from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence -from spox._value_prop import PropValueType +from spox._standard import StandardNode +from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox.opset.ai.onnx.ml.v4 import ( + _ArrayFeatureExtractor, + _Binarizer, + _CastMap, + _CategoryMapper, + _DictVectorizer, + _FeatureVectorizer, + _Imputer, + _LabelEncoder, + _LinearClassifier, + _LinearRegressor, + _Normalizer, + _OneHotEncoder, + _Scaler, + _SVMClassifier, + _SVMRegressor, + _ZipMap, + array_feature_extractor, + binarizer, + cast_map, + category_mapper, + dict_vectorizer, + feature_vectorizer, + imputer, + label_encoder, + linear_classifier, + linear_regressor, + normalizer, + one_hot_encoder, + scaler, + svmclassifier, + svmregressor, + zip_map, +) -from spox.opset.ai.onnx.ml.v4 import _ArrayFeatureExtractor, array_feature_extractor -from spox.opset.ai.onnx.ml.v4 import _Binarizer, binarizer -from spox.opset.ai.onnx.ml.v4 import _CastMap, cast_map -from spox.opset.ai.onnx.ml.v4 import _CategoryMapper, category_mapper -from spox.opset.ai.onnx.ml.v4 import _DictVectorizer, dict_vectorizer -from spox.opset.ai.onnx.ml.v4 import _FeatureVectorizer, feature_vectorizer -from spox.opset.ai.onnx.ml.v4 import _Imputer, imputer -from spox.opset.ai.onnx.ml.v4 import _LabelEncoder, label_encoder -from spox.opset.ai.onnx.ml.v4 import _LinearClassifier, linear_classifier -from spox.opset.ai.onnx.ml.v4 import _LinearRegressor, linear_regressor -from spox.opset.ai.onnx.ml.v4 import _Normalizer, normalizer -from spox.opset.ai.onnx.ml.v4 import _OneHotEncoder, one_hot_encoder -from spox.opset.ai.onnx.ml.v4 import _SVMClassifier, svmclassifier -from spox.opset.ai.onnx.ml.v4 import _SVMRegressor, svmregressor -from spox.opset.ai.onnx.ml.v4 import _Scaler, scaler -from spox.opset.ai.onnx.ml.v4 import _ZipMap, zip_map class _TreeEnsemble(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -86,142 +89,181 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs -def tree_ensemble(X: Var, *, aggregate_function: int = 1, leaf_targetids: Iterable[int], leaf_weights: np.ndarray, membership_values: Optional[np.ndarray] = None, n_targets: Optional[int] = None, nodes_falseleafs: Iterable[int], nodes_falsenodeids: Iterable[int], nodes_featureids: Iterable[int], nodes_hitrates: Optional[np.ndarray] = None, nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, nodes_modes: np.ndarray, nodes_splits: np.ndarray, nodes_trueleafs: Iterable[int], nodes_truenodeids: Iterable[int], post_transform: int = 0, tree_roots: Iterable[int], ) -> Var: + +def tree_ensemble( + X: Var, + *, + aggregate_function: int = 1, + leaf_targetids: Iterable[int], + leaf_weights: np.ndarray, + membership_values: Optional[np.ndarray] = None, + n_targets: Optional[int] = None, + nodes_falseleafs: Iterable[int], + nodes_falsenodeids: Iterable[int], + nodes_featureids: Iterable[int], + nodes_hitrates: Optional[np.ndarray] = None, + nodes_missing_value_tracks_true: Optional[Iterable[int]] = None, + nodes_modes: np.ndarray, + nodes_splits: np.ndarray, + nodes_trueleafs: Iterable[int], + nodes_truenodeids: Iterable[int], + post_transform: int = 0, + tree_roots: Iterable[int], +) -> Var: r""" -Tree Ensemble operator. Returns the regressed values for each input in a -batch. Inputs have dimensions ``[N, F]`` where ``N`` is the input batch -size and ``F`` is the number of input features. Outputs have dimensions -``[N, num_targets]`` where ``N`` is the batch size and ``num_targets`` -is the number of targets, which is a configurable attribute. + Tree Ensemble operator. Returns the regressed values for each input in a + batch. Inputs have dimensions ``[N, F]`` where ``N`` is the input batch + size and ``F`` is the number of input features. Outputs have dimensions + ``[N, num_targets]`` where ``N`` is the batch size and ``num_targets`` + is the number of targets, which is a configurable attribute. -:: + :: - The encoding of this attribute is split along interior nodes and the leaves of the trees. Notably, attributes with the prefix `nodes_*` are associated with interior nodes, and attributes with the prefix `leaf_*` are associated with leaves. - The attributes `nodes_*` must all have the same length and encode a sequence of tuples, as defined by taking all the `nodes_*` fields at a given position. + The encoding of this attribute is split along interior nodes and the leaves of the trees. Notably, attributes with the prefix `nodes_*` are associated with interior nodes, and attributes with the prefix `leaf_*` are associated with leaves. + The attributes `nodes_*` must all have the same length and encode a sequence of tuples, as defined by taking all the `nodes_*` fields at a given position. - All fields prefixed with `leaf_*` represent tree leaves, and similarly define tuples of leaves and must have identical length. + All fields prefixed with `leaf_*` represent tree leaves, and similarly define tuples of leaves and must have identical length. - This operator can be used to implement both the previous `TreeEnsembleRegressor` and `TreeEnsembleClassifier` nodes. - The `TreeEnsembleRegressor` node maps directly to this node and requires changing how the nodes are represented. - The `TreeEnsembleClassifier` node can be implemented by adding a `ArgMax` node after this node to determine the top class. - To encode class labels, a `LabelEncoder` or `GatherND` operator may be used. + This operator can be used to implement both the previous `TreeEnsembleRegressor` and `TreeEnsembleClassifier` nodes. + The `TreeEnsembleRegressor` node maps directly to this node and requires changing how the nodes are represented. + The `TreeEnsembleClassifier` node can be implemented by adding a `ArgMax` node after this node to determine the top class. + To encode class labels, a `LabelEncoder` or `GatherND` operator may be used. -Parameters -========== -X - Type T. - Input of shape [Batch Size, Number of Features] -aggregate_function - Attribute. - Defines how to aggregate leaf values within a target. One of 'AVERAGE' - (0) 'SUM' (1) 'MIN' (2) 'MAX (3) defaults to 'SUM' (1) -leaf_targetids - Attribute. - The index of the target that this leaf contributes to (this must be in - range ``[0, n_targets)``). -leaf_weights - Attribute. - The weight for each leaf. -membership_values - Attribute. - Members to test membership of for each set membership node. List all of - the members to test again in the order that the 'BRANCH_MEMBER' mode - appears in ``node_modes``, delimited by ``NaN``\ s. Will have the same - number of sets of values as nodes with mode 'BRANCH_MEMBER'. This may be - omitted if the node doesn't contain any 'BRANCH_MEMBER' nodes. -n_targets - Attribute. - The total number of targets. -nodes_falseleafs - Attribute. - 1 if false branch is leaf for each node and 0 if an interior node. To - represent a tree that is a leaf (only has one node), one can do so by - having a single ``nodes_*`` entry with true and false branches - referencing the same ``leaf_*`` entry -nodes_falsenodeids - Attribute. - If ``nodes_falseleafs`` is false at an entry, this represents the - position of the false branch node. This position can be used to index - into a ``nodes_*`` entry. If ``nodes_falseleafs`` is false, it is an - index into the leaf\_\* attributes. -nodes_featureids - Attribute. - Feature id for each node. -nodes_hitrates - Attribute. - Popularity of each node, used for performance and may be omitted. -nodes_missing_value_tracks_true - Attribute. - For each node, define whether to follow the true branch (if attribute - value is 1) or false branch (if attribute value is 0) in the presence of - a NaN input feature. This attribute may be left undefined and the - default value is false (0) for all nodes. -nodes_modes - Attribute. - The comparison operation performed by the node. This is encoded as an - enumeration of 0 ('BRANCH_LEQ'), 1 ('BRANCH_LT'), 2 ('BRANCH_GTE'), 3 - ('BRANCH_GT'), 4 ('BRANCH_EQ'), 5 ('BRANCH_NEQ'), and 6 - ('BRANCH_MEMBER'). Note this is a tensor of type uint8. -nodes_splits - Attribute. - Thresholds to do the splitting on for each node with mode that is not - 'BRANCH_MEMBER'. -nodes_trueleafs - Attribute. - 1 if true branch is leaf for each node and 0 an interior node. To - represent a tree that is a leaf (only has one node), one can do so by - having a single ``nodes_*`` entry with true and false branches - referencing the same ``leaf_*`` entry -nodes_truenodeids - Attribute. - If ``nodes_trueleafs`` is false at an entry, this represents the - position of the true branch node. This position can be used to index - into a ``nodes_*`` entry. If ``nodes_trueleafs`` is false, it is an - index into the leaf\_\* attributes. -post_transform - Attribute. - Indicates the transform to apply to the score. One of 'NONE' (0), - 'SOFTMAX' (1), 'LOGISTIC' (2), 'SOFTMAX_ZERO' (3) or 'PROBIT' (4), - defaults to 'NONE' (0) -tree_roots - Attribute. - Index into ``nodes_*`` for the root of each tree. The tree structure is - derived from the branching of each node. + Parameters + ========== + X + Type T. + Input of shape [Batch Size, Number of Features] + aggregate_function + Attribute. + Defines how to aggregate leaf values within a target. One of 'AVERAGE' + (0) 'SUM' (1) 'MIN' (2) 'MAX (3) defaults to 'SUM' (1) + leaf_targetids + Attribute. + The index of the target that this leaf contributes to (this must be in + range ``[0, n_targets)``). + leaf_weights + Attribute. + The weight for each leaf. + membership_values + Attribute. + Members to test membership of for each set membership node. List all of + the members to test again in the order that the 'BRANCH_MEMBER' mode + appears in ``node_modes``, delimited by ``NaN``\ s. Will have the same + number of sets of values as nodes with mode 'BRANCH_MEMBER'. This may be + omitted if the node doesn't contain any 'BRANCH_MEMBER' nodes. + n_targets + Attribute. + The total number of targets. + nodes_falseleafs + Attribute. + 1 if false branch is leaf for each node and 0 if an interior node. To + represent a tree that is a leaf (only has one node), one can do so by + having a single ``nodes_*`` entry with true and false branches + referencing the same ``leaf_*`` entry + nodes_falsenodeids + Attribute. + If ``nodes_falseleafs`` is false at an entry, this represents the + position of the false branch node. This position can be used to index + into a ``nodes_*`` entry. If ``nodes_falseleafs`` is false, it is an + index into the leaf\_\* attributes. + nodes_featureids + Attribute. + Feature id for each node. + nodes_hitrates + Attribute. + Popularity of each node, used for performance and may be omitted. + nodes_missing_value_tracks_true + Attribute. + For each node, define whether to follow the true branch (if attribute + value is 1) or false branch (if attribute value is 0) in the presence of + a NaN input feature. This attribute may be left undefined and the + default value is false (0) for all nodes. + nodes_modes + Attribute. + The comparison operation performed by the node. This is encoded as an + enumeration of 0 ('BRANCH_LEQ'), 1 ('BRANCH_LT'), 2 ('BRANCH_GTE'), 3 + ('BRANCH_GT'), 4 ('BRANCH_EQ'), 5 ('BRANCH_NEQ'), and 6 + ('BRANCH_MEMBER'). Note this is a tensor of type uint8. + nodes_splits + Attribute. + Thresholds to do the splitting on for each node with mode that is not + 'BRANCH_MEMBER'. + nodes_trueleafs + Attribute. + 1 if true branch is leaf for each node and 0 an interior node. To + represent a tree that is a leaf (only has one node), one can do so by + having a single ``nodes_*`` entry with true and false branches + referencing the same ``leaf_*`` entry + nodes_truenodeids + Attribute. + If ``nodes_trueleafs`` is false at an entry, this represents the + position of the true branch node. This position can be used to index + into a ``nodes_*`` entry. If ``nodes_trueleafs`` is false, it is an + index into the leaf\_\* attributes. + post_transform + Attribute. + Indicates the transform to apply to the score. One of 'NONE' (0), + 'SOFTMAX' (1), 'LOGISTIC' (2), 'SOFTMAX_ZERO' (3) or 'PROBIT' (4), + defaults to 'NONE' (0) + tree_roots + Attribute. + Index into ``nodes_*`` for the root of each tree. The tree structure is + derived from the branching of each node. -Returns -======= -Y : Var - Type T. - Output of shape [Batch Size, Number of targets] + Returns + ======= + Y : Var + Type T. + Output of shape [Batch Size, Number of targets] -Notes -===== -Signature: ``ai.onnx.ml@5::TreeEnsemble``. + Notes + ===== + Signature: ``ai.onnx.ml@5::TreeEnsemble``. -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _TreeEnsemble( - _TreeEnsemble.Attributes( - aggregate_function=AttrInt64(aggregate_function, name="aggregate_function"), - leaf_targetids=AttrInt64s(leaf_targetids, name="leaf_targetids"), - leaf_weights=AttrTensor(leaf_weights, name="leaf_weights"), - membership_values=AttrTensor.maybe(membership_values, name="membership_values"), - n_targets=AttrInt64.maybe(n_targets, name="n_targets"), - nodes_falseleafs=AttrInt64s(nodes_falseleafs, name="nodes_falseleafs"), - nodes_falsenodeids=AttrInt64s(nodes_falsenodeids, name="nodes_falsenodeids"), - nodes_featureids=AttrInt64s(nodes_featureids, name="nodes_featureids"), - nodes_hitrates=AttrTensor.maybe(nodes_hitrates, name="nodes_hitrates"), - nodes_missing_value_tracks_true=AttrInt64s.maybe(nodes_missing_value_tracks_true, name="nodes_missing_value_tracks_true"), - nodes_modes=AttrTensor(nodes_modes, name="nodes_modes"), - nodes_splits=AttrTensor(nodes_splits, name="nodes_splits"), - nodes_trueleafs=AttrInt64s(nodes_trueleafs, name="nodes_trueleafs"), - nodes_truenodeids=AttrInt64s(nodes_truenodeids, name="nodes_truenodeids"), - post_transform=AttrInt64(post_transform, name="post_transform"), - tree_roots=AttrInt64s(tree_roots, name="tree_roots"), - ), _TreeEnsemble.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _TreeEnsemble( + _TreeEnsemble.Attributes( + aggregate_function=AttrInt64( + aggregate_function, name="aggregate_function" + ), + leaf_targetids=AttrInt64s(leaf_targetids, name="leaf_targetids"), + leaf_weights=AttrTensor(leaf_weights, name="leaf_weights"), + membership_values=AttrTensor.maybe( + membership_values, name="membership_values" + ), + n_targets=AttrInt64.maybe(n_targets, name="n_targets"), + nodes_falseleafs=AttrInt64s(nodes_falseleafs, name="nodes_falseleafs"), + nodes_falsenodeids=AttrInt64s( + nodes_falsenodeids, name="nodes_falsenodeids" + ), + nodes_featureids=AttrInt64s(nodes_featureids, name="nodes_featureids"), + nodes_hitrates=AttrTensor.maybe(nodes_hitrates, name="nodes_hitrates"), + nodes_missing_value_tracks_true=AttrInt64s.maybe( + nodes_missing_value_tracks_true, + name="nodes_missing_value_tracks_true", + ), + nodes_modes=AttrTensor(nodes_modes, name="nodes_modes"), + nodes_splits=AttrTensor(nodes_splits, name="nodes_splits"), + nodes_trueleafs=AttrInt64s(nodes_trueleafs, name="nodes_trueleafs"), + nodes_truenodeids=AttrInt64s( + nodes_truenodeids, name="nodes_truenodeids" + ), + post_transform=AttrInt64(post_transform, name="post_transform"), + tree_roots=AttrInt64s(tree_roots, name="tree_roots"), + ), + _TreeEnsemble.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) _OPERATORS = { @@ -264,4 +306,4 @@ def tree_ensemble(X: Var, *, aggregate_function: int = 1, leaf_targetids "ZipMap": zip_map, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 023e5da7..a9b3146b 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -1,21 +1,18 @@ +# Copyright (c) QuantCo 2023-2024 +# SPDX-License-Identifier: BSD-3-Clause + # ruff: noqa: E741 -- Allow ambiguous variable name -import typing -import warnings -from dataclasses import dataclass from collections.abc import Iterable, Sequence +from dataclasses import dataclass from typing import ( - Any, Callable, Optional, - Union, ) from typing import cast as typing_cast import numpy as np import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, AttrFloat32, @@ -28,12 +25,14 @@ AttrTensor, AttrType, ) +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._graph import Graph, subgraph -from spox._internal_op import intro from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._type_system import Sequence as SpoxSequence +from spox._type_system import Tensor, Type from spox._value_prop import PropValueType +from spox._var import Var, VarInfo, get_value, unwrap_vars class _Abs(StandardNode): @@ -55,6 +54,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Acos(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -74,6 +74,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Acosh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -93,6 +94,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Add(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -113,6 +115,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _And(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -133,6 +136,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ArgMax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -154,6 +158,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ArgMin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -175,6 +180,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Asin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -194,6 +200,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Asinh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -213,6 +220,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Atan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -232,6 +240,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Atanh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -251,6 +260,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _AveragePool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -275,6 +285,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _BatchNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -302,6 +313,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Bernoulli(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -322,6 +334,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _BitShift(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -342,6 +355,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _BlackmanWindow(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -362,6 +376,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Cast(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -381,6 +396,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _CastLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -401,6 +417,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Ceil(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -420,6 +437,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Celu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -439,6 +457,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Clip(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -460,6 +479,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Compress(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -476,28 +496,37 @@ class Outputs(BaseOutputs): def infer_output_types(self, initializers={}) -> dict[str, Type]: self.infer_output_types_onnx() - inp, cond = self.inputs.input.unwrap_tensor(), self.inputs.condition.unwrap_tensor() + inp, cond = ( + self.inputs.input.unwrap_tensor(), + self.inputs.condition.unwrap_tensor(), + ) if not inp.shape: - return {'output': Tensor(inp.dtype, None)} + return {"output": Tensor(inp.dtype, None)} if cond.dtype != np.dtype(bool): raise InferenceError("Compress input 'condition' must be a boolean dtype.") if cond.shape and len(cond.shape) != 1: - raise InferenceError("Compress input 'condition' must be a vector (of rank 1).") + raise InferenceError( + "Compress input 'condition' must be a vector (of rank 1)." + ) if self.attrs.axis is not None: shape = list(inp.shape) axis = self.attrs.axis.value if not (-len(shape) <= axis < len(shape)): - raise InferenceError(f"Compress attribute 'axis' must in range [-rank, rank-1] (rank={len(shape)}).") + raise InferenceError( + f"Compress attribute 'axis' must in range [-rank, rank-1] (rank={len(shape)})." + ) shape[axis] = None else: shape = [None] - return {'output': Tensor(inp.dtype, tuple(shape))} + return {"output": Tensor(inp.dtype, tuple(shape))} + op_type = OpType("Compress", "", 11) attrs: Attributes inputs: Inputs outputs: Outputs + class _Concat(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -517,6 +546,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ConcatFromSequence(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -537,6 +567,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Constant(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -555,7 +586,9 @@ class Outputs(BaseOutputs): output: VarInfo def propagate_values(self, initializers) -> dict[str, PropValueType]: - ((key, raw),) = ((k, v.value) for k, v in self.attrs.get_fields().items() if v is not None) + ((key, raw),) = ( + (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None + ) if key == "value": value = raw elif key == "value_float": @@ -573,14 +606,18 @@ def propagate_values(self, initializers) -> dict[str, PropValueType]: elif key == "sparse_value": return {} else: - raise RuntimeError(f"Could not extract the set Constant value attribute, got: {key}") + raise RuntimeError( + f"Could not extract the set Constant value attribute, got: {key}" + ) return {"output": value} + op_type = OpType("Constant", "", 13) attrs: Attributes inputs: BaseInputs outputs: Outputs + class _ConstantOfShape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -600,6 +637,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Conv(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -626,6 +664,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ConvInteger(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -653,6 +692,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ConvTranspose(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -681,6 +721,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Cos(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -700,6 +741,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Cosh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -719,6 +761,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _CumSum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -740,6 +783,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _DFT(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -762,6 +806,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _DepthToSpace(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -782,6 +827,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _DequantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -803,6 +849,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Det(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -822,6 +869,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Div(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -842,6 +890,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Dropout(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -864,6 +913,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _DynamicQuantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -885,6 +935,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Einsum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -904,6 +955,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Elu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -923,6 +975,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Equal(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -943,6 +996,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Erf(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -962,6 +1016,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Exp(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -981,6 +1036,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Expand(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1001,6 +1057,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _EyeLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1021,6 +1078,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Flatten(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1040,6 +1098,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Floor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1059,6 +1118,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GRU(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1091,6 +1151,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Gather(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1111,6 +1172,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GatherElements(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1131,6 +1193,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GatherND(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1151,6 +1214,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Gemm(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1175,6 +1239,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GlobalAveragePool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1194,6 +1259,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GlobalLpPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1213,6 +1279,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GlobalMaxPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1232,6 +1299,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Greater(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1252,6 +1320,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GreaterOrEqual(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1272,6 +1341,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GridSample(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1294,6 +1364,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _HammingWindow(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1314,6 +1385,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _HannWindow(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1334,6 +1406,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _HardSigmoid(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1354,6 +1427,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _HardSwish(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1373,6 +1447,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Hardmax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1392,6 +1467,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Identity(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1411,6 +1487,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _If(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1431,6 +1508,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _InstanceNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1452,6 +1530,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _IsInf(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1472,6 +1551,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _IsNaN(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1491,6 +1571,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LRN(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1513,6 +1594,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LSTM(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1548,6 +1630,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LayerNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1573,6 +1656,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LeakyRelu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1592,6 +1676,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Less(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1612,6 +1697,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LessOrEqual(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1632,6 +1718,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Log(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1651,6 +1738,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LogSoftmax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1670,6 +1758,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Loop(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1686,7 +1775,7 @@ class Outputs(BaseOutputs): v_final_and_scan_outputs: Sequence[VarInfo] def infer_output_types(self, initializers={}) -> dict[str, Type]: - output_types = super().infer_output_types() + output_types = super().infer_output_types(initializers) body = self.attrs.body.value n = len(body.requested_arguments) - 2 @@ -1698,12 +1787,14 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: output_types[name] = typ return output_types + op_type = OpType("Loop", "", 16) attrs: Attributes inputs: Inputs outputs: Outputs + class _LpNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1724,6 +1815,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LpPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1747,6 +1839,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _MatMul(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1767,6 +1860,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _MatMulInteger(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1789,6 +1883,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Max(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1808,6 +1903,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _MaxPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1834,6 +1930,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _MaxRoiPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1855,6 +1952,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _MaxUnpool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1878,6 +1976,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Mean(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1897,6 +1996,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _MeanVarianceNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1916,6 +2016,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _MelWeightMatrix(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1939,6 +2040,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Min(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1958,6 +2060,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Mod(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1978,6 +2081,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Mul(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -1998,6 +2102,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Multinomial(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2019,6 +2124,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Neg(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2038,6 +2144,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _NegativeLogLikelihoodLoss(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2060,6 +2167,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _NonMaxSuppression(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2083,6 +2191,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _NonZero(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2102,6 +2211,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Not(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2121,6 +2231,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _OneHot(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2142,6 +2253,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Optional(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2161,6 +2273,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _OptionalGetElement(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2180,6 +2293,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _OptionalHasElement(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2199,6 +2313,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Or(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2219,6 +2334,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _PRelu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2239,6 +2355,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Pad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2260,6 +2377,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Pow(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2280,6 +2398,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _QLinearConv(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2312,6 +2431,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _QLinearMatMul(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2338,6 +2458,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _QuantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2359,6 +2480,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _RNN(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2390,6 +2512,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _RandomNormal(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2411,6 +2534,7 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs + class _RandomNormalLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2433,6 +2557,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _RandomUniform(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2454,6 +2579,7 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs + class _RandomUniformLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2476,6 +2602,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Range(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2497,6 +2624,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Reciprocal(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2516,6 +2644,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceL1(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2536,6 +2665,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceL2(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2556,6 +2686,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceLogSum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2576,6 +2707,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceLogSumExp(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2596,6 +2728,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceMax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2616,6 +2749,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceMean(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2636,6 +2770,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceMin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2656,6 +2791,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceProd(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2676,6 +2812,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceSum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2697,6 +2834,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceSumSquare(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2717,6 +2855,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Relu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2736,6 +2875,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Reshape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2756,6 +2896,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Resize(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2783,6 +2924,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReverseSequence(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2804,6 +2946,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _RoiAlign(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2830,6 +2973,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Round(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2849,6 +2993,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _STFT(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2871,6 +3016,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Scan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2895,6 +3041,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ScatterElements(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2917,6 +3064,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ScatterND(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2938,6 +3086,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Selu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2958,6 +3107,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SequenceAt(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2978,6 +3128,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SequenceConstruct(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -2997,6 +3148,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SequenceEmpty(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3014,6 +3166,7 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs + class _SequenceErase(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3034,6 +3187,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SequenceInsert(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3055,6 +3209,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SequenceLength(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3074,6 +3229,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SequenceMap(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3094,6 +3250,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Shape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3114,6 +3271,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Shrink(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3134,6 +3292,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Sigmoid(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3153,6 +3312,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Sign(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3172,6 +3332,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Sin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3191,6 +3352,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Sinh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3210,6 +3372,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Size(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3229,6 +3392,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Slice(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3252,6 +3416,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Softmax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3271,6 +3436,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SoftmaxCrossEntropyLoss(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3294,6 +3460,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Softplus(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3313,6 +3480,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Softsign(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3332,6 +3500,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SpaceToDepth(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3351,6 +3520,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Split(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3371,6 +3541,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _SplitToSequence(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3392,6 +3563,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Sqrt(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3411,6 +3583,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Squeeze(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3431,6 +3604,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _StringNormalizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3453,6 +3627,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Sub(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3473,6 +3648,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Sum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3492,6 +3668,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Tan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3511,6 +3688,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Tanh(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3530,6 +3708,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _TfIdfVectorizer(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3557,6 +3736,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ThresholdedRelu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3576,6 +3756,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Tile(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3596,6 +3777,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _TopK(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3619,6 +3801,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Transpose(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3638,6 +3821,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Trilu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3658,6 +3842,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Unique(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3681,6 +3866,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Unsqueeze(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3701,6 +3887,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Where(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3722,6 +3909,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Xor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -3742,10266 +3930,12786 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs -def abs(X: Var, ) -> Var: - r""" -Absolute takes one input data (Tensor) and produces one output data -(Tensor) where absolute value, y = abs(x), is applied to the tensor -elementwise. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor -Notes -===== -Signature: ``ai.onnx@13::Abs``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` +def abs( + X: Var, +) -> Var: + r""" + Absolute takes one input data (Tensor) and produces one output data + (Tensor) where absolute value, y = abs(x), is applied to the tensor + elementwise. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::Abs``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Abs( - _Abs.Attributes( - ), _Abs.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _Abs( + _Abs.Attributes(), + _Abs.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def acos(input: Var, ) -> Var: +def acos( + input: Var, +) -> Var: r""" -Calculates the arccosine (inverse of cosine) of the given input tensor, -element-wise. + Calculates the arccosine (inverse of cosine) of the given input tensor, + element-wise. -Parameters -========== -input - Type T. - Input tensor + Parameters + ========== + input + Type T. + Input tensor -Returns -======= -output : Var - Type T. - The arccosine of the input tensor computed element-wise + Returns + ======= + output : Var + Type T. + The arccosine of the input tensor computed element-wise -Notes -===== -Signature: ``ai.onnx@7::Acos``. + Notes + ===== + Signature: ``ai.onnx@7::Acos``. -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Acos( - _Acos.Attributes( - ), _Acos.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Acos( + _Acos.Attributes(), + _Acos.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def acosh(input: Var, ) -> Var: +def acosh( + input: Var, +) -> Var: r""" -Calculates the hyperbolic arccosine of the given input tensor -element-wise. + Calculates the hyperbolic arccosine of the given input tensor + element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The hyperbolic arccosine values of the input tensor computed + element-wise + + Notes + ===== + Signature: ``ai.onnx@9::Acosh``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Acosh( + _Acosh.Attributes(), + _Acosh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -Parameters -========== -input - Type T. - Input tensor -Returns -======= -output : Var - Type T. - The hyperbolic arccosine values of the input tensor computed - element-wise +def add( + A: Var, + B: Var, +) -> Var: + r""" + Performs element-wise binary addition (with Numpy-style broadcasting + support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + (Opset 14 change): Extend supported types to include uint8, int8, + uint16, and int16. + + Parameters + ========== + A + Type T. + First operand. + B + Type T. + Second operand. + + Returns + ======= + C : Var + Type T. + Result, has same element type as two inputs + + Notes + ===== + Signature: ``ai.onnx@14::Add``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Add( + _Add.Attributes(), + _Add.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) -Notes -===== -Signature: ``ai.onnx@9::Acosh``. -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +def and_( + A: Var, + B: Var, +) -> Var: + r""" + Returns the tensor resulted from performing the ``and`` logical + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@7::And``. + + Type constraints: + - T: `tensor(bool)` + - T1: `tensor(bool)` """ - return _Acosh( - _Acosh.Attributes( - ), _Acosh.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _And( + _And.Attributes(), + _And.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) -def add(A: Var, B: Var, ) -> Var: - r""" -Performs element-wise binary addition (with Numpy-style broadcasting -support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -(Opset 14 change): Extend supported types to include uint8, int8, -uint16, and int16. - -Parameters -========== -A - Type T. - First operand. -B - Type T. - Second operand. - -Returns -======= -C : Var - Type T. - Result, has same element type as two inputs - -Notes -===== -Signature: ``ai.onnx@14::Add``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Add( - _Add.Attributes( - ), _Add.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def and_(A: Var, B: Var, ) -> Var: - r""" -Returns the tensor resulted from performing the ``and`` logical -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. - -Returns -======= -C : Var - Type T1. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@7::And``. - -Type constraints: - - T: `tensor(bool)` - - T1: `tensor(bool)` - """ - return _And( - _And.Attributes( - ), _And.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def arg_max(data: Var, *, axis: int = 0, keepdims: int = 1, select_last_index: int = 0, ) -> Var: - r""" -Computes the indices of the max elements of the input tensor's element -along the provided axis. The resulting tensor has the same rank as the -input if keepdims equals 1. If keepdims equals 0, then the resulting -tensor has the reduced dimension pruned. If select_last_index is True -(default False), the index of the last occurrence of the max is selected -if the max appears more than once in the input. Otherwise the index of -the first occurrence is selected. The type of the output tensor is -integer. - -Parameters -========== -data - Type T. - An input tensor. -axis - Attribute. - The axis in which to compute the arg indices. Accepted range is [-r, - r-1] where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -select_last_index - Attribute. - Whether to select the last index or the first index if the {name} - appears in multiple indices, default is False (first index). - -Returns -======= -reduced : Var - Type tensor(int64). - Reduced output tensor with integer data type. - -Notes -===== -Signature: ``ai.onnx@13::ArgMax``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _ArgMax( - _ArgMax.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - select_last_index=AttrInt64(select_last_index, name="select_last_index"), - ), _ArgMax.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def arg_min(data: Var, *, axis: int = 0, keepdims: int = 1, select_last_index: int = 0, ) -> Var: - r""" -Computes the indices of the min elements of the input tensor's element -along the provided axis. The resulting tensor has the same rank as the -input if keepdims equals 1. If keepdims equals 0, then the resulting -tensor has the reduced dimension pruned. If select_last_index is True -(default False), the index of the last occurrence of the min is selected -if the min appears more than once in the input. Otherwise the index of -the first occurrence is selected. The type of the output tensor is -integer. - -Parameters -========== -data - Type T. - An input tensor. -axis - Attribute. - The axis in which to compute the arg indices. Accepted range is [-r, - r-1] where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -select_last_index - Attribute. - Whether to select the last index or the first index if the {name} - appears in multiple indices, default is False (first index). - -Returns -======= -reduced : Var - Type tensor(int64). - Reduced output tensor with integer data type. - -Notes -===== -Signature: ``ai.onnx@13::ArgMin``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _ArgMin( - _ArgMin.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - select_last_index=AttrInt64(select_last_index, name="select_last_index"), - ), _ArgMin.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def asin(input: Var, ) -> Var: - r""" -Calculates the arcsine (inverse of sine) of the given input tensor, -element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The arcsine of the input tensor computed element-wise - -Notes -===== -Signature: ``ai.onnx@7::Asin``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Asin( - _Asin.Attributes( - ), _Asin.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def asinh(input: Var, ) -> Var: - r""" -Calculates the hyperbolic arcsine of the given input tensor -element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The hyperbolic arcsine values of the input tensor computed element-wise +def arg_max( + data: Var, + *, + axis: int = 0, + keepdims: int = 1, + select_last_index: int = 0, +) -> Var: + r""" + Computes the indices of the max elements of the input tensor's element + along the provided axis. The resulting tensor has the same rank as the + input if keepdims equals 1. If keepdims equals 0, then the resulting + tensor has the reduced dimension pruned. If select_last_index is True + (default False), the index of the last occurrence of the max is selected + if the max appears more than once in the input. Otherwise the index of + the first occurrence is selected. The type of the output tensor is + integer. + + Parameters + ========== + data + Type T. + An input tensor. + axis + Attribute. + The axis in which to compute the arg indices. Accepted range is [-r, + r-1] where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + select_last_index + Attribute. + Whether to select the last index or the first index if the {name} + appears in multiple indices, default is False (first index). + + Returns + ======= + reduced : Var + Type tensor(int64). + Reduced output tensor with integer data type. + + Notes + ===== + Signature: ``ai.onnx@13::ArgMax``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _ArgMax( + _ArgMax.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + select_last_index=AttrInt64( + select_last_index, name="select_last_index" + ), + ), + _ArgMax.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + -Notes -===== -Signature: ``ai.onnx@9::Asinh``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +def arg_min( + data: Var, + *, + axis: int = 0, + keepdims: int = 1, + select_last_index: int = 0, +) -> Var: + r""" + Computes the indices of the min elements of the input tensor's element + along the provided axis. The resulting tensor has the same rank as the + input if keepdims equals 1. If keepdims equals 0, then the resulting + tensor has the reduced dimension pruned. If select_last_index is True + (default False), the index of the last occurrence of the min is selected + if the min appears more than once in the input. Otherwise the index of + the first occurrence is selected. The type of the output tensor is + integer. + + Parameters + ========== + data + Type T. + An input tensor. + axis + Attribute. + The axis in which to compute the arg indices. Accepted range is [-r, + r-1] where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + select_last_index + Attribute. + Whether to select the last index or the first index if the {name} + appears in multiple indices, default is False (first index). + + Returns + ======= + reduced : Var + Type tensor(int64). + Reduced output tensor with integer data type. + + Notes + ===== + Signature: ``ai.onnx@13::ArgMin``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Asinh( - _Asinh.Attributes( - ), _Asinh.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _ArgMin( + _ArgMin.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + select_last_index=AttrInt64( + select_last_index, name="select_last_index" + ), + ), + _ArgMin.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) -def atan(input: Var, ) -> Var: +def asin( + input: Var, +) -> Var: r""" -Calculates the arctangent (inverse of tangent) of the given input -tensor, element-wise. + Calculates the arcsine (inverse of sine) of the given input tensor, + element-wise. -Parameters -========== -input - Type T. - Input tensor + Parameters + ========== + input + Type T. + Input tensor -Returns -======= -output : Var - Type T. - The arctangent of the input tensor computed element-wise + Returns + ======= + output : Var + Type T. + The arcsine of the input tensor computed element-wise -Notes -===== -Signature: ``ai.onnx@7::Atan``. + Notes + ===== + Signature: ``ai.onnx@7::Asin``. -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Atan( - _Atan.Attributes( - ), _Atan.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Asin( + _Asin.Attributes(), + _Asin.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def atanh(input: Var, ) -> Var: +def asinh( + input: Var, +) -> Var: r""" -Calculates the hyperbolic arctangent of the given input tensor -element-wise. + Calculates the hyperbolic arcsine of the given input tensor + element-wise. -Parameters -========== -input - Type T. - Input tensor + Parameters + ========== + input + Type T. + Input tensor -Returns -======= -output : Var - Type T. - The hyperbolic arctangent values of the input tensor computed - element-wise + Returns + ======= + output : Var + Type T. + The hyperbolic arcsine values of the input tensor computed element-wise -Notes -===== -Signature: ``ai.onnx@9::Atanh``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Atanh( - _Atanh.Attributes( - ), _Atanh.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def average_pool(X: Var, *, auto_pad: str = "NOTSET", ceil_mode: int = 0, count_include_pad: int = 0, kernel_shape: Iterable[int], pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: - r""" -AveragePool consumes an input tensor X and applies average pooling -across the tensor according to kernel sizes, stride sizes, and pad -lengths. average pooling consisting of computing the average on all -values of a subset of the input tensor according to the kernel size and -downsampling the data into the output tensor Y for further processing. -The output spatial shape will be following: - -:: - - output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) - -or - -:: - - output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) - -if ceil_mode is enabled - -:: - - * pad_shape[i] is sum of pads along axis i - -``auto_pad`` is a DEPRECATED attribute. If you are using them currently, -the output spatial shape will be following when ceil_mode is enabled: - -:: - - VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) - -or when ceil_mode is disabled: - -:: - - VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor(input_spatial_shape[i] / strides_spatial_shape[i]) - -And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: - -:: - - pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] - -The output of each pooling window is divided by the number of elements -(exclude pad when attribute count_include_pad is zero). - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. Optionally, if dimension denotation is in - effect, the operation expects the input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. -ceil_mode - Attribute. - Whether to use ceil or floor (default) to compute the output shape. -count_include_pad - Attribute. - Whether include pad pixels when calculating values for the edges. - Default is 0, doesn't count include pad. -kernel_shape - Attribute. - The size of the kernel along each axis. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - -Returns -======= -Y : Var - Type T. - Output data tensor from average or max pooling across the input tensor. - Dimensions will vary based on various kernel, stride, and pad sizes. - Floor value of the dimension is used - -Notes -===== -Signature: ``ai.onnx@11::AveragePool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _AveragePool( - _AveragePool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - count_include_pad=AttrInt64(count_include_pad, name="count_include_pad"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _AveragePool.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def batch_normalization(X: Var, scale: Var, B: Var, input_mean: Var, input_var: Var, *, epsilon: float = 9.999999747378752e-06, momentum: float = 0.8999999761581421, training_mode: int = 0, ) -> tuple[Var, Var, Var]: - r""" -Carries out batch normalization as described in the paper -https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, -There are five required inputs 'X', 'scale', 'B', 'input_mean' and -'input_var'. Note that 'input_mean' and 'input_var' are expected to be -the estimated statistics in inference mode (training_mode=False, -default), and the running statistics in training mode -(training_mode=True). There are multiple cases for the number of -outputs, which we list below: - -- Output case #1: Y, running_mean, running_var (training_mode=True) -- Output case #2: Y (training_mode=False) - -When training_mode=False, extra outputs are invalid. The outputs are -updated as follows when training_mode=True: - -:: - - running_mean = input_mean * momentum + current_mean * (1 - momentum) - running_var = input_var * momentum + current_var * (1 - momentum) - - Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B - -where: - -:: - - current_mean = ReduceMean(X, axis=all_except_channel_index) - current_var = ReduceVar(X, axis=all_except_channel_index) - -Notice that ``ReduceVar`` refers to the population variance, and it -equals to ``sum(sqrd(x_i - x_avg)) / N`` where ``N`` is the population -size (this formula does not use sample size ``N - 1``). - -The computation of ReduceMean and ReduceVar uses float to avoid overflow -for float16 inputs. - -When training_mode=False: - -:: - - Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B - -For previous (depreciated) non-spatial cases, implementors are suggested -to flatten the input shape to (N x C \* D1 \* D2 \* ... \* Dn) before a -BatchNormalization Op. This operator has **optional** inputs/outputs. -See `the doc `__ for -more details about the representation of optional arguments. An empty -string may be used in the place of an actual argument's name to indicate -a missing argument. Trailing optional arguments (those not followed by -an argument that is present) may also be simply omitted. - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions are in the form - of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number - of channels. Statistics are computed for every channel of C over N and - D1 to Dn dimensions. For image data, input dimensions become (N x C x H - x W). The op also accepts single dimension input of size N in which case - C is assumed to be 1 -scale - Type T1. - Scale tensor of shape (C). -B - Type T1. - Bias tensor of shape (C). -input_mean - Type T2. - running (training) or estimated (testing) mean tensor of shape (C). -input_var - Type T2. - running (training) or estimated (testing) variance tensor of shape (C). -epsilon - Attribute. - The epsilon value to use to avoid division by zero. -momentum - Attribute. - Factor used in computing the running mean and variance.e.g., - running_mean = running_mean \* momentum + mean \* (1 - momentum). -training_mode - Attribute. - If set to true, it indicates BatchNormalization is being used for - training, and outputs 1 and 2 are to be computed. - -Returns -======= -Y : Var - Type T. - The output tensor of the same shape as X -running_mean : Var - Type T2. - The running mean after the BatchNormalization operator. -running_var : Var - Type T2. - The running variance after the BatchNormalization operator. This op uses - the population size (N) for calculating variance, and not the sample - size N-1. - -Notes -===== -Signature: ``ai.onnx@15::BatchNormalization``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _BatchNormalization( - _BatchNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - momentum=AttrFloat32(momentum, name="momentum"), - training_mode=AttrInt64(training_mode, name="training_mode"), - ), _BatchNormalization.Inputs( - X=unwrap_vars(X), scale=unwrap_vars(scale), B=unwrap_vars(B), input_mean=unwrap_vars(input_mean), input_var=unwrap_vars(input_var), ), ).get_output_vars( - X=get_value(X), scale=get_value(scale), B=get_value(B), input_mean=get_value(input_mean), input_var=get_value(input_var), )._unpack_to_any() - - -def bernoulli(input: Var, *, dtype: Optional[npt.DTypeLike] = None, seed: Optional[float] = None, ) -> Var: - r""" -Draws binary random numbers (0 or 1) from a Bernoulli distribution. The -input tensor should be a tensor containing probabilities p (a value in -the range [0,1]) to be used for drawing the binary random number, where -an output of 1 is produced with probability p and an output of 0 is -produced with probability (1-p). - -This operator is non-deterministic and may not produce the same values -in different implementations (even if a seed is specified). - -Parameters -========== -input - Type T1. - All values in input have to be in the range:[0, 1]. -dtype - Attribute. - The data type for the elements of the output tensor. if not specified, - we will use the data type of the input tensor. -seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - -Returns -======= -output : Var - Type T2. - The returned output tensor only has values 0 or 1, same shape as input - tensor. - -Notes -===== -Signature: ``ai.onnx@15::Bernoulli``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Bernoulli( - _Bernoulli.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), _Bernoulli.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def bit_shift(X: Var, Y: Var, *, direction: str, ) -> Var: - r""" -Bitwise shift operator performs element-wise operation. For each input -element, if the attribute "direction" is "RIGHT", this operator moves -its binary representation toward the right side so that the input value -is effectively decreased. If the attribute "direction" is "LEFT", bits -of binary representation moves toward the left side, which results the -increase of its actual value. The input X is the tensor to be shifted -and another input Y specifies the amounts of shifting. For example, if -"direction" is "Right", X is [1, 4], and S is [1, 1], the corresponding -output Z would be [0, 2]. If "direction" is "LEFT" with X=[1, 2] and -S=[1, 2], the corresponding output Y would be [2, 8]. - -Because this operator supports Numpy-style broadcasting, X's and Y's -shapes are not necessarily identical. This operator supports -**multidirectional (i.e., Numpy-style) broadcasting**; for more details -please check `the -doc `__. - -Parameters -========== -X - Type T. - First operand, input to be shifted. -Y - Type T. - Second operand, amounts of shift. -direction - Attribute. - Direction of moving bits. It can be either "RIGHT" (for right shift) or - "LEFT" (for left shift). - -Returns -======= -Z : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@11::BitShift``. - -Type constraints: - - T: `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _BitShift( - _BitShift.Attributes( - direction=AttrString(direction, name="direction"), - ), _BitShift.Inputs( - X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( - X=get_value(X), Y=get_value(Y), ).Z - - -def blackman_window(size: Var, *, output_datatype: int = 1, periodic: int = 1, ) -> Var: - r""" -Generates a Blackman window as described in the paper -https://ieeexplore.ieee.org/document/1455106. - -Parameters -========== -size - Type T1. - A scalar value indicating the length of the window. -output_datatype - Attribute. - The data type of the output tensor. Strictly must be one of the values - from DataType enum in TensorProto whose values correspond to T2. The - default value is 1 = FLOAT. -periodic - Attribute. - If 1, returns a window to be used as periodic function. If 0, return a - symmetric window. When 'periodic' is specified, hann computes a window - of length size + 1 and returns the first size points. The default value - is 1. - -Returns -======= -output : Var - Type T2. - A Blackman window with length: size. The output has the shape: [size]. - -Notes -===== -Signature: ``ai.onnx@17::BlackmanWindow``. - -Type constraints: - - T1: `tensor(int32)`, `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _BlackmanWindow( - _BlackmanWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), _BlackmanWindow.Inputs( - size=unwrap_vars(size), ), ).get_output_vars( - size=get_value(size), ).output - - -def cast(input: Var, *, to: npt.DTypeLike, ) -> Var: - r""" -The operator casts the elements of a given input tensor to a data type -specified by the 'to' argument and returns an output tensor of the same -size in the converted type. The 'to' argument must be one of the data -types specified in the 'DataType' enum field in the TensorProto message. - -Casting from string tensor in plain (e.g., "3.14" and "1000") and -scientific numeric representations (e.g., "1e-5" and "1E8") to float -types is supported. For example, converting string "100.5" to an integer -may yield result 100. There are some string literals reserved for -special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are -positive infinity, negative infinity, and not-a-number, respectively. -Any string which can exactly match "+INF" in a case-insensitive way -would be mapped to positive infinite. Similarly, this case-insensitive -rule is applied to "INF" and "NaN". When casting from numeric tensors to -string tensors, plain floating-point representation (such as -"314.15926") would be used. Converting non-numerical-literal string such -as "Hello World!" is an undefined behavior. Cases of converting string -representing floating-point arithmetic value, such as "2.718", to INT is -an undefined behavior. - -Conversion from a numerical type to any numerical type is always -allowed. User must be aware of precision loss and value change caused by -range difference between two types. For example, a 64-bit float -3.1415926459 may be round to a 32-bit float 3.141592. Similarly, -converting an integer 36 to Boolean may produce 1 because we truncate -bits which can't be stored in the targeted type. - -In more detail, the conversion among numerical types should follow these -rules: - -- Casting from floating point to: - - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. - -- Casting from fixed point to: - - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. - -- Casting from bool to: - - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. - -Parameters -========== -input - Type T1. - Input tensor to be cast. -to - Attribute. - The data type to which the elements of the input tensor are cast. - Strictly must be one of the types from DataType enum in TensorProto - -Returns -======= -output : Var - Type T2. - Output tensor with the same shape as input with type specified by the - 'to' argument - -Notes -===== -Signature: ``ai.onnx@13::Cast``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Cast( - _Cast.Attributes( - to=AttrDtype(to, name="to"), - ), _Cast.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def cast_like(input: Var, target_type: Var, ) -> Var: - r""" -The operator casts the elements of a given input tensor (the first -input) to the same data type as the elements of the second input tensor. -See documentation of the Cast operator for further details. - -Parameters -========== -input - Type T1. - Input tensor to be cast. -target_type - Type T2. - The (first) input tensor will be cast to produce a tensor of the same - type as this (second input) tensor. - -Returns -======= -output : Var - Type T2. - Output tensor produced by casting the first input tensor to have the - same type as the second input tensor. - -Notes -===== -Signature: ``ai.onnx@15::CastLike``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _CastLike( - _CastLike.Attributes( - ), _CastLike.Inputs( - input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), ).get_output_vars( - input=get_value(input), target_type=get_value(target_type), ).output - - -def ceil(X: Var, ) -> Var: - r""" -Ceil takes one input data (Tensor) and produces one output data -(Tensor) where the ceil is, y = ceil(x), is applied to the tensor -elementwise. If x is integral, +0, -0, NaN, or infinite, x itself is -returned. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@13::Ceil``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Ceil( - _Ceil.Attributes( - ), _Ceil.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def celu(X: Var, *, alpha: float = 1.0, ) -> Var: - r""" -Continuously Differentiable Exponential Linear Units: Perform the linear -unit element-wise on the input tensor X using formula: - -:: - - max(0,x) + min(0,alpha*(exp(x/alpha)-1)) - -Parameters -========== -X - Type T. - Input tensor -alpha - Attribute. - The Alpha value in Celu formula which control the shape of the unit. The - default value is 1.0. - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@12::Celu``. - -Type constraints: - - T: `tensor(float)` - """ - return _Celu( - _Celu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), _Celu.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def clip(input: Var, min: Optional[Var] = None, max: Optional[Var] = None, ) -> Var: - r""" -Clip operator limits the given input within an interval. The interval is -specified by the inputs 'min' and 'max'. They default to -numeric_limits::lowest() and numeric_limits::max(), respectively. - -Parameters -========== -input - Type T. - Input tensor whose elements to be clipped -min - Type T. - Minimum value, under which element is replaced by min. It must be a - scalar(tensor of empty shape). -max - Type T. - Maximum value, above which element is replaced by max. It must be a - scalar(tensor of empty shape). - -Returns -======= -output : Var - Type T. - Output tensor with clipped input elements - -Notes -===== -Signature: ``ai.onnx@13::Clip``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Clip( - _Clip.Attributes( - ), _Clip.Inputs( - input=unwrap_vars(input), min=unwrap_vars(min), max=unwrap_vars(max), ), ).get_output_vars( - input=get_value(input), min=get_value(min), max=get_value(max), ).output - - -def compress(input: Var, condition: Var, *, axis: Optional[int] = None, ) -> Var: - r""" -Selects slices from an input tensor along a given axis where condition -evaluates to True for each axis index. In case axis is not provided, -input is flattened before elements are selected. Compress behaves like -numpy.compress: -https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html - -Parameters -========== -input - Type T. - Tensor of rank r >= 1. -condition - Type T1. - Rank 1 tensor of booleans to indicate which slices or data elements to - be selected. Its length can be less than the input length along the axis - or the flattened input size if axis is not specified. In such cases data - slices or elements exceeding the condition length are discarded. -axis - Attribute. - (Optional) Axis along which to take slices. If not specified, input is - flattened before elements being selected. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - -Returns -======= -output : Var - Type T. - Tensor of rank r if axis is specified. Otherwise output is a Tensor of - rank 1. - -Notes -===== -Signature: ``ai.onnx@11::Compress``. - -Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return _Compress( - _Compress.Attributes( - axis=AttrInt64.maybe(axis, name="axis"), - ), _Compress.Inputs( - input=unwrap_vars(input), condition=unwrap_vars(condition), ), ).get_output_vars( - input=get_value(input), condition=get_value(condition), ).output - - -def concat(inputs: Sequence[Var], *, axis: int, ) -> Var: - r""" -Concatenate a list of tensors into a single tensor. All input tensors -must have the same shape, except for the dimension size of the axis to -concatenate on. - -Parameters -========== -inputs - Type T. - List of tensors for concatenation -axis - Attribute. - Which axis to concat on. A negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(inputs).. - -Returns -======= -concat_result : Var - Type T. - Concatenated tensor - -Notes -===== -Signature: ``ai.onnx@13::Concat``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Concat( - _Concat.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _Concat.Inputs( - inputs=unwrap_vars(inputs), ), ).get_output_vars( - inputs=get_value(inputs), ).concat_result - - -def concat_from_sequence(input_sequence: Var, *, axis: int, new_axis: int = 0, ) -> Var: - r""" -Concatenate a sequence of tensors into a single tensor. All input -tensors must have the same shape, except for the dimension size of the -axis to concatenate on. By default 'new_axis' is 0, the behavior is -similar to numpy.concatenate. When 'new_axis' is 1, the behavior is -similar to numpy.stack. - -Parameters -========== -input_sequence - Type S. - Sequence of tensors for concatenation -axis - Attribute. - Which axis to concat on. Accepted range in ``[-r, r - 1]``, where ``r`` - is the rank of input tensors. When ``new_axis`` is 1, accepted range is - ``[-r - 1, r]``. -new_axis - Attribute. - Insert and concatenate on a new axis or not, default 0 means do not - insert new axis. - -Returns -======= -concat_result : Var - Type T. - Concatenated tensor - -Notes -===== -Signature: ``ai.onnx@11::ConcatFromSequence``. - -Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _ConcatFromSequence( - _ConcatFromSequence.Attributes( - axis=AttrInt64(axis, name="axis"), - new_axis=AttrInt64(new_axis, name="new_axis"), - ), _ConcatFromSequence.Inputs( - input_sequence=unwrap_vars(input_sequence), ), ).get_output_vars( - input_sequence=get_value(input_sequence), ).concat_result - - -def constant(*, value: Optional[np.ndarray] = None, value_float: Optional[float] = None, value_floats: Optional[Iterable[float]] = None, value_int: Optional[int] = None, value_ints: Optional[Iterable[int]] = None, value_string: Optional[str] = None, value_strings: Optional[Iterable[str]] = None, ) -> Var: - r""" -This operator produces a constant tensor. Exactly one of the provided -attributes, either value, sparse_value, or value\_\* must be specified. - -Parameters -========== -sparse_value - Attribute. - The value for the elements of the output tensor in sparse format. -value - Attribute. - The value for the elements of the output tensor. -value_float - Attribute. - The value for the sole element for the scalar, float32, output tensor. -value_floats - Attribute. - The values for the elements for the 1D, float32, output tensor. -value_int - Attribute. - The value for the sole element for the scalar, int64, output tensor. -value_ints - Attribute. - The values for the elements for the 1D, int64, output tensor. -value_string - Attribute. - The value for the sole element for the scalar, UTF-8 string, output - tensor. -value_strings - Attribute. - The values for the elements for the 1D, UTF-8 string, output tensor. - -Returns -======= -output : Var - Type T. - Output tensor containing the same value of the provided tensor. - -Notes -===== -Signature: ``ai.onnx@13::Constant``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), _Constant.Inputs( - ), ).get_output_vars( - ).output - - -def constant_of_shape(input: Var, *, value: Optional[np.ndarray] = None, ) -> Var: - r""" -Generate a tensor with given value and shape. - -Parameters -========== -input - Type T1. - 1D tensor. The shape of the expected output tensor. If empty tensor is - given, the output would be a scalar. All values must be >= 0. -value - Attribute. - (Optional) The value of the output elements.Should be a one-element - tensor. If not specified, it defaults to a tensor of value 0 and - datatype float32 - -Returns -======= -output : Var - Type T2. - Output tensor of shape specified by 'input'.If attribute 'value' is - specified, the value and datatype of the output tensor is taken from - 'value'.If attribute 'value' is not specified, the value in the output - defaults to 0, and the datatype defaults to float32. - -Notes -===== -Signature: ``ai.onnx@9::ConstantOfShape``. - -Type constraints: - - T1: `tensor(int64)` - - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), _ConstantOfShape.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def conv(X: Var, W: Var, B: Optional[Var] = None, *, auto_pad: str = "NOTSET", dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: - r""" -The convolution operator consumes an input tensor and a filter, and -computes the output. - -Parameters -========== -X - Type T. - Input data tensor from previous layer; has size (N x C x H x W), where N - is the batch size, C is the number of channels, and H and W are the - height and width. Note that this is for the 2D image. Otherwise the size - is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in - effect, the operation expects input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. -W - Type T. - The weight tensor that will be used in the convolutions; has size (M x - C/group x kH x kW), where C is the number of channels, and kH and kW are - the height and width of the kernel, and M is the number of feature maps. - For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x - k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. - Optionally, if dimension denotation is in effect, the operation expects - the weight tensor to arrive with the dimension denotation of - [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL - ...]. Assuming zero based indices for the shape array, X.shape[1] == - (W.shape[1] \* group) == C and W.shape[0] mod G == 0. Or in other words - FILTER_IN_CHANNEL multiplied by the number of groups should be equal to - DATA_CHANNEL and the number of feature maps M should be a multiple of - the number of groups G. -B - Type T. - Optional 1D bias to be added to the convolution, has size of M. -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. -dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults is 1 along each spatial axis. -group - Attribute. - number of groups input channels and output channels are divided into. -kernel_shape - Attribute. - The shape of the convolution kernel. If not present, should be inferred - from input W. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults is 1 - along each spatial axis. - -Returns -======= -Y : Var - Type T. - Output data tensor that contains the result of the convolution. The - output dimensions are functions of the kernel size, stride size, and pad - lengths. - -Notes -===== -Signature: ``ai.onnx@11::Conv``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Conv( - _Conv.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _Conv.Inputs( - X=unwrap_vars(X), W=unwrap_vars(W), B=unwrap_vars(B), ), ).get_output_vars( - X=get_value(X), W=get_value(W), B=get_value(B), ).Y - - -def conv_integer(x: Var, w: Var, x_zero_point: Optional[Var] = None, w_zero_point: Optional[Var] = None, *, auto_pad: str = "NOTSET", dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: - r""" -The integer convolution operator consumes an input tensor, its -zero-point, a filter, and its zero-point, and computes the output. The -production MUST never overflow. The accumulation may overflow if and -only if in 32 bits. - -Parameters -========== -x - Type T1. - Input data tensor from previous layer; has size (N x C x H x W), where N - is the batch size, C is the number of channels, and H and W are the - height and width. Note that this is for the 2D image. Otherwise the size - is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in - effect, the operation expects input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. -w - Type T2. - The weight tensor that will be used in the convolutions; has size (M x - C/group x kH x kW), where C is the number of channels, and kH and kW are - the height and width of the kernel, and M is the number of feature maps. - For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x - k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. - Optionally, if dimension denotation is in effect, the operation expects - the weight tensor to arrive with the dimension denotation of - [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL - ...]. X.shape[1] == (W.shape[1] \* group) == C (assuming zero based - indices for the shape array). Or in other words FILTER_IN_CHANNEL should - be equal to DATA_CHANNEL. -x_zero_point - Type T1. - Zero point tensor for input 'x'. It's optional and default value is 0. - It's a scalar, which means a per-tensor/layer quantization. -w_zero_point - Type T2. - Zero point tensor for input 'w'. It's optional and default value is 0. - It could be a scalar or a 1-D tensor, which means a per-tensor/layer or - per output channel quantization. If it's a 1-D tensor, its number of - elements should be equal to the number of output channels (M) -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. -dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults to 1 along each axis. -group - Attribute. - number of groups input channels and output channels are divided into. - default is 1. -kernel_shape - Attribute. - The shape of the convolution kernel. If not present, should be inferred - from input 'w'. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0.The value represent the number - of pixels added to the beginning and end part of the corresponding - axis.\ ``pads`` format should be as follow [x1_begin, x2_begin...x1_end, - x2_end,...], where xi_begin the number ofpixels added at the beginning - of axis ``i`` and xi_end, the number of pixels added at the end of axis - ``i``.This attribute cannot be used simultaneously with auto_pad - attribute. If not present, the padding defaultsto 0 along start and end - of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each axis. - -Returns -======= -y : Var - Type T3. - Output data tensor that contains the result of the convolution. The - output dimensions are functions of the kernel size, stride size, and pad - lengths. - -Notes -===== -Signature: ``ai.onnx@10::ConvInteger``. - -Type constraints: - - T1: `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(int32)` - """ - return _ConvInteger( - _ConvInteger.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _ConvInteger.Inputs( - x=unwrap_vars(x), w=unwrap_vars(w), x_zero_point=unwrap_vars(x_zero_point), w_zero_point=unwrap_vars(w_zero_point), ), ).get_output_vars( - x=get_value(x), w=get_value(w), x_zero_point=get_value(x_zero_point), w_zero_point=get_value(w_zero_point), ).y - - -def conv_transpose(X: Var, W: Var, B: Optional[Var] = None, *, auto_pad: str = "NOTSET", dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, output_padding: Optional[Iterable[int]] = None, output_shape: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: - r""" -The convolution transpose operator consumes an input tensor and a -filter, and computes the output. - -If the pads parameter is provided the shape of the output is calculated -via the following equation: - -output_shape[i] = stride[i] \* (input_size[i] - 1) + output_padding[i] + -((kernel_shape[i] - 1) \* dilations[i] + 1) - pads[start_i] - -pads[end_i] - -output_shape can also be explicitly specified in which case pads values -are auto generated using these equations: - -total_padding[i] = stride[i] \* (input_size[i] - 1) + output_padding[i] -+ ((kernel_shape[i] - 1) \* dilations[i] + 1) - output_shape[i] If -(auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; -pads[end_i] = total_padding[i] - (total_padding[i]/2) Else: -pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = -(total_padding[i]/2). - -Parameters -========== -X - Type T. - Input data tensor from previous layer; has size (N x C x H x W), where N - is the batch size, C is the number of channels, and H and W are the - height and width. Note that this is for the 2D image. Otherwise the size - is (N x C x D1 x D2 ... x Dn) -W - Type T. - The weight tensor that will be used in the convolutions; has size (C x - M/group x kH x kW), where C is the number of channels, and kH and kW are - the height and width of the kernel, and M is the number of feature maps. - For more than 2 dimensions, the weight shape will be (C x M/group x k1 x - k2 x ... x kn), where (k1 x k2 x ... x kn) is the dimension of the - kernel. The number of channels in the output should be equal to - W.shape[1] \* group (assuming zero based indices of the shape array) -B - Type T. - Optional 1D bias to be added to the convolution, has size of M. -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = input_shape[i] * strides[i]`` for each axis ``i``. - The padding is split between the two sides equally or almost equally - (depending on whether it is even or odd). In case the padding is an odd - number, the extra padding is added at the end for SAME_UPPER and at the - beginning for SAME_LOWER. -dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults to 1 along each spatial axis. -group - Attribute. - number of groups input channels and output channels are divided into. -kernel_shape - Attribute. - The shape of the convolution kernel. If not present, should be inferred - from input W. -output_padding - Attribute. - Additional elements added to the side with higher coordinate indices in - the output. Each padding value in "output_padding" must be less than the - corresponding stride/dilation dimension. By default, this attribute is a - zero vector. Note that this attribute doesn't directly affect the - computed output values. It only controls the selection of the computed - values, so changing this attribute only adds or removes output elements. - If "output_shape" is explicitly provided, "output_padding" does not - contribute additional size to "output_shape" but participates in the - computation of the needed padding amount. This is also called adjs or - adjustment in some frameworks. -output_shape - Attribute. - The shape of the output can be explicitly set which will cause pads - values to be auto generated. If output_shape is specified pads values - are ignored. See doc for details for equations to generate pads. Note - that the output_shape attribute value should not include dimensions for - batch size and channels, which are automatically inferred. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - -Returns -======= -Y : Var - Type T. - Output data tensor that contains the result of the convolution. The - output dimensions are functions of the kernel size, stride size, pad - lengths and group count. The number of channels in the output should be - equal to W.shape[1] \* group (assuming zero based indices of the shape - array) - -Notes -===== -Signature: ``ai.onnx@11::ConvTranspose``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _ConvTranspose( - _ConvTranspose.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - output_padding=AttrInt64s.maybe(output_padding, name="output_padding"), - output_shape=AttrInt64s.maybe(output_shape, name="output_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _ConvTranspose.Inputs( - X=unwrap_vars(X), W=unwrap_vars(W), B=unwrap_vars(B), ), ).get_output_vars( - X=get_value(X), W=get_value(W), B=get_value(B), ).Y - - -def cos(input: Var, ) -> Var: - r""" -Calculates the cosine of the given input tensor, element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The cosine of the input tensor computed element-wise - -Notes -===== -Signature: ``ai.onnx@7::Cos``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Cos( - _Cos.Attributes( - ), _Cos.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def cosh(input: Var, ) -> Var: - r""" -Calculates the hyperbolic cosine of the given input tensor element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The hyperbolic cosine values of the input tensor computed element-wise - -Notes -===== -Signature: ``ai.onnx@9::Cosh``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Cosh( - _Cosh.Attributes( - ), _Cosh.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def cumsum(x: Var, axis: Var, *, exclusive: int = 0, reverse: int = 0, ) -> Var: - r""" -Performs cumulative sum of the input elements along the given axis. By -default, it will do the sum inclusively meaning the first element is -copied as is. Through an ``exclusive`` attribute, this behavior can -change to exclude the first element. It can also perform summation in -the opposite direction of the axis. For that, set ``reverse`` attribute -to 1. - -Example: - -:: - - input_x = [1, 2, 3] - axis=0 - output = [1, 3, 6] - exclusive=1 - output = [0, 1, 3] - exclusive=0 - reverse=1 - output = [6, 5, 3] - exclusive=1 - reverse=1 - output = [5, 3, 0] - -Parameters -========== -x - Type T. - An input tensor that is to be processed. -axis - Type T2. - A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value - means counting dimensions from the back. -exclusive - Attribute. - If set to 1 will return exclusive sum in which the top element is not - included. In other terms, if set to 1, the j-th output element would be - the sum of the first (j-1) elements. Otherwise, it would be the sum of - the first j elements. -reverse - Attribute. - If set to 1 will perform the sums in reverse direction. - -Returns -======= -y : Var - Type T. - Output tensor of the same type as 'x' with cumulative sums of the x's - elements - -Notes -===== -Signature: ``ai.onnx@14::CumSum``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return _CumSum( - _CumSum.Attributes( - exclusive=AttrInt64(exclusive, name="exclusive"), - reverse=AttrInt64(reverse, name="reverse"), - ), _CumSum.Inputs( - x=unwrap_vars(x), axis=unwrap_vars(axis), ), ).get_output_vars( - x=get_value(x), axis=get_value(axis), ).y - - -def dft(input: Var, dft_length: Optional[Var] = None, *, axis: int = 1, inverse: int = 0, onesided: int = 0, ) -> Var: - r""" -Computes the discrete Fourier transform of input. - -Parameters -========== -input - Type T1. - For real input, the following shape is expected: - [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][1]. For complex - input, the following shape is expected: - [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][2]. The first - dimension is the batch dimension. The following N dimensions correspond - to the signal's dimensions. The final dimension represents the real and - imaginary parts of the value in that order. -dft_length - Type T2. - The length of the signal as a scalar. If greater than the axis - dimension, the signal will be zero-padded up to dft_length. If less than - the axis dimension, only the first dft_length values will be used as the - signal. It's an optional value. -axis - Attribute. - The axis on which to perform the DFT. By default this value is set to 1, - which corresponds to the first dimension after the batch index. Negative - value means counting dimensions from the back. Accepted range is - :math:`[-r, -2] \cup [0, r-2]` where ``r = rank(input)``. The last - dimension is for representing complex numbers and thus is an invalid - axis. -inverse - Attribute. - Whether to perform the inverse discrete fourier transform. By default - this value is set to 0, which corresponds to false. -onesided - Attribute. - If onesided is 1, only values for w in [0, 1, 2, ..., floor(n_fft/2) + - 1] are returned because the real-to-complex Fourier transform satisfies - the conjugate symmetry, i.e., X[m, w] = X[m, n_fft-w]\*. Note if the - input or window tensors are complex, then onesided output is not - possible. Enabling onesided with real inputs performs a Real-valued fast - Fourier transform (RFFT). When invoked with real or complex valued - input, the default value is 0. Values can be 0 or 1. - -Returns -======= -output : Var - Type T1. - The Fourier Transform of the input vector. If onesided is 0, the - following shape is expected: - [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][2]. If axis=1 and - onesided is 1, the following shape is expected: - [batch_idx][floor(signal_dim1/2)+1][signal_dim2]...[signal_dimN][2]. If - axis=2 and onesided is 1, the following shape is expected: - [batch_idx][signal_dim1][floor(signal_dim2/2)+1]...[signal_dimN][2]. If - axis=N and onesided is 1, the following shape is expected: - [batch_idx][signal_dim1][signal_dim2]...[floor(signal_dimN/2)+1][2]. The - signal_dim at the specified axis is equal to the dft_length. - -Notes -===== -Signature: ``ai.onnx@17::DFT``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return _DFT( - _DFT.Attributes( - axis=AttrInt64(axis, name="axis"), - inverse=AttrInt64(inverse, name="inverse"), - onesided=AttrInt64(onesided, name="onesided"), - ), _DFT.Inputs( - input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), ), ).get_output_vars( - input=get_value(input), dft_length=get_value(dft_length), ).output - - -def depth_to_space(input: Var, *, blocksize: int, mode: str = "DCR", ) -> Var: - r""" -DepthToSpace rearranges (permutes) data from depth into blocks of -spatial data. This is the reverse transformation of SpaceToDepth. More -specifically, this op outputs a copy of the input tensor where values -from the depth dimension are moved in spatial blocks to the height and -width dimensions. By default, ``mode`` = ``DCR``. In the DCR mode, -elements along the depth dimension from the input tensor are rearranged -in the following order: depth, column, and then row. The output y is -computed from the input x as below: - -:: - - b, c, h, w = x.shape - tmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w]) - tmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2]) - y = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize]) - -In the CRD mode, elements along the depth dimension from the input -tensor are rearranged in the following order: column, row, and the -depth. The output y is computed from the input x as below: - -:: - - b, c, h, w = x.shape - tmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w]) - tmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3]) - y = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize]) - -Parameters -========== -input - Type T. - Input tensor of [N,C,H,W], where N is the batch axis, C is the channel - or depth, H is the height and W is the width. -blocksize - Attribute. - Blocks of [blocksize, blocksize] are moved. -mode - Attribute. - DCR (default) for depth-column-row order re-arrangement. Use CRD for - column-row-depth order. - -Returns -======= -output : Var - Type T. - Output tensor of [N, C/(blocksize \* blocksize), H \* blocksize, W \* - blocksize]. - -Notes -===== -Signature: ``ai.onnx@13::DepthToSpace``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _DepthToSpace( - _DepthToSpace.Attributes( - blocksize=AttrInt64(blocksize, name="blocksize"), - mode=AttrString(mode, name="mode"), - ), _DepthToSpace.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def dequantize_linear(x: Var, x_scale: Var, x_zero_point: Optional[Var] = None, *, axis: int = 1, ) -> Var: - r""" -The linear dequantization operator. It consumes a quantized tensor, a -scale, and a zero point to compute the full precision tensor. The -dequantization formula is ``y = (x - x_zero_point) * x_scale``. -``x_scale`` and ``x_zero_point`` must have same shape, and can be either -a scalar for per-tensor / per layer quantization, or a 1-D tensor for -per-axis quantization. ``x_zero_point`` and ``x`` must have same type. -``x`` and ``y`` must have same shape. In the case of dequantizing int32, -there's no zero point (zero point is supposed to be 0). - -Parameters -========== -x - Type T. - N-D quantized input tensor to be de-quantized. -x_scale - Type tensor(float). - Scale for input 'x'. It can be a scalar, which means a per-tensor/layer - dequantization, or a 1-D tensor for per-axis dequantization. -x_zero_point - Type T. - Zero point for input 'x'. Shape must match x_scale. It's optional. Zero - point is 0 when it's not specified. -axis - Attribute. - (Optional) The axis of the dequantizing dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - -Returns -======= -y : Var - Type tensor(float). - N-D full precision output tensor. It has same shape as input 'x'. - -Notes -===== -Signature: ``ai.onnx@13::DequantizeLinear``. - -Type constraints: - - T: `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` - """ - return _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _DequantizeLinear.Inputs( - x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), ).get_output_vars( - x=get_value(x), x_scale=get_value(x_scale), x_zero_point=get_value(x_zero_point), ).y - - -def det(X: Var, ) -> Var: - r""" -Det calculates determinant of a square matrix or batches of square -matrices. Det takes one input tensor of shape ``[*, M, M]``, where ``*`` -is zero or more batch dimensions, and the inner-most 2 dimensions form -square matrices. The output is a tensor of shape ``[*]``, containing the -determinants of all input submatrices. e.g., When the input is 2-D, the -output is a scalar(shape is empty: ``[]``). - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@11::Det``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Det( - _Det.Attributes( - ), _Det.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def div(A: Var, B: Var, ) -> Var: - r""" -Performs element-wise binary division (with Numpy-style broadcasting -support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -(Opset 14 change): Extend supported types to include uint8, int8, -uint16, and int16. - -Parameters -========== -A - Type T. - First operand. -B - Type T. - Second operand. - -Returns -======= -C : Var - Type T. - Result, has same element type as two inputs - -Notes -===== -Signature: ``ai.onnx@14::Div``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Div( - _Div.Attributes( - ), _Div.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def dropout(data: Var, ratio: Optional[Var] = None, training_mode: Optional[Var] = None, *, seed: Optional[int] = None, ) -> tuple[Var, Var]: - r""" -Dropout takes an input floating-point tensor, an optional input ratio -(floating-point scalar) and an optional input training_mode (boolean -scalar). It produces two tensor outputs, output (floating-point tensor) -and mask (optional ``Tensor``). If ``training_mode`` is true then -the output Y will be a random dropout; Note that this Dropout scales the -masked input data by the following equation, so to convert the trained -model into inference mode, the user can simply not pass -``training_mode`` input or set it to false. - -:: - - output = scale * data * mask, - -where - -:: - - scale = 1. / (1. - ratio). - -This operator has **optional** inputs/outputs. See `the -doc `__ for more -details about the representation of optional arguments. An empty string -may be used in the place of an actual argument's name to indicate a -missing argument. Trailing optional arguments (those not followed by an -argument that is present) may also be simply omitted. - -Parameters -========== -data - Type T. - The input data as Tensor. -ratio - Type T1. - The ratio of random dropout, with value in [0, 1). If this input was not - set, or if it was set to 0, the output would be a simple copy of the - input. If it's non-zero, output will be a random dropout of the scaled - input, which is typically the case during training. It is an optional - value, if not specified it will default to 0.5. -training_mode - Type T2. - If set to true then it indicates dropout is being used for training. It - is an optional value hence unless specified explicitly, it is false. If - it is false, ratio is ignored and the operation mimics inference mode - where nothing will be dropped from the input data and if mask is - requested as output it will contain all ones. -seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - -Returns -======= -output : Var - Type T. - The output. -mask : Var - Type T2. - The output mask. - -Notes -===== -Signature: ``ai.onnx@13::Dropout``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(bool)` - """ - return _Dropout( - _Dropout.Attributes( - seed=AttrInt64.maybe(seed, name="seed"), - ), _Dropout.Inputs( - data=unwrap_vars(data), ratio=unwrap_vars(ratio), training_mode=unwrap_vars(training_mode), ), ).get_output_vars( - data=get_value(data), ratio=get_value(ratio), training_mode=get_value(training_mode), )._unpack_to_any() - - -def dynamic_quantize_linear(x: Var, ) -> tuple[Var, Var, Var]: - r""" -A Function to fuse calculation for Scale, Zero Point and FP32->8Bit -conversion of FP32 Input data. Outputs Scale, ZeroPoint and Quantized -Input for a given FP32 Input. Scale is calculated as: - -:: - - y_scale = (maximum(0, max(x)) - minimum(0, min(x))) / (qmax - qmin) - -- where qmax and qmin are max and min values for quantization range - i.e. [0, 255] in case of uint8 -- data range is adjusted to include 0. - -Zero point is calculated as: - -:: - - intermediate_zero_point = qmin - min(x)/y_scale - y_zero_point = cast(round(saturate(itermediate_zero_point))) - -- where qmax and qmin are max and min values for quantization range - .i.e [0, 255] in case of uint8 -- for saturation, it saturates to [0, 255] if it's uint8, or [-127, - 127] if it's int8. Right now only uint8 is supported. -- rounding to nearest ties to even. - -Data quantization formula is: - -:: - - y = saturate (round (x / y_scale) + y_zero_point) - -- for saturation, it saturates to [0, 255] if it's uint8, or [-127, - 127] if it's int8. Right now only uint8 is supported. -- rounding to nearest ties to even. - -Parameters -========== -x - Type T1. - Input tensor - -Returns -======= -y : Var - Type T2. - Quantized output tensor -y_scale : Var - Type tensor(float). - Output scale. It's a scalar, which means a per-tensor/layer - quantization. -y_zero_point : Var - Type T2. - Output zero point. It's a scalar, which means a per-tensor/layer - quantization. - -Notes -===== -Signature: ``ai.onnx@11::DynamicQuantizeLinear``. - -Type constraints: - - T1: `tensor(float)` - - T2: `tensor(uint8)` - """ - return _DynamicQuantizeLinear( - _DynamicQuantizeLinear.Attributes( - ), _DynamicQuantizeLinear.Inputs( - x=unwrap_vars(x), ), ).get_output_vars( - x=get_value(x), )._unpack_to_any() - - -def einsum(Inputs: Sequence[Var], *, equation: str, ) -> Var: - r""" -An einsum of the form ``term1, term2 -> output-term`` produces an output -tensor using the following equation - -:: - - output[output-term] = reduce-sum( input1[term1] * input2[term2] ) - -where the reduce-sum performs a summation over all the indices occurring -in the input terms (term1, term2) that do not occur in the output-term. - -The Einsum operator evaluates algebraic tensor operations on a sequence -of tensors, using the Einstein summation convention. The equation string -contains a comma-separated sequence of lower case letters. Each term -corresponds to an operand tensor, and the characters within the terms -correspond to operands dimensions. - -This sequence may be followed by "->" to separate the left and right -hand side of the equation. If the equation contains "->" followed by the -right-hand side, the explicit (not classical) form of the Einstein -summation is performed, and the right-hand side indices indicate output -tensor dimensions. In other cases, output indices are (implicitly) set -to the alphabetically sorted sequence of indices appearing exactly once -in the equation. - -When a dimension character is repeated in the left-hand side, it -represents summation along the dimension. - -The equation may contain ellipsis ("...") to enable broadcasting. -Ellipsis must indicate a fixed number of dimensions. Specifically, every -occurrence of ellipsis in the equation must represent the same number of -dimensions. The right-hand side may contain exactly one ellipsis. In -implicit mode, the ellipsis dimensions are set to the beginning of the -output. The equation string may contain space (U+0020) character. - -Parameters -========== -Inputs - Type T. - Operands -equation - Attribute. - Einsum expression string. - -Returns -======= -Output : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@12::Einsum``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Einsum( - _Einsum.Attributes( - equation=AttrString(equation, name="equation"), - ), _Einsum.Inputs( - Inputs=unwrap_vars(Inputs), ), ).get_output_vars( - Inputs=get_value(Inputs), ).Output - - -def elu(X: Var, *, alpha: float = 1.0, ) -> Var: - r""" -Elu takes one input data (Tensor) and produces one output data -(Tensor) where the function -``f(x) = alpha * (exp(x) - 1.) for x < 0``, ``f(x) = x for x >= 0``., is -applied to the tensor elementwise. - -Parameters -========== -X - Type T. - 1D input tensor -alpha - Attribute. - Coefficient of ELU. - -Returns -======= -Y : Var - Type T. - 1D output tensor - -Notes -===== -Signature: ``ai.onnx@6::Elu``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Elu( - _Elu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), _Elu.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def equal(A: Var, B: Var, ) -> Var: - r""" -Returns the tensor resulted from performing the ``equal`` logical -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. - -Returns -======= -C : Var - Type T1. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@13::Equal``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return _Equal( - _Equal.Attributes( - ), _Equal.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def erf(input: Var, ) -> Var: - r""" -Computes the error function of the given input tensor element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The error function of the input tensor computed element-wise. It has the - same shape and type of the input. - -Notes -===== -Signature: ``ai.onnx@13::Erf``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Erf( - _Erf.Attributes( - ), _Erf.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def exp(input: Var, ) -> Var: - r""" -Calculates the exponential of the given input tensor, element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The exponential of the input tensor computed element-wise - -Notes -===== -Signature: ``ai.onnx@13::Exp``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Exp( - _Exp.Attributes( - ), _Exp.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def expand(input: Var, shape: Var, ) -> Var: - r""" -Broadcast the input tensor following the given shape and the broadcast -rule. The broadcast rule is similar to numpy.array(input) \* -numpy.ones(shape): Dimensions are right alignment; Two corresponding -dimensions must have the same value, or one of them is equal to 1. Also, -this operator is similar to numpy.broadcast_to(input, shape), but the -major difference is numpy.broadcast_to() does not allow shape to be -smaller than input.size(). It is possible that the output.shape is not -equal to shape, when some dimensions in shape is equal to 1, or the -shape.ndim < input.shape.ndim. - -Parameters -========== -input - Type T. - Input tensor -shape - Type tensor(int64). - A 1-D tensor indicates the shape you want to expand to, following the - broadcast rule - -Returns -======= -output : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@13::Expand``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Expand( - _Expand.Attributes( - ), _Expand.Inputs( - input=unwrap_vars(input), shape=unwrap_vars(shape), ), ).get_output_vars( - input=get_value(input), shape=get_value(shape), ).output - - -def eye_like(input: Var, *, dtype: Optional[npt.DTypeLike] = None, k: int = 0, ) -> Var: - r""" -Generate a 2D tensor (matrix) with ones on the diagonal and zeros -everywhere else. Only 2D tensors are supported, i.e. input T1 must be of -rank 2. The shape of the output tensor is the same as the input tensor. -The data type can be specified by the 'dtype' argument. If 'dtype' is -not specified, then the type of input tensor is used. By default, the -main diagonal is populated with ones, but attribute 'k' can be used to -populate upper or lower diagonals. The 'dtype' argument must be one of -the data types specified in the 'DataType' enum field in the TensorProto -message and be valid as an output type. - -Parameters -========== -input - Type T1. - 2D input tensor to copy shape, and optionally, type information from. -dtype - Attribute. - (Optional) The data type for the elements of the output tensor. If not - specified,the data type of the input tensor T1 is used. If input tensor - T1 is also notspecified, then type defaults to 'float'. -k - Attribute. - (Optional) Index of the diagonal to be populated with ones. Default is - 0. If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the - main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a - lower diagonal. - -Returns -======= -output : Var - Type T2. - Output tensor, same shape as input tensor T1. - -Notes -===== -Signature: ``ai.onnx@9::EyeLike``. - -Type constraints: - - T1: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _EyeLike( - _EyeLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - k=AttrInt64(k, name="k"), - ), _EyeLike.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def flatten(input: Var, *, axis: int = 1, ) -> Var: - r""" -Flattens the input tensor into a 2D matrix. If input tensor has shape -(d_0, d_1, ... d_n) then the output will have shape (d_0 X d_1 ... -d\_(axis-1), d_axis X d\_(axis+1) ... X dn). - -Parameters -========== -input - Type T. - A tensor of rank >= axis. -axis - Attribute. - Indicate up to which input dimensions (exclusive) should be flattened to - the outer dimension of the output. The value for axis must be in the - range [-r, r], where r is the rank of the input tensor. Negative value - means counting dimensions from the back. When axis = 0, the shape of the - output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input - tensor is (d_0, d_1, ... d_n). - -Returns -======= -output : Var - Type T. - A 2D tensor with the contents of the input tensor, with input dimensions - up to axis flattened to the outer dimension of the output and remaining - input dimensions flattened into the inner dimension of the output. - -Notes -===== -Signature: ``ai.onnx@13::Flatten``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Flatten( - _Flatten.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _Flatten.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def floor(X: Var, ) -> Var: - r""" -Floor takes one input data (Tensor) and produces one output data -(Tensor) where the floor is, y = floor(x), is applied to the tensor -elementwise. If x is integral, +0, -0, NaN, or infinite, x itself is -returned. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@13::Floor``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Floor( - _Floor.Attributes( - ), _Floor.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def gru(X: Var, W: Var, R: Var, B: Optional[Var] = None, sequence_lens: Optional[Var] = None, initial_h: Optional[Var] = None, *, activation_alpha: Optional[Iterable[float]] = None, activation_beta: Optional[Iterable[float]] = None, activations: Optional[Iterable[str]] = None, clip: Optional[float] = None, direction: str = "forward", hidden_size: Optional[int] = None, layout: int = 0, linear_before_reset: int = 0, ) -> tuple[Var, Var]: - r""" -Computes an one-layer GRU. This operator is usually supported via some -custom implementation such as CuDNN. - -Notations: - -- ``X`` - input tensor -- ``z`` - update gate -- ``r`` - reset gate -- ``h`` - hidden gate -- ``t`` - time step (t-1 means previous time step) -- ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden - gates -- ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden - gates -- ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates -- ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates -- ``WB[zrh]`` - W parameter weight matrix for backward update, reset, - and hidden gates -- ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, - and hidden gates -- ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden - gates -- ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden - gates -- ``H`` - Hidden state -- ``num_directions`` - 2 if direction == bidirectional else 1 - -Activation functions: - -- Relu(x) - max(0, x) -- Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) -- Sigmoid(x) - 1/(1 + e^{-x}) - -NOTE: Below are optional - -- Affine(x) - alpha \* x + beta -- LeakyRelu(x) - x if x >= 0 else alpha \* x -- ThresholdedRelu(x) - x if x >= alpha else 0 -- ScaledTanh(x) - alpha \* Tanh(beta \* x) -- HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) -- Elu(x) - x if x >= 0 else alpha \* (e^x - 1) -- Softsign(x) - x/(1 + \|x\|) -- Softplus(x) - log(1 + e^x) - -Equations (Default: f=Sigmoid, g=Tanh): - -- zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) -- rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) -- ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when - linear_before_reset = 0 -- ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when - linear_before_reset != 0 -- Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** - inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. - -Parameters -========== -X - Type T. - The input sequences packed (and potentially padded) into one 3-D tensor - with the shape of ``[seq_length, batch_size, input_size]``. -W - Type T. - The weight tensor for the gates. Concatenation of ``W[zrh]`` and - ``WB[zrh]`` (if bidirectional) along dimension 0. This tensor has shape - ``[num_directions, 3*hidden_size, input_size]``. -R - Type T. - The recurrence weight tensor. Concatenation of ``R[zrh]`` and - ``RB[zrh]`` (if bidirectional) along dimension 0. This tensor has shape - ``[num_directions, 3*hidden_size, hidden_size]``. -B - Type T. - The bias tensor for the gates. Concatenation of ``[Wb[zrh], Rb[zrh]]`` - and ``[WBb[zrh], RBb[zrh]]`` (if bidirectional) along dimension 0. This - tensor has shape ``[num_directions, 6*hidden_size]``. Optional: If not - specified - assumed to be 0 -sequence_lens - Type T1. - Optional tensor specifying lengths of the sequences in a batch. If not - specified - assumed all sequences in the batch to have length - ``seq_length``. It has shape ``[batch_size]``. -initial_h - Type T. - Optional initial value of the hidden. If not specified - assumed to be - 0. It has shape ``[num_directions, batch_size, hidden_size]``. -activation_alpha - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX - operators.For example with LeakyRelu, the default alpha is 0.01. -activation_beta - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX operators. -activations - Attribute. - A list of 2 (or 4 if bidirectional) activation functions for update, - reset, and hidden gates. The activation functions must be one of the - activation functions specified above. Optional: See the equations for - default if not specified. -clip - Attribute. - Cell clip threshold. Clipping bounds the elements of a tensor in the - range of [-threshold, +threshold] and is applied to the input of - activations. No clip if not specified. -direction - Attribute. - Specify if the RNN is forward, reverse, or bidirectional. Must be one of - forward (default), reverse, or bidirectional. -hidden_size - Attribute. - Number of neurons in the hidden layer -layout - Attribute. - The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the - following shapes are expected: X.shape = [seq_length, batch_size, - input_size], Y.shape = [seq_length, num_directions, batch_size, - hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, - hidden_size]. If 1, the following shapes are expected: X.shape = - [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, - num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, - num_directions, hidden_size]. -linear_before_reset - Attribute. - When computing the output of the hidden gate, apply the linear - transformation before multiplying by the output of the reset gate. - -Returns -======= -Y : Var - Type T. - A tensor that concats all the intermediate output values of the hidden. - It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. -Y_h : Var - Type T. - The last output value of the hidden. It has shape - ``[num_directions, batch_size, hidden_size]``. - -Notes -===== -Signature: ``ai.onnx@14::GRU``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(int32)` - """ - return _GRU( - _GRU.Attributes( - activation_alpha=AttrFloat32s.maybe(activation_alpha, name="activation_alpha"), - activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), - activations=AttrStrings.maybe(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - layout=AttrInt64(layout, name="layout"), - linear_before_reset=AttrInt64(linear_before_reset, name="linear_before_reset"), - ), _GRU.Inputs( - X=unwrap_vars(X), W=unwrap_vars(W), R=unwrap_vars(R), B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), ), ).get_output_vars( - X=get_value(X), W=get_value(W), R=get_value(R), B=get_value(B), sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), )._unpack_to_any() - - -def gather(data: Var, indices: Var, *, axis: int = 0, ) -> Var: - r""" -Given ``data`` tensor of rank r >= 1, and ``indices`` tensor of rank q, -gather entries of the axis dimension of ``data`` (by default outer-most -one as axis=0) indexed by ``indices``, and concatenates them in an -output tensor of rank q + (r - 1). - -If ``axis = 0``, let ``k = indices[i_{0}, ..., i_{q-1}]`` then -``output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]``: - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - indices = [ - [0, 1], - [1, 2], - ] - output = [ - [ - [1.0, 1.2], - [2.3, 3.4], - ], - [ - [2.3, 3.4], - [4.5, 5.7], - ], - ] - -If ``axis = 1``, let ``k = indices[i_{0}, ..., i_{q-1}]`` then -``output[j_{0}, i_{0}, ..., i_{q-1}, j_{1}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]``: - -:: - - data = [ - [1.0, 1.2, 1.9], - [2.3, 3.4, 3.9], - [4.5, 5.7, 5.9], - ] - indices = [ - [0, 2], - ] - axis = 1, - output = [ - [[1.0, 1.9]], - [[2.3, 3.9]], - [[4.5, 5.9]], - ] - -Parameters -========== -data - Type T. - Tensor of rank r >= 1. -indices - Type Tind. - Tensor of int32/int64 indices, of any rank q. All index values are - expected to be within bounds [-s, s-1] along axis of size s. It is an - error if any of the index values are out of bounds. -axis - Attribute. - Which axis to gather on. Negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(data). - -Returns -======= -output : Var - Type T. - Tensor of rank q + (r - 1). - -Notes -===== -Signature: ``ai.onnx@13::Gather``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return _Gather( - _Gather.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _Gather.Inputs( - data=unwrap_vars(data), indices=unwrap_vars(indices), ), ).get_output_vars( - data=get_value(data), indices=get_value(indices), ).output - - -def gather_elements(data: Var, indices: Var, *, axis: int = 0, ) -> Var: - r""" -GatherElements takes two inputs ``data`` and ``indices`` of the same -rank r >= 1 and an optional attribute ``axis`` that identifies an axis -of ``data`` (by default, the outer-most axis, that is axis 0). It is an -indexing operation that produces its output by indexing into the input -data tensor at index positions determined by elements of the ``indices`` -tensor. Its output shape is the same as the shape of ``indices`` and -consists of one value (gathered from the ``data``) for each element in -``indices``. - -For instance, in the 3-D case (r = 3), the output produced is determined -by the following equations: - -:: - - out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0, - out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1, - out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2, - -This operator is also the inverse of ScatterElements. It is similar to -Torch's gather operation. - -Example 1: - -:: - - data = [ - [1, 2], - [3, 4], - ] - indices = [ - [0, 0], - [1, 0], - ] - axis = 1 - output = [ - [1, 1], - [4, 3], - ] - -Example 2: - -:: - - data = [ - [1, 2, 3], - [4, 5, 6], - [7, 8, 9], - ] - indices = [ - [1, 2, 0], - [2, 0, 0], - ] - axis = 0 - output = [ - [4, 8, 3], - [7, 2, 3], - ] - -Parameters -========== -data - Type T. - Tensor of rank r >= 1. -indices - Type Tind. - Tensor of int32/int64 indices, with the same rank r as the input. All - index values are expected to be within bounds [-s, s-1] along axis of - size s. It is an error if any of the index values are out of bounds. -axis - Attribute. - Which axis to gather on. Negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(data). - -Returns -======= -output : Var - Type T. - Tensor of the same shape as indices. - -Notes -===== -Signature: ``ai.onnx@13::GatherElements``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return _GatherElements( - _GatherElements.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _GatherElements.Inputs( - data=unwrap_vars(data), indices=unwrap_vars(indices), ), ).get_output_vars( - data=get_value(data), indices=get_value(indices), ).output - - -def gather_nd(data: Var, indices: Var, *, batch_dims: int = 0, ) -> Var: - r""" -Given ``data`` tensor of rank ``r`` >= 1, ``indices`` tensor of rank -``q`` >= 1, and ``batch_dims`` integer ``b``, this operator gathers -slices of ``data`` into an output tensor of rank -``q + r - indices_shape[-1] - 1 - b``. - -``indices`` is an q-dimensional integer tensor, best thought of as a -``(q-1)``-dimensional tensor of index-tuples into ``data``, where each -element defines a slice of ``data`` - -``batch_dims`` (denoted as ``b``) is an integer indicating the number of -batch dimensions, i.e the leading ``b`` number of dimensions of ``data`` -tensor and ``indices`` are representing the batches, and the gather -starts from the ``b+1`` dimension. - -Some salient points about the inputs' rank and shape: - -1) r >= 1 and q >= 1 are to be honored. There is no dependency condition - to be met between ranks ``r`` and ``q`` - -2) The first ``b`` dimensions of the shape of ``indices`` tensor and - ``data`` tensor must be equal. - -3) b < min(q, r) is to be honored. - -4) The ``indices_shape[-1]`` should have a value between 1 (inclusive) - and rank ``r-b`` (inclusive) - -5) All values in ``indices`` are expected to be within bounds [-s, s-1] - along axis of size ``s`` (i.e.) - ``-data_shape[i] <= indices[...,i] <= data_shape[i] - 1``. It is an - error if any of the index values are out of bounds. - -The output is computed as follows: - -The output tensor is obtained by mapping each index-tuple in the -``indices`` tensor to the corresponding slice of the input ``data``. - -1) If ``indices_shape[-1] > r-b`` => error condition - -2) If ``indices_shape[-1] == r-b``, since the rank of ``indices`` is - ``q``, ``indices`` can be thought of as ``N`` ``(q-b-1)``-dimensional - tensors containing 1-D tensors of dimension ``r-b``, where ``N`` is - an integer equals to the product of 1 and all the elements in the - batch dimensions of the indices_shape. Let us think of each such - ``r-b`` ranked tensor as ``indices_slice``. Each *scalar value* - corresponding to ``data[0:b-1,indices_slice]`` is filled into the - corresponding location of the ``(q-b-1)``-dimensional tensor to form - the ``output`` tensor (Example 1 below) - -3) If ``indices_shape[-1] < r-b``, since the rank of ``indices`` is - ``q``, ``indices`` can be thought of as ``N`` ``(q-b-1)``-dimensional - tensor containing 1-D tensors of dimension ``< r-b``. Let us think of - each such tensors as ``indices_slice``. Each *tensor slice* - corresponding to ``data[0:b-1, indices_slice , :]`` is filled into - the corresponding location of the ``(q-b-1)``-dimensional tensor to - form the ``output`` tensor (Examples 2, 3, 4 and 5 below) - -This operator is the inverse of ``ScatterND``. - -**Example 1** - -:: - - batch_dims = 0 - data = [[0,1],[2,3]] # data_shape = [2, 2] - indices = [[0,0],[1,1]] # indices_shape = [2, 2] - output = [0,3] # output_shape = [2] - -**Example 2** - -:: - - batch_dims = 0 - data = [[0,1],[2,3]] # data_shape = [2, 2] - indices = [[1],[0]] # indices_shape = [2, 1] - output = [[2,3],[0,1]] # output_shape = [2, 2] - -**Example 3** - -:: - - batch_dims = 0 - data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] - indices = [[0,1],[1,0]] # indices_shape = [2, 2] - output = [[2,3],[4,5]] # output_shape = [2, 2] - -**Example 4** - -:: - - batch_dims = 0 - data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] - indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2] - output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2] - -**Example 5** - -:: - - batch_dims = 1 - data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] - indices = [[1],[0]] # indices_shape = [2, 1] - output = [[2,3],[4,5]] # output_shape = [2, 2] - -Parameters -========== -data - Type T. - Tensor of rank r >= 1. -indices - Type tensor(int64). - Tensor of rank q >= 1. All index values are expected to be within bounds - [-s, s-1] along axis of size s. It is an error if any of the index - values are out of bounds. -batch_dims - Attribute. - The number of batch dimensions. The gather of indexing starts from - dimension of data[batch_dims:] - -Returns -======= -output : Var - Type T. - Tensor of rank q + r - indices_shape[-1] - 1. - -Notes -===== -Signature: ``ai.onnx@13::GatherND``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _GatherND( - _GatherND.Attributes( - batch_dims=AttrInt64(batch_dims, name="batch_dims"), - ), _GatherND.Inputs( - data=unwrap_vars(data), indices=unwrap_vars(indices), ), ).get_output_vars( - data=get_value(data), indices=get_value(indices), ).output - - -def gemm(A: Var, B: Var, C: Optional[Var] = None, *, alpha: float = 1.0, beta: float = 1.0, transA: int = 0, transB: int = 0, ) -> Var: - r""" -General Matrix multiplication: -https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 - -- A' = transpose(A) if transA else A -- B' = transpose(B) if transB else B - -Compute Y = alpha \* A' \* B' + beta \* C, where input tensor A has -shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input -tensor C is broadcastable to shape (M, N), and output tensor Y has shape -(M, N). A will be transposed before doing the computation if attribute -transA is non-zero, same for B and transB. This operator supports -**unidirectional broadcasting** (tensor C should be unidirectional -broadcastable to tensor A \* B); for more details please check `the -doc `__. -This operator has **optional** inputs/outputs. See `the -doc `__ for more -details about the representation of optional arguments. An empty string -may be used in the place of an actual argument's name to indicate a -missing argument. Trailing optional arguments (those not followed by an -argument that is present) may also be simply omitted. - -Parameters -========== -A - Type T. - Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, - M) if transA is non-zero. -B - Type T. - Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, - K) if transB is non-zero. -C - Type T. - Optional input tensor C. If not specified, the computation is done as if - C is a scalar 0. The shape of C should be unidirectional broadcastable - to (M, N). -alpha - Attribute. - Scalar multiplier for the product of input tensors A \* B. -beta - Attribute. - Scalar multiplier for input tensor C. -transA - Attribute. - Whether A should be transposed -transB - Attribute. - Whether B should be transposed - -Returns -======= -Y : Var - Type T. - Output tensor of shape (M, N). - -Notes -===== -Signature: ``ai.onnx@13::Gemm``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _Gemm( - _Gemm.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - transA=AttrInt64(transA, name="transA"), - transB=AttrInt64(transB, name="transB"), - ), _Gemm.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), C=unwrap_vars(C), ), ).get_output_vars( - A=get_value(A), B=get_value(B), C=get_value(C), ).Y - - -def global_average_pool(X: Var, ) -> Var: - r""" -GlobalAveragePool consumes an input tensor X and applies average pooling -across the values in the same channel. This is equivalent to AveragePool -with kernel size equal to the spatial dimension of input tensor. - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. - -Returns -======= -Y : Var - Type T. - Output data tensor from pooling across the input tensor. The output - tensor has the same rank as the input. The first two dimensions of - output shape are the same as the input (N x C), while the other - dimensions are all 1. - -Notes -===== -Signature: ``ai.onnx@1::GlobalAveragePool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _GlobalAveragePool( - _GlobalAveragePool.Attributes( - ), _GlobalAveragePool.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def global_lp_pool(X: Var, *, p: int = 2, ) -> Var: - r""" -GlobalLpPool consumes an input tensor X and applies lp pool pooling -across the values in the same channel. This is equivalent to LpPool with -kernel size equal to the spatial dimension of input tensor. - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. -p - Attribute. - p value of the Lp norm used to pool over the input data. - -Returns -======= -Y : Var - Type T. - Output data tensor from pooling across the input tensor. The output - tensor has the same rank as the input. The first two dimensions of - output shape are the same as the input (N x C), while the other - dimensions are all 1. - -Notes -===== -Signature: ``ai.onnx@2::GlobalLpPool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _GlobalLpPool( - _GlobalLpPool.Attributes( - p=AttrInt64(p, name="p"), - ), _GlobalLpPool.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def global_max_pool(X: Var, ) -> Var: - r""" -GlobalMaxPool consumes an input tensor X and applies max pooling across -the values in the same channel. This is equivalent to MaxPool with -kernel size equal to the spatial dimension of input tensor. - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. - -Returns -======= -Y : Var - Type T. - Output data tensor from pooling across the input tensor. The output - tensor has the same rank as the input. The first two dimensions of - output shape are the same as the input (N x C), while the other - dimensions are all 1. - -Notes -===== -Signature: ``ai.onnx@1::GlobalMaxPool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _GlobalMaxPool( - _GlobalMaxPool.Attributes( - ), _GlobalMaxPool.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def greater(A: Var, B: Var, ) -> Var: - r""" -Returns the tensor resulted from performing the ``greater`` logical -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. - -Returns -======= -C : Var - Type T1. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@13::Greater``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return _Greater( - _Greater.Attributes( - ), _Greater.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def greater_or_equal(A: Var, B: Var, ) -> Var: - r""" -Returns the tensor resulted from performing the ``greater_equal`` -logical operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. - -Returns -======= -C : Var - Type T1. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@16::GreaterOrEqual``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return _GreaterOrEqual( - _GreaterOrEqual.Attributes( - ), _GreaterOrEqual.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def grid_sample(X: Var, grid: Var, *, align_corners: int = 0, mode: str = "bilinear", padding_mode: str = "zeros", ) -> Var: - r""" -Given an input ``X`` and a flow-field ``grid``, computes the output -``Y`` using ``X`` values and pixel locations from ``grid``. Currently, -only spatial (4-D) inputs are supported. For input ``X`` with shape (N, -C, H, W) and ``grid`` with shape (N, H_out, W_out, 2), the output ``Y`` -will have shape (N, C, H_out, W_out). - -The tensor ``X`` contains values at centers of square pixels in a H by W -2-dimensional image. The tensor ``grid`` describes normalized positions -where the output ``Y`` is to be computed using a specified interpolation -method (the mode) and a padding mode (for grid positions falling outside -the 2-dimensional image). - -Elements in ``grid[N, H_out, W_out]`` are size-2 vectors specifying -positions in the 2-dimensional space of ``X``. They are used to -interpolate output values of ``Y[N, C, H_out, W_out]``. - -The GridSample operator is often used in doing grid generator and -sampler in the `Spatial Transformer -Networks `__. See also in -`torch.nn.functional.grid_sample `__. - -Parameters -========== -X - Type T1. - 4-D tensor of shape (N, C, H, W), where N is the batch size, C is the - numbers of channels, H and W are the height and width of the input data. -grid - Type T2. - Input offset, 4-D tensor of shape (N, H_out, W_out, 2), where H_out and - W_out are the height and width of grid and output, Grid specifies the - sampling pixel locations normalized by the input spatial dimensions. - Therefore, it should have most values in the range of [-1, 1]. If grid - has values outside the range of [-1, 1], the corresponding outputs will - be handled as defined by padding_mode. -align_corners - Attribute. - If align_corners=1, the extrema (-1 and 1) are considered as referring - to the center points of the input's corner pixels. If align_corners=0, - they are instead considered as referring to the corner points of the - input's corner pixels, making the sampling more resolution agnostic. -mode - Attribute. - Three interpolation modes: bilinear (default), nearest and bicubic. -padding_mode - Attribute. - Support padding modes for outside grid values: ``zeros``\ (default), - ``border``, ``reflection``. zeros: use 0 for out-of-bound grid - locations, border: use border values for out-of-bound grid locations, - reflection: use values at locations reflected by the border for - out-of-bound grid locations. If index 0 represents the margin pixel, the - reflected value at index -1 will be the same as the value at index 1. - For location far away from the border, it will keep being reflected - until becoming in bound. If pixel location x = -3.5 reflects by border - -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = - 0.5. - -Returns -======= -Y : Var - Type T1. - 4-D tensor of shape (N, C, H_out, W_out) of sampled values. For integer - input types, intermediate values are computed as floating point and cast - to integer at the end. - -Notes -===== -Signature: ``ai.onnx@16::GridSample``. - -Type constraints: - - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _GridSample( - _GridSample.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - mode=AttrString(mode, name="mode"), - padding_mode=AttrString(padding_mode, name="padding_mode"), - ), _GridSample.Inputs( - X=unwrap_vars(X), grid=unwrap_vars(grid), ), ).get_output_vars( - X=get_value(X), grid=get_value(grid), ).Y - - -def hamming_window(size: Var, *, output_datatype: int = 1, periodic: int = 1, ) -> Var: - r""" -Generates a Hamming window as described in the paper -https://ieeexplore.ieee.org/document/1455106. - -Parameters -========== -size - Type T1. - A scalar value indicating the length of the window. -output_datatype - Attribute. - The data type of the output tensor. Strictly must be one of the values - from DataType enum in TensorProto whose values correspond to T2. The - default value is 1 = FLOAT. -periodic - Attribute. - If 1, returns a window to be used as periodic function. If 0, return a - symmetric window. When 'periodic' is specified, hann computes a window - of length size + 1 and returns the first size points. The default value - is 1. - -Returns -======= -output : Var - Type T2. - A Hamming window with length: size. The output has the shape: [size]. - -Notes -===== -Signature: ``ai.onnx@17::HammingWindow``. - -Type constraints: - - T1: `tensor(int32)`, `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _HammingWindow( - _HammingWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), _HammingWindow.Inputs( - size=unwrap_vars(size), ), ).get_output_vars( - size=get_value(size), ).output - - -def hann_window(size: Var, *, output_datatype: int = 1, periodic: int = 1, ) -> Var: - r""" -Generates a Hann window as described in the paper -https://ieeexplore.ieee.org/document/1455106. - -Parameters -========== -size - Type T1. - A scalar value indicating the length of the window. -output_datatype - Attribute. - The data type of the output tensor. Strictly must be one of the values - from DataType enum in TensorProto whose values correspond to T2. The - default value is 1 = FLOAT. -periodic - Attribute. - If 1, returns a window to be used as periodic function. If 0, return a - symmetric window. When 'periodic' is specified, hann computes a window - of length size + 1 and returns the first size points. The default value - is 1. - -Returns -======= -output : Var - Type T2. - A Hann window with length: size. The output has the shape: [size]. - -Notes -===== -Signature: ``ai.onnx@17::HannWindow``. - -Type constraints: - - T1: `tensor(int32)`, `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _HannWindow( - _HannWindow.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - periodic=AttrInt64(periodic, name="periodic"), - ), _HannWindow.Inputs( - size=unwrap_vars(size), ), ).get_output_vars( - size=get_value(size), ).output - - -def hard_sigmoid(X: Var, *, alpha: float = 0.20000000298023224, beta: float = 0.5, ) -> Var: - r""" -HardSigmoid takes one input data (Tensor) and produces one output -data (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha -\* x + beta)), is applied to the tensor elementwise. - -Parameters -========== -X - Type T. - Input tensor -alpha - Attribute. - Value of alpha. -beta - Attribute. - Value of beta. - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@6::HardSigmoid``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _HardSigmoid( - _HardSigmoid.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - ), _HardSigmoid.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def hard_swish(X: Var, ) -> Var: - r""" -HardSwish takes one input data (Tensor) and produces one output data -(Tensor) where the HardSwish function, y = x \* max(0, min(1, alpha -\* x + beta)) = x \* HardSigmoid(x), where alpha = 1/6 and -beta = 0.5, is applied to the tensor elementwise. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@14::HardSwish``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _HardSwish( - _HardSwish.Attributes( - ), _HardSwish.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def hardmax(input: Var, *, axis: int = -1, ) -> Var: - r""" -The operator computes the hardmax values for the given input: - -Hardmax(element in input, axis) = 1 if the element is the first maximum -value along the specified axis, 0 otherwise - -The "axis" attribute indicates the dimension along which Hardmax will be -performed. The output tensor has the same shape and contains the Hardmax -values of the corresponding input. - -Parameters -========== -input - Type T. - The input tensor of rank >= axis. -axis - Attribute. - Describes the dimension Hardmax will be performed on. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(input). - -Returns -======= -output : Var - Type T. - The output values with the same shape as the input tensor. - -Notes -===== -Signature: ``ai.onnx@13::Hardmax``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Hardmax( - _Hardmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _Hardmax.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def identity(input: Var, ) -> Var: - r""" -Identity operator - -Parameters -========== -input - Type V. - Input tensor - -Returns -======= -output : Var - Type V. - Tensor to copy input into. - -Notes -===== -Signature: ``ai.onnx@16::Identity``. - -Type constraints: - - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Identity( - _Identity.Attributes( - ), _Identity.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def if_(cond: Var, *, else_branch: Callable[[], Iterable[Var]], then_branch: Callable[[], Iterable[Var]], ) -> Sequence[Var]: - r""" -If conditional - -Parameters -========== -cond - Type B. - Condition for the if. The tensor must contain a single element. -else_branch - Attribute. - Graph to run if condition is false. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the then_branch. -then_branch - Attribute. - Graph to run if condition is true. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the else_branch. - -Returns -======= -outputs : Sequence[Var] - Type V. - Values that are live-out to the enclosing scope. The return values in - the ``then_branch`` and ``else_branch`` must be of the same data type. - The ``then_branch`` and ``else_branch`` may produce tensors with the - same element type and different shapes. If corresponding outputs from - the then-branch and the else-branch have static shapes S1 and S2, then - the shape of the corresponding output variable of the if-node (if - present) must be compatible with both S1 and S2 as it represents the - union of both possible shapes.For example, if in a model file, the first - output of ``then_branch`` is typed float tensor with shape [2] and the - first output of ``else_branch`` is another float tensor with shape [3], - If's first output should have (a) no shape set, or (b) a shape of rank 1 - with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank - 1 with a unique ``dim_param``. In contrast, the first output cannot have - the shape [2] since [2] and [3] are not compatible. - -Notes -===== -Signature: ``ai.onnx@16::If``. - -Type constraints: - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _else_branch_subgraph: Graph = subgraph( - (), - else_branch - ) - _then_branch_subgraph: Graph = subgraph( - (), - then_branch - ) - return _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), _If.Inputs( - cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), ).get_output_vars( - cond=get_value(cond), ).outputs - - -def instance_normalization(input: Var, scale: Var, B: Var, *, epsilon: float = 9.999999747378752e-06, ) -> Var: - r""" -Carries out instance normalization as described in the paper -https://arxiv.org/abs/1607.08022. - -y = scale \* (x - mean) / sqrt(variance + epsilon) + B, where mean and -variance are computed per instance per channel. - -Parameters -========== -input - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. -scale - Type T. - The input 1-dimensional scale tensor of size C. -B - Type T. - The input 1-dimensional bias tensor of size C. -epsilon - Attribute. - The epsilon value to use to avoid division by zero. - -Returns -======= -output : Var - Type T. - The output tensor of the same shape as input. - -Notes -===== -Signature: ``ai.onnx@6::InstanceNormalization``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _InstanceNormalization( - _InstanceNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - ), _InstanceNormalization.Inputs( - input=unwrap_vars(input), scale=unwrap_vars(scale), B=unwrap_vars(B), ), ).get_output_vars( - input=get_value(input), scale=get_value(scale), B=get_value(B), ).output - - -def isinf(X: Var, *, detect_negative: int = 1, detect_positive: int = 1, ) -> Var: - r""" -Map infinity to true and other values to false. - -Parameters -========== -X - Type T1. - input -detect_negative - Attribute. - (Optional) Whether map negative infinity to true. Default to 1 so that - negative infinity induces true. Set this attribute to 0 if negative - infinity should be mapped to false. -detect_positive - Attribute. - (Optional) Whether map positive infinity to true. Default to 1 so that - positive infinity induces true. Set this attribute to 0 if positive - infinity should be mapped to false. - -Returns -======= -Y : Var - Type T2. - output - -Notes -===== -Signature: ``ai.onnx@10::IsInf``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)` - - T2: `tensor(bool)` - """ - return _IsInf( - _IsInf.Attributes( - detect_negative=AttrInt64(detect_negative, name="detect_negative"), - detect_positive=AttrInt64(detect_positive, name="detect_positive"), - ), _IsInf.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def isnan(X: Var, ) -> Var: - r""" -Returns which elements of the input are NaN. - -Parameters -========== -X - Type T1. - input + Notes + ===== + Signature: ``ai.onnx@9::Asinh``. -Returns -======= -Y : Var - Type T2. - output - -Notes -===== -Signature: ``ai.onnx@13::IsNaN``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(bool)` - """ - return _IsNaN( - _IsNaN.Attributes( - ), _IsNaN.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def lrn(X: Var, *, alpha: float = 9.999999747378752e-05, beta: float = 0.75, bias: float = 1.0, size: int, ) -> Var: - r""" -Local Response Normalization proposed in the `AlexNet -paper `__. -It normalizes over local input regions. The local region is defined -across the channels. For an element ``X[n, c, d1, ..., dk]`` in a tensor -of shape ``(N x C x D1 x D2, ..., Dk)``, its region is -``{X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}``. - -``square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2)``, where -``max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))``. - -``Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta`` - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. Optionally, if dimension denotation is in - effect, the operation expects the input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. -alpha - Attribute. - Scaling parameter. -beta - Attribute. - The exponent. -bias - Attribute. - -size - Attribute. - The number of channels to sum over - -Returns -======= -Y : Var - Type T. - Output tensor, which has the shape and type as input tensor - -Notes -===== -Signature: ``ai.onnx@13::LRN``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _LRN( - _LRN.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - beta=AttrFloat32(beta, name="beta"), - bias=AttrFloat32(bias, name="bias"), - size=AttrInt64(size, name="size"), - ), _LRN.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def lstm(X: Var, W: Var, R: Var, B: Optional[Var] = None, sequence_lens: Optional[Var] = None, initial_h: Optional[Var] = None, initial_c: Optional[Var] = None, P: Optional[Var] = None, *, activation_alpha: Optional[Iterable[float]] = None, activation_beta: Optional[Iterable[float]] = None, activations: Optional[Iterable[str]] = None, clip: Optional[float] = None, direction: str = "forward", hidden_size: Optional[int] = None, input_forget: int = 0, layout: int = 0, ) -> tuple[Var, Var, Var]: - r""" -Computes an one-layer LSTM. This operator is usually supported via some -custom implementation such as CuDNN. - -Notations: - -- ``X`` - input tensor -- ``i`` - input gate -- ``o`` - output gate -- ``f`` - forget gate -- ``c`` - cell gate -- ``t`` - time step (t-1 means previous time step) -- ``W[iofc]`` - W parameter weight matrix for input, output, forget, - and cell gates -- ``R[iofc]`` - R recurrence weight matrix for input, output, forget, - and cell gates -- ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell - gates -- ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell - gates -- ``P[iof]`` - P peephole weight vector for input, output, and forget - gates -- ``WB[iofc]`` - W parameter weight matrix for backward input, output, - forget, and cell gates -- ``RB[iofc]`` - R recurrence weight matrix for backward input, output, - forget, and cell gates -- ``WBb[iofc]`` - W bias vectors for backward input, output, forget, - and cell gates -- ``RBb[iofc]`` - R bias vectors for backward input, output, forget, - and cell gates -- ``PB[iof]`` - P peephole weight vector for backward input, output, - and forget gates -- ``H`` - Hidden state -- ``num_directions`` - 2 if direction == bidirectional else 1 - -Activation functions: - -- Relu(x) - max(0, x) -- Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) -- Sigmoid(x) - 1/(1 + e^{-x}) - -NOTE: Below are optional - -- Affine(x) - alpha*x + beta -- LeakyRelu(x) - x if x >= 0 else alpha \* x -- ThresholdedRelu(x) - x if x >= alpha else 0 -- ScaledTanh(x) - alpha\ *Tanh(beta*\ x) -- HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) -- Elu(x) - x if x >= 0 else alpha*(e^x - 1) -- Softsign(x) - x/(1 + \|x\|) -- Softplus(x) - log(1 + e^x) - -Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): - -- it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) -- ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) -- ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) -- Ct = ft (.) Ct-1 + it (.) ct -- ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) -- Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See - `the doc `__ for - more details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. - -Parameters -========== -X - Type T. - The input sequences packed (and potentially padded) into one 3-D tensor - with the shape of ``[seq_length, batch_size, input_size]``. -W - Type T. - The weight tensor for the gates. Concatenation of ``W[iofc]`` and - ``WB[iofc]`` (if bidirectional) along dimension 0. The tensor has shape - ``[num_directions, 4*hidden_size, input_size]``. -R - Type T. - The recurrence weight tensor. Concatenation of ``R[iofc]`` and - ``RB[iofc]`` (if bidirectional) along dimension 0. This tensor has shape - ``[num_directions, 4*hidden_size, hidden_size]``. -B - Type T. - The bias tensor for input gate. Concatenation of - ``[Wb[iofc], Rb[iofc]]``, and ``[WBb[iofc], RBb[iofc]]`` (if - bidirectional) along dimension 0. This tensor has shape - ``[num_directions, 8*hidden_size]``. Optional: If not specified - - assumed to be 0. -sequence_lens - Type T1. - Optional tensor specifying lengths of the sequences in a batch. If not - specified - assumed all sequences in the batch to have length - ``seq_length``. It has shape ``[batch_size]``. -initial_h - Type T. - Optional initial value of the hidden. If not specified - assumed to be - 0. It has shape ``[num_directions, batch_size, hidden_size]``. -initial_c - Type T. - Optional initial value of the cell. If not specified - assumed to be 0. - It has shape ``[num_directions, batch_size, hidden_size]``. -P - Type T. - The weight tensor for peepholes. Concatenation of ``P[iof]`` and - ``PB[iof]`` (if bidirectional) along dimension 0. It has shape - ``[num_directions, 3*hidde_size]``. Optional: If not specified - assumed - to be 0. -activation_alpha - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX - operators.For example with LeakyRelu, the default alpha is 0.01. -activation_beta - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX operators. -activations - Attribute. - A list of 3 (or 6 if bidirectional) activation functions for input, - output, forget, cell, and hidden. The activation functions must be one - of the activation functions specified above. Optional: See the equations - for default if not specified. -clip - Attribute. - Cell clip threshold. Clipping bounds the elements of a tensor in the - range of [-threshold, +threshold] and is applied to the input of - activations. No clip if not specified. -direction - Attribute. - Specify if the RNN is forward, reverse, or bidirectional. Must be one of - forward (default), reverse, or bidirectional. -hidden_size - Attribute. - Number of neurons in the hidden layer -input_forget - Attribute. - Couple the input and forget gates if 1. -layout - Attribute. - The shape format of inputs X, initial_h, initial_c and outputs Y, Y_h, - Y_c. If 0, the following shapes are expected: X.shape = [seq_length, - batch_size, input_size], Y.shape = [seq_length, num_directions, - batch_size, hidden_size], initial_h.shape = Y_h.shape = initial_c.shape - = Y_c.shape = [num_directions, batch_size, hidden_size]. If 1, the - following shapes are expected: X.shape = [batch_size, seq_length, - input_size], Y.shape = [batch_size, seq_length, num_directions, - hidden_size], initial_h.shape = Y_h.shape = initial_c.shape = Y_c.shape - = [batch_size, num_directions, hidden_size]. - -Returns -======= -Y : Var - Type T. - A tensor that concats all the intermediate output values of the hidden. - It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. -Y_h : Var - Type T. - The last output value of the hidden. It has shape - ``[num_directions, batch_size, hidden_size]``. -Y_c : Var - Type T. - The last output value of the cell. It has shape - ``[num_directions, batch_size, hidden_size]``. - -Notes -===== -Signature: ``ai.onnx@14::LSTM``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(int32)` - """ - return _LSTM( - _LSTM.Attributes( - activation_alpha=AttrFloat32s.maybe(activation_alpha, name="activation_alpha"), - activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), - activations=AttrStrings.maybe(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - input_forget=AttrInt64(input_forget, name="input_forget"), - layout=AttrInt64(layout, name="layout"), - ), _LSTM.Inputs( - X=unwrap_vars(X), W=unwrap_vars(W), R=unwrap_vars(R), B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), initial_c=unwrap_vars(initial_c), P=unwrap_vars(P), ), ).get_output_vars( - X=get_value(X), W=get_value(W), R=get_value(R), B=get_value(B), sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), initial_c=get_value(initial_c), P=get_value(P), )._unpack_to_any() - - -def layer_normalization(X: Var, Scale: Var, B: Optional[Var] = None, *, axis: int = -1, epsilon: float = 9.999999747378752e-06, stash_type: int = 1, ) -> tuple[Var, Var, Var]: - r""" -This is layer normalization defined in ONNX as function. The overall -computation can be split into two stages. The first stage is -standardization, which makes the normalized elements have zero mean and -unit variances. The computation required by standardization can be -described by the following equations. -``Mean = ReduceMean(X) D = Sub(X, Mean) DD = Mul(D, D) Var = ReduceMean(DD) VarEps = Add(Var, epsilon) StdDev = Sqrt(VarEps) InvStdDev = Reciprocal(StdDev) Normalized = Mul(D, InvStdDev)`` -where ``normalized_axes`` is ``[axis, ..., rank of X - 1]``. The -variables ``Var`` and ``StdDev`` stand for variance and standard -deviation, respectively. The second output is ``Mean`` and the last one -is ``InvStdDev``. Depending on ``stash_type`` attribute, the actual -computation must happen in different floating-point precision. For -example, if ``stash_type`` is 1, this operator casts all input variables -to 32-bit float, perform the computation, and finally cast -``Normalized`` back to the original type of ``X``. The second stage then -scales and shifts the outcome of the first stage using -``NormalizedScaled = Mul(Normalized, Scale) Y = Add(NormalizedScaled, B)`` -The second stage doesn't depends on ``stash_type``. All equations are in -`this syntax `__. -The same variable (i.e., input, output, and attribute) uses the same -name in the equations above and this operator's definition. Let ``d[i]`` -indicate the i-th dimension of ``X``. If ``X``'s shape is -``[d[0], ..., d[axis-1], d[axis], ..., d[rank-1]]``, the shape of -``Mean`` and ``InvStdDev`` is ``[d[0], ..., d[axis-1], 1, ..., 1]``. -``Y`` and ``X`` have the same shape. This operator supports -unidirectional broadcasting (tensors ``Scale`` and ``B`` should be -unidirectional broadcastable to tensor ``X``); for more details please -check `the -doc `__. - -Parameters -========== -X - Type T. - Tensor to be normalized. -Scale - Type T. - Scale tensor. -B - Type T. - Bias tensor. -axis - Attribute. - The first normalization dimension. If rank(X) is r, axis' allowed range - is [-r, r). Negative value means counting dimensions from the back. -epsilon - Attribute. - The epsilon value to use to avoid division by zero. -stash_type - Attribute. - Type of Mean and InvStdDev. This also specifies stage one's computation - precision. - -Returns -======= -Y : Var - Type T. - Normalized tensor. -Mean : Var - Type U. - Saved mean used during training to speed up gradient computation -InvStdDev : Var - Type U. - Saved inverse standard deviation used during training to speed up - gradient computation. - -Notes -===== -Signature: ``ai.onnx@17::LayerNormalization``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - U: `tensor(bfloat16)`, `tensor(float)` - """ - return _LayerNormalization( - _LayerNormalization.Attributes( - axis=AttrInt64(axis, name="axis"), - epsilon=AttrFloat32(epsilon, name="epsilon"), - stash_type=AttrInt64(stash_type, name="stash_type"), - ), _LayerNormalization.Inputs( - X=unwrap_vars(X), Scale=unwrap_vars(Scale), B=unwrap_vars(B), ), ).get_output_vars( - X=get_value(X), Scale=get_value(Scale), B=get_value(B), )._unpack_to_any() - - -def leaky_relu(X: Var, *, alpha: float = 0.009999999776482582, ) -> Var: - r""" -LeakyRelu takes input data (Tensor) and an argument alpha, and -produces one output data (Tensor) where the function -``f(x) = alpha * x for x < 0``, ``f(x) = x for x >= 0``, is applied to -the data tensor elementwise. - -Parameters -========== -X - Type T. - Input tensor -alpha - Attribute. - Coefficient of leakage. - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@16::LeakyRelu``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _LeakyRelu( - _LeakyRelu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), _LeakyRelu.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def less(A: Var, B: Var, ) -> Var: - r""" -Returns the tensor resulted from performing the ``less`` logical -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. - -Returns -======= -C : Var - Type T1. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@13::Less``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return _Less( - _Less.Attributes( - ), _Less.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def less_or_equal(A: Var, B: Var, ) -> Var: - r""" -Returns the tensor resulted from performing the ``less_equal`` logical -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. - -Returns -======= -C : Var - Type T1. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@16::LessOrEqual``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` - """ - return _LessOrEqual( - _LessOrEqual.Attributes( - ), _LessOrEqual.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def log(input: Var, ) -> Var: - r""" -Calculates the natural log of the given input tensor, element-wise. + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Asinh( + _Asinh.Attributes(), + _Asinh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -Parameters -========== -input - Type T. - Input tensor -Returns -======= -output : Var - Type T. - The natural log of the input tensor computed element-wise +def atan( + input: Var, +) -> Var: + r""" + Calculates the arctangent (inverse of tangent) of the given input + tensor, element-wise. -Notes -===== -Signature: ``ai.onnx@13::Log``. + Parameters + ========== + input + Type T. + Input tensor -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Log( - _Log.Attributes( - ), _Log.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def log_softmax(input: Var, *, axis: int = -1, ) -> Var: - r""" -The operator computes the log of softmax values for the given input: - -LogSoftmax(input, axis) = Log(Softmax(input, axis=axis)) - -The "axis" attribute indicates the dimension along which LogSoftmax will -be performed. The output tensor has the same shape and contains the -LogSoftmax values of the corresponding input. - -Parameters -========== -input - Type T. - The input tensor of rank >= axis. -axis - Attribute. - Describes the dimension LogSoftmax will be performed on. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(input). - -Returns -======= -output : Var - Type T. - The output values with the same shape as the input tensor. - -Notes -===== -Signature: ``ai.onnx@13::LogSoftmax``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _LogSoftmax( - _LogSoftmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _LogSoftmax.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def loop(M: Optional[Var] = None, cond: Optional[Var] = None, v_initial: Sequence[Var] = (), *, body: Callable[..., Iterable[Var]], ) -> Sequence[Var]: - r""" -Generic Looping construct. This loop has multiple termination -conditions: - -1) Trip count. Iteration count specified at runtime. Set by specifying - the input M. Optional. Set to empty string to omit. Note that a - static trip count (specified at graph construction time) can be - specified by passing in a constant node for input M. -2) Loop termination condition. This is an input to the op that - determines whether to run the first iteration and also a loop-carried - dependency for the body graph. The body graph must yield a value for - the condition variable, whether this input is provided or not. - -This table summarizes the operating modes of this operator with -equivalent C-style code: - -Operator inputs defined as (max_trip_count, condition_var). - -- input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } - -- input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } - -- input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } - -- input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } - -- input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } - -*Sample usage - cond as well as trip count* - -:: - - graph predict-net { - %a = Constant[value = ]() - %b = Constant[value = ]() - %keepgoing = Constant[value = ]() - %max_trip_count = Constant[value = ]() - %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) - return - } - - graph body-net ( - %i[INT32, scalar] // iteration number - %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used - %b_in[INT32, scalar] // incoming value of loop-carried-dependency b - ) { - %my_local = Add(%a, %b_in) - %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b - %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition - %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated - return %keepgoing_out, %b_out, %user_defined_val - } - -*Sample equivalent C code* - -:: - - { - /* User-defined code (enclosing scope) */ - int a = 3, b = 6; - bool keepgoing = true; // Analogous to input cond - /* End user-defined code */ - - /* Implicitly-defined code */ - const int max_trip_count = 10; // Analogous to input M - int user_defined_vals[]; // Imagine this is resizable - /* End implicitly-defined code */ - /* initialize loop-carried variables and scan-output variables */ - bool keepgoing_out = keepgoing - int b_out = b - - for (int i=0; i < max_trip_count && keepgoing_out; ++i) { - /* Implicitly-defined code: bind actual parameter values - to formal parameter variables of loop-body */ - bool keepgoing_in = keepgoing_out; - bool b_in = b_out; - - /* User-defined code (loop body) */ - int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine - b_out = a - b_in; - keepgoing_out = my_local > b_out; - user_defined_val = b_in + b_in; // b_in and b_out are different variables - /* End user-defined code */ - - /* Implicitly defined-code */ - user_defined_vals[i] = user_defined_val // accumulate scan-output values - } - // int t = my_local; // Can't do this. my_local is not accessible here. - - // The values below are bound to the output variables of the loop and therefore accessible - // b_out; user_defined_vals; keepgoing_out; - } - -There are several things of note in this code snippet: - -1) Values from the enclosing scope (i.e. variable "a" here) are in scope - and can be referenced in the inputs of the loop. -2) Any values computed in the loop body that needs to be used in a - subsequent iteration or after the loop are modelled using a pair of - variables in the loop-body, consisting of an input variable (eg., - b_in) and an output variable (eg., b_out). These are referred to as - loop-carried dependences. The loop operation node supplies the input - value of the input variable for the first iteration, and returns the - output value of the output variable produced by the final iteration. -3) Scan_output variables are used to implicitly concatenate values - computed across all the iterations. In the above example, the value - of user_defined_val computed over all iterations are concatenated and - returned as the value of user_defined_vals after the loop. -4) Values created in the body cannot be accessed in the enclosing scope, - except using the mechanism described above. - -Note that the semantics of this op support "diagonal" or "wavefront" -execution. (See Step 3 here for an example: -https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). -Frontends should emit multi-layer RNNs as a series of While operators -(with time being the inner looping dimension), with each successive -layer consuming the scan_outputs from the previous layer, possibly going -through several point-wise operators (e.g. dropout, residual -connections, linear layer). - -The input/output of subgraph (produced by loop node) matching is based -on order instead of name. The implementation will figure out the names -based on this order. - -Parameters -========== -M - Type I. - A maximum trip-count for the loop specified at runtime. Optional. Pass - empty string to skip. -cond - Type B. - A boolean termination condition. Optional. Pass empty string to skip. -v_initial - Type V. - The initial values of any loop-carried dependencies (values that change - across loop iterations) -body - Attribute. - The graph run each iteration. It has 2+N inputs: (iteration_num, - condition, loop carried dependencies...). It has 1+N+K outputs: - (condition, loop carried dependencies..., scan_outputs...). Each - scan_output is created by concatenating the value of the specified - output value at the end of each iteration of the loop. It is an error if - the dimensions or data type of these scan_outputs change across loop - iterations. - -Returns -======= -v_final_and_scan_outputs : Sequence[Var] - Type V. - Final N loop carried dependency values then K scan_outputs. Scan outputs - must be Tensors. - -Notes -===== -Signature: ``ai.onnx@16::Loop``. - -Type constraints: - - I: `tensor(int64)` - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _body_subgraph: Graph = subgraph( - typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))])+ [var.unwrap_type() for var in v_initial], - body - ) - return _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), _Loop.Inputs( - M=unwrap_vars(M), cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, ).get_output_vars( - M=get_value(M), cond=get_value(cond), v_initial=get_value(v_initial), ).v_final_and_scan_outputs - - -def lp_normalization(input: Var, *, axis: int = -1, p: int = 2, ) -> Var: - r""" -Given a matrix, apply Lp-normalization along the provided axis. - -Parameters -========== -input - Type T. - Input matrix -axis - Attribute. - The axis on which to apply normalization, -1 mean last axis. -p - Attribute. - The order of the normalization, only 1 or 2 are supported. - -Returns -======= -output : Var - Type T. - Matrix after normalization - -Notes -===== -Signature: ``ai.onnx@1::LpNormalization``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _LpNormalization( - _LpNormalization.Attributes( - axis=AttrInt64(axis, name="axis"), - p=AttrInt64(p, name="p"), - ), _LpNormalization.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def lp_pool(X: Var, *, auto_pad: str = "NOTSET", kernel_shape: Iterable[int], p: int = 2, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: - r""" -LpPool consumes an input tensor X and applies Lp pooling across the -tensor according to kernel sizes, stride sizes, and pad lengths. Lp -pooling consisting of computing the Lp norm on all values of a subset of -the input tensor according to the kernel size and downsampling the data -into the output tensor Y for further processing. - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. -kernel_shape - Attribute. - The size of the kernel along each axis. -p - Attribute. - p value of the Lp norm used to pool over the input data. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - -Returns -======= -Y : Var - Type T. - Output data tensor from Lp pooling across the input tensor. Dimensions - will vary based on various kernel, stride, and pad sizes. - -Notes -===== -Signature: ``ai.onnx@11::LpPool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _LpPool( - _LpPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - p=AttrInt64(p, name="p"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _LpPool.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def matmul(A: Var, B: Var, ) -> Var: - r""" -Matrix product that behaves like numpy.matmul: -https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html - -Parameters -========== -A - Type T. - N-dimensional matrix A -B - Type T. - N-dimensional matrix B - -Returns -======= -Y : Var - Type T. - Matrix multiply results from A \* B - -Notes -===== -Signature: ``ai.onnx@13::MatMul``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _MatMul( - _MatMul.Attributes( - ), _MatMul.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).Y - - -def matmul_integer(A: Var, B: Var, a_zero_point: Optional[Var] = None, b_zero_point: Optional[Var] = None, ) -> Var: - r""" -Matrix product that behaves like numpy.matmul: -https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. -The production MUST never overflow. The accumulation may overflow if and -only if in 32 bits. - -Parameters -========== -A - Type T1. - N-dimensional matrix A -B - Type T2. - N-dimensional matrix B -a_zero_point - Type T1. - Zero point tensor for input 'A'. It's optional and default value is 0. - It could be a scalar or N-D tensor. Scalar refers to per tensor - quantization whereas N-D refers to per row quantization. If the input is - 2D of shape [M, K] then zero point tensor may be an M element vector - [zp_1, zp_2, ..., zp_M]. If the input is N-D tensor with shape [D1, D2, - M, K] then zero point tensor may have shape [D1, D2, M, 1]. -b_zero_point - Type T2. - Zero point tensor for input 'B'. It's optional and default value is 0. - It could be a scalar or a N-D tensor, Scalar refers to per tensor - quantization whereas N-D refers to per col quantization. If the input is - 2D of shape [K, N] then zero point tensor may be an N element vector - [zp_1, zp_2, ..., zp_N]. If the input is N-D tensor with shape [D1, D2, - K, N] then zero point tensor may have shape [D1, D2, 1, N]. - -Returns -======= -Y : Var - Type T3. - Matrix multiply results from A \* B - -Notes -===== -Signature: ``ai.onnx@10::MatMulInteger``. - -Type constraints: - - T1: `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(int32)` - """ - return _MatMulInteger( - _MatMulInteger.Attributes( - ), _MatMulInteger.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), a_zero_point=unwrap_vars(a_zero_point), b_zero_point=unwrap_vars(b_zero_point), ), ).get_output_vars( - A=get_value(A), B=get_value(B), a_zero_point=get_value(a_zero_point), b_zero_point=get_value(b_zero_point), ).Y - - -def max(data_0: Sequence[Var], ) -> Var: - r""" -Element-wise max of each of the input tensors (with Numpy-style -broadcasting support). All inputs and outputs must have the same data -type. This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -data_0 - Type T. - List of tensors for max. - -Returns -======= -max : Var - Type T. - Output tensor. - -Notes -===== -Signature: ``ai.onnx@13::Max``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Max( - _Max.Attributes( - ), _Max.Inputs( - data_0=unwrap_vars(data_0), ), ).get_output_vars( - data_0=get_value(data_0), ).max - - -def max_pool(X: Var, *, auto_pad: str = "NOTSET", ceil_mode: int = 0, dilations: Optional[Iterable[int]] = None, kernel_shape: Iterable[int], pads: Optional[Iterable[int]] = None, storage_order: int = 0, strides: Optional[Iterable[int]] = None, ) -> tuple[Var, Var]: - r""" -MaxPool consumes an input tensor X and applies max pooling across the -tensor according to kernel sizes, stride sizes, and pad lengths. max -pooling consisting of computing the max on all values of a subset of the -input tensor according to the kernel size and downsampling the data into -the output tensor Y for further processing. The output spatial shape is -calculated differently depending on whether explicit padding is used, -where pads is employed, or auto padding is used, where auto_pad is -utilized. With explicit padding -(https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): - -:: - - output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) - -or - -:: - - output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) - -if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis -``i``. Sliding windows that would start in the right padded region are -ignored. - -``auto_pad`` is a DEPRECATED attribute. If you are using them currently, -the output spatial shape will be following when ceil_mode is enabled: - -:: - - VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) - -or when ceil_mode is disabled -(https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): - -:: - - VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 - -And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: - -:: - - pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] - -The output of each pooling window is maximum number of elements exclude -pad. - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. Optionally, if dimension denotation is in - effect, the operation expects the input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. -ceil_mode - Attribute. - Whether to use ceil or floor (default) to compute the output shape. -dilations - Attribute. - Dilation value along each spatial axis of filter. If not present, the - dilation defaults to 1 along each spatial axis. -kernel_shape - Attribute. - The size of the kernel along each axis. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. -storage_order - Attribute. - The storage order of the tensor. 0 is row major, and 1 is column major. - This attribute is used only to convert an n-tuple index value into a - single integer value for producing the second output. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - -Returns -======= -Y : Var - Type T. - Output data tensor from average or max pooling across the input tensor. - Dimensions will vary based on various kernel, stride, and pad sizes. - Floor value of the dimension is used -Indices : Var - Type I. - Indices tensor from max pooling across the input tensor. The dimensions - of indices are the same as output tensor. The values in indices of are - the indices of the selected values during pooling. The indices are - computed as flatten 1-D tensor, and the indices do not consider padding. - So the values in indices are in [0, N x C x D1 x ... x Dn). - -Notes -===== -Signature: ``ai.onnx@12::MaxPool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int8)`, `tensor(uint8)` - - I: `tensor(int64)` - """ - return _MaxPool( - _MaxPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - storage_order=AttrInt64(storage_order, name="storage_order"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _MaxPool.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), )._unpack_to_any() - - -def max_roi_pool(X: Var, rois: Var, *, pooled_shape: Iterable[int], spatial_scale: float = 1.0, ) -> Var: - r""" -ROI max pool consumes an input tensor X and region of interests (RoIs) -to apply max pooling across each RoI, to produce output 4-D tensor of -shape (num_rois, channels, pooled_shape[0], pooled_shape[1]). - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. -rois - Type T. - RoIs (Regions of Interest) to pool over. Should be a 2-D tensor of shape - (num_rois, 5) given as [[batch_id, x1, y1, x2, y2], ...]. -pooled_shape - Attribute. - ROI pool output shape (height, width). -spatial_scale - Attribute. - Multiplicative spatial scale factor to translate ROI coordinates from - their input scale to the scale used when pooling. - -Returns -======= -Y : Var - Type T. - RoI pooled output 4-D tensor of shape (num_rois, channels, - pooled_shape[0], pooled_shape[1]). - -Notes -===== -Signature: ``ai.onnx@1::MaxRoiPool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _MaxRoiPool( - _MaxRoiPool.Attributes( - pooled_shape=AttrInt64s(pooled_shape, name="pooled_shape"), - spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), - ), _MaxRoiPool.Inputs( - X=unwrap_vars(X), rois=unwrap_vars(rois), ), ).get_output_vars( - X=get_value(X), rois=get_value(rois), ).Y - - -def max_unpool(X: Var, I: Var, output_shape: Optional[Var] = None, *, kernel_shape: Iterable[int], pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: - r""" -MaxUnpool essentially computes the partial inverse of the MaxPool op. -The input information to this op is typically the output information -from a MaxPool op. The first input tensor X is the tensor that needs to -be unpooled, which is typically the pooled tensor (first output) from -MaxPool. The second input tensor, I, contains the indices to the -(locally maximal) elements corresponding to the elements in the first -input tensor X. Input tensor I is typically the second output of the -MaxPool op. The third (optional) input is a tensor that specifies the -output size of the unpooling operation. - -MaxUnpool is intended to do 'partial' inverse of the MaxPool op. -'Partial' because all the non-maximal values from the original input to -MaxPool are set to zero in the output of the MaxUnpool op. Pooling the -result of an unpooling operation should give back the original input to -the unpooling op. - -MaxUnpool can produce the same output size for several input sizes, -which makes unpooling op ambiguous. The third input argument, -output_size, is meant to disambiguate the op and produce output tensor -of known/predictable size. - -In addition to the inputs, MaxUnpool takes three attributes, namely -kernel_shape, strides, and pads, which define the exact unpooling op. -The attributes typically have the same values as the corresponding -pooling op that the unpooling op is trying to invert. - -Parameters -========== -X - Type T1. - Input data tensor that has to be unpooled. This tensor is typically the - first output of the MaxPool op.Dimensions for image case are (N x C x H - x W), where N is the batch size, C is the number of channels, and H and - W are the height and the width of the data. For non-image case, the - dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the - batch size. Optionally, if dimension denotation is in effect, the - operation expects the input data tensor to arrive with the dimension - denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE - ...]. -I - Type T2. - Input data tensor containing the indices corresponding to elements in - the first input tensor X.This tensor is typically the second output of - the MaxPool op.Dimensions must be the same as input tensor X. The - indices are linear, i.e. computed considering the tensor as flattened - 1-D tensor, assuming row-major storage. Also, the linear indices should - not consider padding. So the values in indices are in the range [0, N x - C x D1 x ... x Dn). -output_shape - Type T2. - The shape of the output can be explicitly set which will cause pads - values to be auto generated. If 'output_shape' is specified, 'pads' - values are ignored. -kernel_shape - Attribute. - The size of the kernel along each axis. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - -Returns -======= -output : Var - Type T1. - Output data tensor that contains the result of the unpooling. - -Notes -===== -Signature: ``ai.onnx@11::MaxUnpool``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int64)` - """ - return _MaxUnpool( - _MaxUnpool.Attributes( - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _MaxUnpool.Inputs( - X=unwrap_vars(X), I=unwrap_vars(I), output_shape=unwrap_vars(output_shape), ), ).get_output_vars( - X=get_value(X), I=get_value(I), output_shape=get_value(output_shape), ).output - - -def mean(data_0: Sequence[Var], ) -> Var: - r""" -Element-wise mean of each of the input tensors (with Numpy-style -broadcasting support). All inputs and outputs must have the same data -type. This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -data_0 - Type T. - List of tensors for mean. - -Returns -======= -mean : Var - Type T. - Output tensor. - -Notes -===== -Signature: ``ai.onnx@13::Mean``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Mean( - _Mean.Attributes( - ), _Mean.Inputs( - data_0=unwrap_vars(data_0), ), ).get_output_vars( - data_0=get_value(data_0), ).mean - - -def mean_variance_normalization(X: Var, *, axes: Iterable[int] = (0, 2, 3), ) -> Var: - r""" -A MeanVarianceNormalization Function: Perform mean variance -normalization on the input tensor X using formula: -``(X-EX)/sqrt(E(X-EX)^2)`` - -Parameters -========== -X - Type T. - Input tensor -axes - Attribute. - A list of integers, along which to reduce. The default is to calculate - along axes [0,2,3] for calculating mean and variance along each channel. - Two variables with the same C-coordinate are associated with the same - mean and variance. - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@13::MeanVarianceNormalization``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _MeanVarianceNormalization( - _MeanVarianceNormalization.Attributes( - axes=AttrInt64s(axes, name="axes"), - ), _MeanVarianceNormalization.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def mel_weight_matrix(num_mel_bins: Var, dft_length: Var, sample_rate: Var, lower_edge_hertz: Var, upper_edge_hertz: Var, *, output_datatype: int = 1, ) -> Var: - r""" -Generate a MelWeightMatrix that can be used to re-weight a Tensor -containing a linearly sampled frequency spectra (from DFT or STFT) into -num_mel_bins frequency information based on the [lower_edge_hertz, -upper_edge_hertz] range on the mel scale. This function defines the mel -scale in terms of a frequency in hertz according to the following -formula: - -:: - - mel(f) = 2595 * log10(1 + f/700) - -In the returned matrix, all the triangles (filterbanks) have a peak -value of 1.0. - -The returned MelWeightMatrix can be used to right-multiply a spectrogram -S of shape [frames, num_spectrogram_bins] of linear scale spectrum -values (e.g. STFT magnitudes) to generate a "mel spectrogram" M of shape -[frames, num_mel_bins]. - -Parameters -========== -num_mel_bins - Type T1. - The number of bands in the mel spectrum. -dft_length - Type T1. - The size of the original DFT. The size of the original DFT is used to - infer the size of the onesided DFT, which is understood to be - floor(dft_length/2) + 1, i.e. the spectrogram only contains the - nonredundant DFT bins. -sample_rate - Type T1. - Samples per second of the input signal used to create the spectrogram. - Used to figure out the frequencies corresponding to each spectrogram - bin, which dictates how they are mapped into the mel scale. -lower_edge_hertz - Type T2. - Lower bound on the frequencies to be included in the mel spectrum. This - corresponds to the lower edge of the lowest triangular band. -upper_edge_hertz - Type T2. - The desired top edge of the highest frequency band. -output_datatype - Attribute. - The data type of the output tensor. Strictly must be one of the values - from DataType enum in TensorProto whose values correspond to T3. The - default value is 1 = FLOAT. - -Returns -======= -output : Var - Type T3. - The Mel Weight Matrix. The output has the shape: [floor(dft_length/2) + - 1][num_mel_bins]. - -Notes -===== -Signature: ``ai.onnx@17::MelWeightMatrix``. - -Type constraints: - - T1: `tensor(int32)`, `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T3: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _MelWeightMatrix( - _MelWeightMatrix.Attributes( - output_datatype=AttrInt64(output_datatype, name="output_datatype"), - ), _MelWeightMatrix.Inputs( - num_mel_bins=unwrap_vars(num_mel_bins), dft_length=unwrap_vars(dft_length), sample_rate=unwrap_vars(sample_rate), lower_edge_hertz=unwrap_vars(lower_edge_hertz), upper_edge_hertz=unwrap_vars(upper_edge_hertz), ), ).get_output_vars( - num_mel_bins=get_value(num_mel_bins), dft_length=get_value(dft_length), sample_rate=get_value(sample_rate), lower_edge_hertz=get_value(lower_edge_hertz), upper_edge_hertz=get_value(upper_edge_hertz), ).output - - -def min(data_0: Sequence[Var], ) -> Var: - r""" -Element-wise min of each of the input tensors (with Numpy-style -broadcasting support). All inputs and outputs must have the same data -type. This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -data_0 - Type T. - List of tensors for min. - -Returns -======= -min : Var - Type T. - Output tensor. - -Notes -===== -Signature: ``ai.onnx@13::Min``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Min( - _Min.Attributes( - ), _Min.Inputs( - data_0=unwrap_vars(data_0), ), ).get_output_vars( - data_0=get_value(data_0), ).min - - -def mod(A: Var, B: Var, *, fmod: int = 0, ) -> Var: - r""" -Performs element-wise binary modulus (with Numpy-style broadcasting -support). The sign of the remainder is the same as that of the Divisor. - -Mod operator can also behave like C fmod() or numpy.fmod. In this case, -the sign of the remainder however, will be the same as the Dividend (in -contrast to integer mod). To force a behavior like numpy.fmod() an -'fmod' Attribute is provided. This attribute is set to 0 by default -causing the behavior to be like integer mod. Setting this attribute to 1 -causes the remainder to be calculated similar to that of numpy.fmod(). - -If the input type is floating point, then ``fmod`` attribute must be set -to 1. - -In case of dividend being zero, the results will be platform dependent. - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - Dividend tensor -B - Type T. - Divisor tensor -fmod - Attribute. - Whether the operator should behave like fmod (default=0 meaning it will - do integer mods); Set this to 1 to force fmod treatment - -Returns -======= -C : Var - Type T. - Remainder tensor - -Notes -===== -Signature: ``ai.onnx@13::Mod``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Mod( - _Mod.Attributes( - fmod=AttrInt64(fmod, name="fmod"), - ), _Mod.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def mul(A: Var, B: Var, ) -> Var: - r""" -Performs element-wise binary multiplication (with Numpy-style -broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -(Opset 14 change): Extend supported types to include uint8, int8, -uint16, and int16. - -Parameters -========== -A - Type T. - First operand. -B - Type T. - Second operand. - -Returns -======= -C : Var - Type T. - Result, has same element type as two inputs - -Notes -===== -Signature: ``ai.onnx@14::Mul``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Mul( - _Mul.Attributes( - ), _Mul.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def multinomial(input: Var, *, dtype: npt.DTypeLike = np.int32, sample_size: int = 1, seed: Optional[float] = None, ) -> Var: - r""" -Generate a tensor of samples from a multinomial distribution according -to the probabilities of each of the possible outcomes. - -Parameters -========== -input - Type T1. - Input tensor with shape [batch_size, class_size], where class_size is - the number of all possible outcomes. Each value along the axis zero - represents the unnormalized log-probability of each corresponding - outcome in a batch. -dtype - Attribute. - (Optional) The data type for the elements of the output tensor, if not - specified, we will use int32. -sample_size - Attribute. - Number of times to sample. -seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - -Returns -======= -output : Var - Type T2. - Output tensor with shape [batch_size, sample_size], where sample_size is - the number of times to sample. Each value along the axis zero represents - the outcome of the corresponding sample in a batch. + Returns + ======= + output : Var + Type T. + The arctangent of the input tensor computed element-wise -Notes -===== -Signature: ``ai.onnx@7::Multinomial``. + Notes + ===== + Signature: ``ai.onnx@7::Atan``. -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int32)`, `tensor(int64)` + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Multinomial( - _Multinomial.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - sample_size=AttrInt64(sample_size, name="sample_size"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), _Multinomial.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Atan( + _Atan.Attributes(), + _Atan.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def neg(X: Var, ) -> Var: +def atanh( + input: Var, +) -> Var: r""" -Neg takes one input data (Tensor) and produces one output data -(Tensor) where each element flipped sign, y = -x, is applied to the -tensor elementwise. + Calculates the hyperbolic arctangent of the given input tensor + element-wise. -Parameters -========== -X - Type T. - Input tensor + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The hyperbolic arctangent values of the input tensor computed + element-wise + + Notes + ===== + Signature: ``ai.onnx@9::Atanh``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Atanh( + _Atanh.Attributes(), + _Atanh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@13::Neg``. -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` +def average_pool( + X: Var, + *, + auto_pad: str = "NOTSET", + ceil_mode: int = 0, + count_include_pad: int = 0, + kernel_shape: Iterable[int], + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: + r""" + AveragePool consumes an input tensor X and applies average pooling + across the tensor according to kernel sizes, stride sizes, and pad + lengths. average pooling consisting of computing the average on all + values of a subset of the input tensor according to the kernel size and + downsampling the data into the output tensor Y for further processing. + The output spatial shape will be following: + + :: + + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + + or + + :: + + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + + if ceil_mode is enabled + + :: + + * pad_shape[i] is sum of pads along axis i + + ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, + the output spatial shape will be following when ceil_mode is enabled: + + :: + + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + + or when ceil_mode is disabled: + + :: + + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor(input_spatial_shape[i] / strides_spatial_shape[i]) + + And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: + + :: + + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + + The output of each pooling window is divided by the number of elements + (exclude pad when attribute count_include_pad is zero). + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. Optionally, if dimension denotation is in + effect, the operation expects the input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. + ceil_mode + Attribute. + Whether to use ceil or floor (default) to compute the output shape. + count_include_pad + Attribute. + Whether include pad pixels when calculating values for the edges. + Default is 0, doesn't count include pad. + kernel_shape + Attribute. + The size of the kernel along each axis. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + + Returns + ======= + Y : Var + Type T. + Output data tensor from average or max pooling across the input tensor. + Dimensions will vary based on various kernel, stride, and pad sizes. + Floor value of the dimension is used + + Notes + ===== + Signature: ``ai.onnx@11::AveragePool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Neg( - _Neg.Attributes( - ), _Neg.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + return ( + _AveragePool( + _AveragePool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + count_include_pad=AttrInt64( + count_include_pad, name="count_include_pad" + ), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _AveragePool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def negative_log_likelihood_loss(input: Var, target: Var, weight: Optional[Var] = None, *, ignore_index: Optional[int] = None, reduction: str = "mean", ) -> Var: +def batch_normalization( + X: Var, + scale: Var, + B: Var, + input_mean: Var, + input_var: Var, + *, + epsilon: float = 9.999999747378752e-06, + momentum: float = 0.8999999761581421, + training_mode: int = 0, +) -> tuple[Var, Var, Var]: r""" -A NegativeLogLikelihoodLoss operator computes (weighted) negative log -likelihood loss. Its "input" tensor has the shape of (N, C, d1, d2, ..., -dk) where k >= 0. The "input" tensor contains log-probabilities for -input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). The -operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). -It encodes class labels (one of C classes) or it may contain a special -value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x -dk samples. The loss value for input[n, :, d_1, d_2,...d_k] being -classified as class c = target[n][d_1][d_2]...[d_k] is computed as: - -:: - - loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. - -When an optional "weight" is provided, the sample loss is calculated as: - -:: - - loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. - -loss is zero for the case when target-value equals ignore_index. - -:: - - loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index - -If "reduction" attribute is set to "none", the operator's output will be -the above loss with shape (N, d1, d2, ..., dk). If "reduction" attribute -is set to "mean" (the default attribute value), the output loss is -(weight) averaged: - -:: - - mean(loss), if "weight" is not provided, - -or if weight is provided, - -:: - - sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. - -If "reduction" attribute is set to "sum", the output is a scalar: -``sum(loss)``. - -See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. - -Example 1: - -:: - - // negative log likelihood loss, "none" reduction - N, C, d1 = 2, 3, 2 - input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] - target = [[2, 1], [0, 2]] - - loss = np.zeros((N, d1)) - for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] - - // print(loss) - // [[-3. -2.] - // [-0. -2.]] - -Example 2: - -:: - - // weighted negative log likelihood loss, sum reduction - N, C, d1 = 2, 3, 2 - input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] - target = [[2, 1], [0, 2]] - weight = [0.2, 0.3, 0.1] - loss = np.zeros((N, d1)) - for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] * weight[c] - - loss = np.sum(loss) - // print(loss) - // -1.1 - -Example 3: - -:: - - // weighted negative log likelihood loss, mean reduction - N, C, d1 = 2, 3, 2 - input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], - [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] - target = [[2, 1], [0, 2]] - weight = [0.2, 0.3, 0.1] - loss = np.zeros((N, d1)) - weight_total = 0 - for n in range(N): - for d_1 in range(d1): - c = target[n][d_1] - loss[n][d_1] = -input[n][c][d_1] * weight[c] - weight_total = weight_total + weight[c] - - loss = np.sum(loss) / weight_total - // print(loss) - // -1.57 - -Parameters -========== -input - Type T. - Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk). -target - Type Tind. - Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value - shall be in range of [0, C). If ignore_index is specified, it may have a - value outside [0, C) and the target values should either be in the range - [0, C) or have the value ignore_index. -weight - Type T. - Optional rescaling weight tensor. If given, it has to be a tensor of - size C. Otherwise, it is treated as if having all ones. -ignore_index - Attribute. - Specifies a target value that is ignored and does not contribute to the - input gradient. It's an optional value. -reduction - Attribute. - Type of reduction to apply to loss: none, sum, mean (default). 'none': - the output is the loss for each sample. 'sum': the output will be - summed. 'mean': the sum of the output will be divided by the sum of - applied weights. - -Returns -======= -loss : Var - Type T. - The negative log likelihood loss - -Notes -===== -Signature: ``ai.onnx@13::NegativeLogLikelihoodLoss``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return _NegativeLogLikelihoodLoss( - _NegativeLogLikelihoodLoss.Attributes( - ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), - reduction=AttrString(reduction, name="reduction"), - ), _NegativeLogLikelihoodLoss.Inputs( - input=unwrap_vars(input), target=unwrap_vars(target), weight=unwrap_vars(weight), ), ).get_output_vars( - input=get_value(input), target=get_value(target), weight=get_value(weight), ).loss - - -def non_max_suppression(boxes: Var, scores: Var, max_output_boxes_per_class: Optional[Var] = None, iou_threshold: Optional[Var] = None, score_threshold: Optional[Var] = None, *, center_point_box: int = 0, ) -> Var: - r""" -Filter out boxes that have high intersection-over-union (IOU) overlap -with previously selected boxes. Bounding boxes with score less than -score_threshold are removed. Bounding box format is indicated by -attribute center_point_box. Note that this algorithm is agnostic to -where the origin is in the coordinate system and more generally is -invariant to orthogonal transformations and translations of the -coordinate system; thus translating or reflections of the coordinate -system result in the same boxes being selected by the algorithm. The -selected_indices output is a set of integers indexing into the input -collection of bounding boxes representing the selected boxes. The -bounding box coordinates corresponding to the selected indices can then -be obtained using the Gather or GatherND operation. - -Parameters -========== -boxes - Type tensor(float). - An input tensor with shape [num_batches, spatial_dimension, 4]. The - single box data format is indicated by center_point_box. -scores - Type tensor(float). - An input tensor with shape [num_batches, num_classes, spatial_dimension] -max_output_boxes_per_class - Type tensor(int64). - Integer representing the maximum number of boxes to be selected per - batch per class. It is a scalar. Default to 0, which means no output. -iou_threshold - Type tensor(float). - Float representing the threshold for deciding whether boxes overlap too - much with respect to IOU. It is scalar. Value range [0, 1]. Default to - 0. -score_threshold - Type tensor(float). - Float representing the threshold for deciding when to remove boxes based - on score. It is a scalar. -center_point_box - Attribute. - Integer indicate the format of the box data. The default is 0. 0 - the - box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are - the coordinates of any diagonal pair of box corners and the coordinates - can be provided as normalized (i.e., lying in the interval [0, 1]) or - absolute. Mostly used for TF models. 1 - the box data is supplied as - [x_center, y_center, width, height]. Mostly used for Pytorch models. - -Returns -======= -selected_indices : Var - Type tensor(int64). - selected indices from the boxes tensor. [num_selected_indices, 3], the - selected index format is [batch_index, class_index, box_index]. - -Notes -===== -Signature: ``ai.onnx@11::NonMaxSuppression``. - - """ - return _NonMaxSuppression( - _NonMaxSuppression.Attributes( - center_point_box=AttrInt64(center_point_box, name="center_point_box"), - ), _NonMaxSuppression.Inputs( - boxes=unwrap_vars(boxes), scores=unwrap_vars(scores), max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), iou_threshold=unwrap_vars(iou_threshold), score_threshold=unwrap_vars(score_threshold), ), ).get_output_vars( - boxes=get_value(boxes), scores=get_value(scores), max_output_boxes_per_class=get_value(max_output_boxes_per_class), iou_threshold=get_value(iou_threshold), score_threshold=get_value(score_threshold), ).selected_indices - - -def non_zero(X: Var, ) -> Var: - r""" -Returns the indices of the elements that are non-zero (in row-major -order - by dimension). NonZero behaves similar to numpy.nonzero: -https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html, -but for scalar input, NonZero produces output shape (0, N) instead of -(1, N), which is different from Numpy's behavior. - -Parameters -========== -X - Type T. - input - -Returns -======= -Y : Var - Type tensor(int64). - output - -Notes -===== -Signature: ``ai.onnx@13::NonZero``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _NonZero( - _NonZero.Attributes( - ), _NonZero.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def not_(X: Var, ) -> Var: - r""" -Returns the negation of the input tensor element-wise. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@1::Not``. - -Type constraints: - - T: `tensor(bool)` - """ - return _Not( - _Not.Attributes( - ), _Not.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def one_hot(indices: Var, depth: Var, values: Var, *, axis: int = -1, ) -> Var: - r""" -Produces a one-hot tensor based on inputs. The locations represented by -the index values in the 'indices' input tensor will have 'on_value' and -the other locations will have 'off_value' in the output tensor, where -'on_value' and 'off_value' are specified as part of required input -argument 'values', which is a two-element tensor of format [off_value, -on_value]. The rank of the output tensor will be one greater than the -rank of the input tensor. The additional dimension is for one-hot -representation. The additional dimension will be inserted at the -position specified by 'axis'. If 'axis' is not specified then then -additional dimension will be inserted as the innermost dimension, i.e. -axis=-1. The size of the additional dimension is specified by required -scalar input 'depth'. The type of the output tensor is the same as the -type of the 'values' input. Any entries in the 'indices' input tensor -with values outside the range [-depth, depth-1] will result in one-hot -representation with all 'off_value' values in the output tensor. - -:: - - when axis = 0: - output[input[i, j, k], i, j, k] = 1 for all i, j, k and 0 otherwise. - - when axis = -1: - output[i, j, k, input[i, j, k]] = 1 for all i, j, k and 0 otherwise. - -Parameters -========== -indices - Type T1. - Input tensor containing indices. Any entries in the 'indices' input - tensor with values outside the range [-depth, depth-1] will result in - one-hot representation with all 'off_value' values in the output - tensor.In case 'indices' is of non-integer type, the values will be - casted to int64 before use. -depth - Type T2. - Scalar or Rank 1 tensor containing exactly one element, specifying the - number of classes in one-hot tensor. This is also the size of the - one-hot dimension (specified by 'axis' attribute) added on in the output - tensor. The values in the 'indices' input tensor are expected to be in - the range [-depth, depth-1]. In case 'depth' is of non-integer type, it - will be casted to int64 before use. -values - Type T3. - Rank 1 tensor containing exactly two elements, in the format [off_value, - on_value], where 'on_value' is the value used for filling locations - specified in 'indices' input tensor, and 'off_value' is the value used - for filling locations other than those specified in 'indices' input - tensor. -axis - Attribute. - (Optional) Axis along which one-hot representation in added. Default: - axis=-1. axis=-1 means that the additional dimension will be inserted as - the innermost/last dimension in the output tensor. Negative value means - counting dimensions from the back. Accepted range is [-r-1, r] where r = - rank(indices). - -Returns -======= -output : Var - Type T3. - Tensor of rank one greater than input tensor 'indices', i.e. - rank(output) = rank(indices) + 1. The data type for the elements of the - output tensor is the same as the type of input 'values' is used. - -Notes -===== -Signature: ``ai.onnx@11::OneHot``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T3: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _OneHot( - _OneHot.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _OneHot.Inputs( - indices=unwrap_vars(indices), depth=unwrap_vars(depth), values=unwrap_vars(values), ), ).get_output_vars( - indices=get_value(indices), depth=get_value(depth), values=get_value(values), ).output - - -def optional(input: Optional[Var] = None, *, type: Optional[Type] = None, ) -> Var: - r""" -Constructs an optional-type value containing either an empty optional of -a certain type specified by the attribute, or a non-empty value -containing the input element. - -Parameters -========== -input - Type V. - The input element. -type - Attribute. - Type of the element in the optional output - -Returns -======= -output : Var - Type O. - The optional output enclosing the input element. - -Notes -===== -Signature: ``ai.onnx@15::Optional``. - -Type constraints: - - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - """ - return _Optional( - _Optional.Attributes( - type=AttrType.maybe(type, name="type"), - ), _Optional.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def optional_get_element(input: Var, ) -> Var: - r""" -Outputs the element in the optional-type input. It is an error if the -input value does not have an element and the behavior is undefined in -this case. - -Parameters -========== -input - Type O. - The optional input. - -Returns -======= -output : Var - Type V. - Output element in the optional input. - -Notes -===== -Signature: ``ai.onnx@15::OptionalGetElement``. - -Type constraints: - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _OptionalGetElement( - _OptionalGetElement.Attributes( - ), _OptionalGetElement.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def optional_has_element(input: Var, ) -> Var: - r""" -Returns true if the optional-type input contains an element. If it is an -empty optional-type, this op returns false. - -Parameters -========== -input - Type O. - The optional input. - -Returns -======= -output : Var - Type B. - A scalar boolean tensor. If true, it indicates that optional-type input - contains an element. Otherwise, it is empty. - -Notes -===== -Signature: ``ai.onnx@15::OptionalHasElement``. - -Type constraints: - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - - B: `tensor(bool)` - """ - return _OptionalHasElement( - _OptionalHasElement.Attributes( - ), _OptionalHasElement.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def or_(A: Var, B: Var, ) -> Var: - r""" -Returns the tensor resulted from performing the ``or`` logical operation -elementwise on the input tensors ``A`` and ``B`` (with Numpy-style -broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. + Carries out batch normalization as described in the paper + https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, + There are five required inputs 'X', 'scale', 'B', 'input_mean' and + 'input_var'. Note that 'input_mean' and 'input_var' are expected to be + the estimated statistics in inference mode (training_mode=False, + default), and the running statistics in training mode + (training_mode=True). There are multiple cases for the number of + outputs, which we list below: + + - Output case #1: Y, running_mean, running_var (training_mode=True) + - Output case #2: Y (training_mode=False) + + When training_mode=False, extra outputs are invalid. The outputs are + updated as follows when training_mode=True: + + :: + + running_mean = input_mean * momentum + current_mean * (1 - momentum) + running_var = input_var * momentum + current_var * (1 - momentum) + + Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B + + where: + + :: + + current_mean = ReduceMean(X, axis=all_except_channel_index) + current_var = ReduceVar(X, axis=all_except_channel_index) + + Notice that ``ReduceVar`` refers to the population variance, and it + equals to ``sum(sqrd(x_i - x_avg)) / N`` where ``N`` is the population + size (this formula does not use sample size ``N - 1``). + + The computation of ReduceMean and ReduceVar uses float to avoid overflow + for float16 inputs. + + When training_mode=False: + + :: + + Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B + + For previous (depreciated) non-spatial cases, implementors are suggested + to flatten the input shape to (N x C \* D1 \* D2 \* ... \* Dn) before a + BatchNormalization Op. This operator has **optional** inputs/outputs. + See `the doc `__ for + more details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to indicate + a missing argument. Trailing optional arguments (those not followed by + an argument that is present) may also be simply omitted. + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions are in the form + of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number + of channels. Statistics are computed for every channel of C over N and + D1 to Dn dimensions. For image data, input dimensions become (N x C x H + x W). The op also accepts single dimension input of size N in which case + C is assumed to be 1 + scale + Type T1. + Scale tensor of shape (C). + B + Type T1. + Bias tensor of shape (C). + input_mean + Type T2. + running (training) or estimated (testing) mean tensor of shape (C). + input_var + Type T2. + running (training) or estimated (testing) variance tensor of shape (C). + epsilon + Attribute. + The epsilon value to use to avoid division by zero. + momentum + Attribute. + Factor used in computing the running mean and variance.e.g., + running_mean = running_mean \* momentum + mean \* (1 - momentum). + training_mode + Attribute. + If set to true, it indicates BatchNormalization is being used for + training, and outputs 1 and 2 are to be computed. + + Returns + ======= + Y : Var + Type T. + The output tensor of the same shape as X + running_mean : Var + Type T2. + The running mean after the BatchNormalization operator. + running_var : Var + Type T2. + The running variance after the BatchNormalization operator. This op uses + the population size (N) for calculating variance, and not the sample + size N-1. + + Notes + ===== + Signature: ``ai.onnx@15::BatchNormalization``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _BatchNormalization( + _BatchNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + momentum=AttrFloat32(momentum, name="momentum"), + training_mode=AttrInt64(training_mode, name="training_mode"), + ), + _BatchNormalization.Inputs( + X=unwrap_vars(X), + scale=unwrap_vars(scale), + B=unwrap_vars(B), + input_mean=unwrap_vars(input_mean), + input_var=unwrap_vars(input_var), + ), + ) + .get_output_vars( + X=get_value(X), + scale=get_value(scale), + B=get_value(B), + input_mean=get_value(input_mean), + input_var=get_value(input_var), + ) + ._unpack_to_any() + ) -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. -Returns -======= -C : Var - Type T1. - Result tensor. +def bernoulli( + input: Var, + *, + dtype: Optional[npt.DTypeLike] = None, + seed: Optional[float] = None, +) -> Var: + r""" + Draws binary random numbers (0 or 1) from a Bernoulli distribution. The + input tensor should be a tensor containing probabilities p (a value in + the range [0,1]) to be used for drawing the binary random number, where + an output of 1 is produced with probability p and an output of 0 is + produced with probability (1-p). -Notes -===== -Signature: ``ai.onnx@7::Or``. + This operator is non-deterministic and may not produce the same values + in different implementations (even if a seed is specified). -Type constraints: - - T: `tensor(bool)` - - T1: `tensor(bool)` + Parameters + ========== + input + Type T1. + All values in input have to be in the range:[0, 1]. + dtype + Attribute. + The data type for the elements of the output tensor. if not specified, + we will use the data type of the input tensor. + seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + + Returns + ======= + output : Var + Type T2. + The returned output tensor only has values 0 or 1, same shape as input + tensor. + + Notes + ===== + Signature: ``ai.onnx@15::Bernoulli``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Or( - _Or.Attributes( - ), _Or.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C + return ( + _Bernoulli( + _Bernoulli.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), + _Bernoulli.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def prelu(X: Var, slope: Var, ) -> Var: +def bit_shift( + X: Var, + Y: Var, + *, + direction: str, +) -> Var: r""" -PRelu takes input data (Tensor) and slope tensor as input, and -produces one output data (Tensor) where the function -``f(x) = slope * x for x < 0``, ``f(x) = x for x >= 0``., is applied to -the data tensor elementwise. This operator supports **unidirectional -broadcasting** (tensor slope should be unidirectional broadcastable to -input tensor X); for more details please check `the -doc `__. + Bitwise shift operator performs element-wise operation. For each input + element, if the attribute "direction" is "RIGHT", this operator moves + its binary representation toward the right side so that the input value + is effectively decreased. If the attribute "direction" is "LEFT", bits + of binary representation moves toward the left side, which results the + increase of its actual value. The input X is the tensor to be shifted + and another input Y specifies the amounts of shifting. For example, if + "direction" is "Right", X is [1, 4], and S is [1, 1], the corresponding + output Z would be [0, 2]. If "direction" is "LEFT" with X=[1, 2] and + S=[1, 2], the corresponding output Y would be [2, 8]. + + Because this operator supports Numpy-style broadcasting, X's and Y's + shapes are not necessarily identical. This operator supports + **multidirectional (i.e., Numpy-style) broadcasting**; for more details + please check `the + doc `__. + + Parameters + ========== + X + Type T. + First operand, input to be shifted. + Y + Type T. + Second operand, amounts of shift. + direction + Attribute. + Direction of moving bits. It can be either "RIGHT" (for right shift) or + "LEFT" (for left shift). + + Returns + ======= + Z : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@11::BitShift``. + + Type constraints: + - T: `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _BitShift( + _BitShift.Attributes( + direction=AttrString(direction, name="direction"), + ), + _BitShift.Inputs( + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + X=get_value(X), + Y=get_value(Y), + ) + .Z + ) -Parameters -========== -X - Type T. - Input tensor -slope - Type T. - Slope tensor. The shape of slope can be smaller than first input X; if - so, its shape must be unidirectional broadcastable to X - -Returns -======= -Y : Var - Type T. - Output tensor (same size as X) -Notes -===== -Signature: ``ai.onnx@16::PRelu``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _PRelu( - _PRelu.Attributes( - ), _PRelu.Inputs( - X=unwrap_vars(X), slope=unwrap_vars(slope), ), ).get_output_vars( - X=get_value(X), slope=get_value(slope), ).Y - - -def pad(data: Var, pads: Var, constant_value: Optional[Var] = None, *, mode: str = "constant", ) -> Var: - r""" -Given a tensor containing the data to be padded (``data``), a tensor -containing the number of start and end pad values for axis (``pads``), -(optionally) a ``mode``, and (optionally) ``constant_value``, a padded -tensor (``output``) is generated. - -The three supported ``modes`` are (similar to corresponding modes -supported by ``numpy.pad``): - -1) ``constant``\ (default) - pads with a given constant value as - specified by ``constant_value`` (which defaults to 0, empty string, - or False) - -2) ``reflect`` - pads with the reflection of the vector mirrored on the - first and last values of the vector along each axis - -3) ``edge`` - pads with the edge values of array - -Example 1 (``constant`` mode): Insert 0 pads to the beginning of the -second dimension. - -data = [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], ] - -pads = [0, 2, 0, 0] - -mode = 'constant' - -constant_value = 0.0 - -output = [ [0.0, 0.0, 1.0, 1.2], [0.0, 0.0, 2.3, 3.4], [0.0, 0.0, 4.5, -5.7], ] - -Example 2 (``reflect`` mode): data = [ [1.0, 1.2], [2.3, 3.4], [4.5, -5.7], ] - -pads = [0, 2, 0, 0] - -mode = 'reflect' - -output = [ [1.0, 1.2, 1.0, 1.2], [2.3, 3.4, 2.3, 3.4], [4.5, 5.7, 4.5, -5.7], ] - -Example 3 (``edge`` mode): data = [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], -] - -pads = [0, 2, 0, 0] - -mode = 'edge' - -output = [ [1.0, 1.0, 1.0, 1.2], [2.3, 2.3, 2.3, 3.4], [4.5, 4.5, 4.5, -5.7], ] - -Parameters -========== -data - Type T. - Input tensor. -pads - Type tensor(int64). - Tensor of integers indicating the number of padding elements to add or - remove (if negative) at the beginning and end of each axis. For 2D input - tensor, it is the number of pixels. ``pads`` should be a 1D tensor of - shape [2 \* input_rank]. ``pads`` format should be: [x1_begin, - x2_begin,...,x1_end, x2_end,...], where xi_begin is the number of pad - values added at the beginning of axis ``i`` and xi_end, the number of - pad values added at the end of axis ``i``. -constant_value - Type T. - (Optional) A scalar value to be used if the mode chosen is ``constant`` - (by default it is 0, empty string or False). -mode - Attribute. - Supported modes: ``constant``\ (default), ``reflect``, ``edge`` - -Returns -======= -output : Var - Type T. - Tensor after padding. - -Notes -===== -Signature: ``ai.onnx@13::Pad``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), _Pad.Inputs( - data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), ), ).get_output_vars( - data=get_value(data), pads=get_value(pads), constant_value=get_value(constant_value), ).output - - -def pow(X: Var, Y: Var, ) -> Var: - r""" -Pow takes input data (Tensor) and exponent Tensor, and produces one -output data (Tensor) where the function ``f(x) = x^exponent``, is -applied to the data tensor elementwise. This operator supports -**multidirectional (i.e., Numpy-style) broadcasting**; for more details -please check `the -doc `__. - -Parameters -========== -X - Type T. - First operand, base of the exponent. -Y - Type T1. - Second operand, power of the exponent. - -Returns -======= -Z : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@15::Pow``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)` - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Pow( - _Pow.Attributes( - ), _Pow.Inputs( - X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( - X=get_value(X), Y=get_value(Y), ).Z - - -def qlinear_conv(x: Var, x_scale: Var, x_zero_point: Var, w: Var, w_scale: Var, w_zero_point: Var, y_scale: Var, y_zero_point: Var, B: Optional[Var] = None, *, auto_pad: str = "NOTSET", dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: - r""" -The convolution operator consumes a quantized input tensor, its scale -and zero point, a quantized filter, its scale and zero point, and -output's scale and zero point, and computes the quantized output. Each -scale and zero-point pair must have same shape. It means they must be -either scalars (per tensor) or 1-D tensors (per output channel). Each -input or output and its related zero point must have same type. When -bias is present it must be quantized using scale = input scale \* weight -scale and zero point as 0. - -Parameters -========== -x - Type T1. - Input data tensor from previous layer; has size (N x C x H x W), where N - is the batch size, C is the number of channels, and H and W are the - height and width. Note that this is for the 2D image. Otherwise the size - is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in - effect, the operation expects input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. -x_scale - Type tensor(float). - Scale tensor for input 'x'. It's a scalar, which means a - per-tensor/layer quantization. -x_zero_point - Type T1. - Zero point tensor for input 'x'. It's a scalar, which means a - per-tensor/layer quantization. -w - Type T2. - The weight tensor that will be used in the convolutions; has size (M x - C/group x kH x kW), where C is the number of channels, and kH and kW are - the height and width of the kernel, and M is the number of feature maps. - For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x - k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. - Optionally, if dimension denotation is in effect, the operation expects - the weight tensor to arrive with the dimension denotation of - [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL - ...]. X.shape[1] == (W.shape[1] \* group) == C (assuming zero based - indices for the shape array). Or in other words FILTER_IN_CHANNEL should - be equal to DATA_CHANNEL. -w_scale - Type tensor(float). - Scale tensor for input 'w'. It could be a scalar or a 1-D tensor, which - means a per-tensor/layer or per output channel quantization. If it's a - 1-D tensor, its number of elements should be equal to the number of - output channels (M). -w_zero_point - Type T2. - Zero point tensor for input 'w'. It could be a scalar or a 1-D tensor, - which means a per-tensor/layer or per output channel quantization. If - it's a 1-D tensor, its number of elements should be equal to the number - of output channels (M). -y_scale - Type tensor(float). - Scale tensor for output 'y'. It's a scalar, which means a - per-tensor/layer quantization. -y_zero_point - Type T3. - Zero point tensor for output 'y'. It's a scalar, which means a - per-tensor/layer quantization. -B - Type T4. - Optional 1D bias to be added to the convolution, has size of M. Bias - must be quantized using scale = x_scale \* w_scale and zero_point = 0 -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. -dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults to 1 along each spatial axis. -group - Attribute. - number of groups input channels and output channels are divided into. - default is 1. -kernel_shape - Attribute. - The shape of the convolution kernel. If not present, should be inferred - from input 'w'. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0.The value represent the number - of pixels added to the beginning and end part of the corresponding - axis.\ ``pads`` format should be as follow [x1_begin, x2_begin...x1_end, - x2_end,...], where xi_begin the number ofpixels added at the beginning - of axis ``i`` and xi_end, the number of pixels added at the end of axis - ``i``.This attribute cannot be used simultaneously with auto_pad - attribute. If not present, the padding defaultsto 0 along start and end - of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - -Returns -======= -y : Var - Type T3. - Output data tensor that contains the result of the convolution. The - output dimensions are functions of the kernel size, stride size, and pad - lengths. - -Notes -===== -Signature: ``ai.onnx@10::QLinearConv``. - -Type constraints: - - T1: `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(int8)`, `tensor(uint8)` - - T4: `tensor(int32)` - """ - return _QLinearConv( - _QLinearConv.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _QLinearConv.Inputs( - x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), w=unwrap_vars(w), w_scale=unwrap_vars(w_scale), w_zero_point=unwrap_vars(w_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), B=unwrap_vars(B), ), ).get_output_vars( - x=get_value(x), x_scale=get_value(x_scale), x_zero_point=get_value(x_zero_point), w=get_value(w), w_scale=get_value(w_scale), w_zero_point=get_value(w_zero_point), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), B=get_value(B), ).y - - -def qlinear_matmul(a: Var, a_scale: Var, a_zero_point: Var, b: Var, b_scale: Var, b_zero_point: Var, y_scale: Var, y_zero_point: Var, ) -> Var: - r""" -Matrix product that behaves like numpy.matmul: -https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. -It consumes two quantized input tensors, their scales and zero points, -scale and zero point of output, and computes the quantized output. The -quantization formula is y = saturate((x / y_scale) + y_zero_point). For -(x / y_scale), it is rounding to nearest ties to even. Refer to -https://en.wikipedia.org/wiki/Rounding for details. Scale and zero point -must have same shape. They must be either scalar (per tensor) or N-D -tensor (per row for 'a' and per column for 'b'). Scalar refers to per -tensor quantization whereas N-D refers to per row or per column -quantization. If the input is 2D of shape [M, K] then zero point and -scale tensor may be an M element vector [v_1, v_2, ..., v_M] for per row -quantization and K element vector of shape [v_1, v_2, ..., v_K] for per -column quantization. If the input is N-D tensor with shape [D1, D2, M, -K] then zero point and scale tensor may have shape [D1, D2, M, 1] for -per row quantization and shape [D1, D2, 1, K] for per column -quantization. Production must never overflow, and accumulation may -overflow if and only if in 32 bits. - -Parameters -========== -a - Type T1. - N-dimensional quantized matrix a -a_scale - Type tensor(float). - scale of quantized input a -a_zero_point - Type T1. - zero point of quantized input a -b - Type T2. - N-dimensional quantized matrix b -b_scale - Type tensor(float). - scale of quantized input b -b_zero_point - Type T2. - zero point of quantized input b -y_scale - Type tensor(float). - scale of quantized output y -y_zero_point - Type T3. - zero point of quantized output y - -Returns -======= -y : Var - Type T3. - Quantized matrix multiply results from a \* b - -Notes -===== -Signature: ``ai.onnx@10::QLinearMatMul``. - -Type constraints: - - T1: `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(int8)`, `tensor(uint8)` - """ - return _QLinearMatMul( - _QLinearMatMul.Attributes( - ), _QLinearMatMul.Inputs( - a=unwrap_vars(a), a_scale=unwrap_vars(a_scale), a_zero_point=unwrap_vars(a_zero_point), b=unwrap_vars(b), b_scale=unwrap_vars(b_scale), b_zero_point=unwrap_vars(b_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( - a=get_value(a), a_scale=get_value(a_scale), a_zero_point=get_value(a_zero_point), b=get_value(b), b_scale=get_value(b_scale), b_zero_point=get_value(b_zero_point), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y - - -def quantize_linear(x: Var, y_scale: Var, y_zero_point: Optional[Var] = None, *, axis: int = 1, ) -> Var: - r""" -The linear quantization operator. It consumes a high precision tensor, a -scale, and a zero point to compute the low precision / quantized tensor. -The scale factor and zero point must have same shape, and can be either -a scalar for per-tensor / per layer quantization, or a 1-D tensor for -per-axis quantization. The quantization formula is y = saturate ((x / -y_scale) + y_zero_point). For saturation, it saturates to [0, 255] if -it's uint8, or [-128, 127] if it's int8. For (x / y_scale), it's -rounding to the nearest even. Refer to -https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and -'y' must have same type. - -Parameters -========== -x - Type T1. - N-D full precision Input tensor to be quantized. -y_scale - Type tensor(float). - Scale for doing quantization to get 'y'. It can be a scalar, which means - per-tensor/layer quantization, or a 1-D Tensor for per-axis - quantization. -y_zero_point - Type T2. - Zero point for doing quantization to get 'y'. Shape must match y_scale. - Default is uint8 with zero point of 0 if it's not specified. -axis - Attribute. - (Optional) The axis of the quantization dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - -Returns -======= -y : Var - Type T2. - N-D quantized output tensor. It has same shape as input 'x'. - -Notes -===== -Signature: ``ai.onnx@13::QuantizeLinear``. - -Type constraints: - - T1: `tensor(float)`, `tensor(int32)` - - T2: `tensor(int8)`, `tensor(uint8)` - """ - return _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _QuantizeLinear.Inputs( - x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( - x=get_value(x), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y - - -def rnn(X: Var, W: Var, R: Var, B: Optional[Var] = None, sequence_lens: Optional[Var] = None, initial_h: Optional[Var] = None, *, activation_alpha: Optional[Iterable[float]] = None, activation_beta: Optional[Iterable[float]] = None, activations: Iterable[str] = ('Tanh', 'Tanh'), clip: Optional[float] = None, direction: str = "forward", hidden_size: Optional[int] = None, layout: int = 0, ) -> tuple[Var, Var]: - r""" -Computes an one-layer simple RNN. This operator is usually supported via -some custom implementation such as CuDNN. - -Notations: - -- ``X`` - input tensor -- ``i`` - input gate -- ``t`` - time step (t-1 means previous time step) -- ``Wi`` - W parameter weight matrix for input gate -- ``Ri`` - R recurrence weight matrix for input gate -- ``Wbi`` - W parameter bias vector for input gate -- ``Rbi`` - R parameter bias vector for input gate -- ``WBi`` - W parameter weight matrix for backward input gate -- ``RBi`` - R recurrence weight matrix for backward input gate -- ``WBbi`` - WR bias vectors for backward input gate -- ``RBbi`` - RR bias vectors for backward input gate -- ``H`` - Hidden state -- ``num_directions`` - 2 if direction == bidirectional else 1 - -Activation functions: - -- Relu(x) - max(0, x) -- Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) -- Sigmoid(x) - 1/(1 + e^{-x}) - -NOTE: Below are optional - -- Affine(x) - alpha*x + beta -- LeakyRelu(x) - x if x >= 0 else alpha \* x -- ThresholdedRelu(x) - x if x >= alpha else 0 -- ScaledTanh(x) - alpha\ *Tanh(beta*\ x) -- HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) -- Elu(x) - x if x >= 0 else alpha*(e^x - 1) -- Softsign(x) - x/(1 + \|x\|) -- Softplus(x) - log(1 + e^x) - -Equations (Default: f=Tanh): - -- Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has - **optional** inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. - -Parameters -========== -X - Type T. - The input sequences packed (and potentially padded) into one 3-D tensor - with the shape of ``[seq_length, batch_size, input_size]``. -W - Type T. - The weight tensor for input gate. Concatenation of ``Wi`` and ``WBi`` - (if bidirectional). The tensor has shape - ``[num_directions, hidden_size, input_size]``. -R - Type T. - The recurrence weight tensor. Concatenation of ``Ri`` and ``RBi`` (if - bidirectional). The tensor has shape - ``[num_directions, hidden_size, hidden_size]``. -B - Type T. - The bias tensor for input gate. Concatenation of ``[Wbi, Rbi]`` and - ``[WBbi, RBbi]`` (if bidirectional). The tensor has shape - ``[num_directions, 2*hidden_size]``. Optional: If not specified - - assumed to be 0. -sequence_lens - Type T1. - Optional tensor specifying lengths of the sequences in a batch. If not - specified - assumed all sequences in the batch to have length - ``seq_length``. It has shape ``[batch_size]``. -initial_h - Type T. - Optional initial value of the hidden. If not specified - assumed to be - 0. It has shape ``[num_directions, batch_size, hidden_size]``. -activation_alpha - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX - operators.For example with LeakyRelu, the default alpha is 0.01. -activation_beta - Attribute. - Optional scaling values used by some activation functions. The values - are consumed in the order of activation functions, for example (f, g, h) - in LSTM. Default values are the same as of corresponding ONNX operators. -activations - Attribute. - One (or two if bidirectional) activation function for input gate. The - activation function must be one of the activation functions specified - above. Optional: Default ``Tanh`` if not specified. -clip - Attribute. - Cell clip threshold. Clipping bounds the elements of a tensor in the - range of [-threshold, +threshold] and is applied to the input of - activations. No clip if not specified. -direction - Attribute. - Specify if the RNN is forward, reverse, or bidirectional. Must be one of - forward (default), reverse, or bidirectional. -hidden_size - Attribute. - Number of neurons in the hidden layer -layout - Attribute. - The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the - following shapes are expected: X.shape = [seq_length, batch_size, - input_size], Y.shape = [seq_length, num_directions, batch_size, - hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, - hidden_size]. If 1, the following shapes are expected: X.shape = - [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, - num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, - num_directions, hidden_size]. - -Returns -======= -Y : Var - Type T. - A tensor that concats all the intermediate output values of the hidden. - It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. -Y_h : Var - Type T. - The last output value of the hidden. It has shape - ``[num_directions, batch_size, hidden_size]``. - -Notes -===== -Signature: ``ai.onnx@14::RNN``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T1: `tensor(int32)` - """ - return _RNN( - _RNN.Attributes( - activation_alpha=AttrFloat32s.maybe(activation_alpha, name="activation_alpha"), - activation_beta=AttrFloat32s.maybe(activation_beta, name="activation_beta"), - activations=AttrStrings(activations, name="activations"), - clip=AttrFloat32.maybe(clip, name="clip"), - direction=AttrString(direction, name="direction"), - hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), - layout=AttrInt64(layout, name="layout"), - ), _RNN.Inputs( - X=unwrap_vars(X), W=unwrap_vars(W), R=unwrap_vars(R), B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), ), ).get_output_vars( - X=get_value(X), W=get_value(W), R=get_value(R), B=get_value(B), sequence_lens=get_value(sequence_lens), initial_h=get_value(initial_h), )._unpack_to_any() - - -def random_normal(*, dtype: npt.DTypeLike = np.float32, mean: float = 0.0, scale: float = 1.0, seed: Optional[float] = None, shape: Iterable[int], ) -> Var: - r""" -Generate a tensor with random values drawn from a normal distribution. -The shape of the tensor is specified by the ``shape`` argument and the -parameter of the normal distribution specified by ``mean`` and -``scale``. - -The data type is specified by the 'dtype' argument. The 'dtype' argument -must be one of the data types specified in the 'DataType' enum field in -the TensorProto message. - -Parameters -========== -dtype - Attribute. - The data type for the elements of the output tensor. Default is - TensorProto::FLOAT. -mean - Attribute. - The mean of the normal distribution. -scale - Attribute. - The standard deviation of the normal distribution. -seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. -shape - Attribute. - The shape of the output tensor. - -Returns -======= -output : Var - Type T. - Output tensor of random values drawn from normal distribution - -Notes -===== -Signature: ``ai.onnx@1::RandomNormal``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _RandomNormal( - _RandomNormal.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - mean=AttrFloat32(mean, name="mean"), - scale=AttrFloat32(scale, name="scale"), - seed=AttrFloat32.maybe(seed, name="seed"), - shape=AttrInt64s(shape, name="shape"), - ), _RandomNormal.Inputs( - ), ).get_output_vars( - ).output - - -def random_normal_like(input: Var, *, dtype: Optional[npt.DTypeLike] = None, mean: float = 0.0, scale: float = 1.0, seed: Optional[float] = None, ) -> Var: - r""" -Generate a tensor with random values drawn from a normal distribution. -The shape of the output tensor is copied from the shape of the input -tensor, and the parameters of the normal distribution are specified by -``mean`` and ``scale``. - -The data type is specified by the 'dtype' argument, or copied from the -input tensor if not provided. The 'dtype' argument must be one of the -data types specified in the 'DataType' enum field in the TensorProto -message, and be valid as an output type. - -Parameters -========== -input - Type T1. - Input tensor to copy shape and optionally type information from. -dtype - Attribute. - (Optional) The data type for the elements of the output tensor, if not - specified, we will use the data type of the input tensor. -mean - Attribute. - The mean of the normal distribution. -scale - Attribute. - The standard deviation of the normal distribution. -seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - -Returns -======= -output : Var - Type T2. - Output tensor of random values drawn from normal distribution - -Notes -===== -Signature: ``ai.onnx@1::RandomNormalLike``. - -Type constraints: - - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _RandomNormalLike( - _RandomNormalLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - mean=AttrFloat32(mean, name="mean"), - scale=AttrFloat32(scale, name="scale"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), _RandomNormalLike.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def random_uniform(*, dtype: npt.DTypeLike = np.float32, high: float = 1.0, low: float = 0.0, seed: Optional[float] = None, shape: Iterable[int], ) -> Var: - r""" -Generate a tensor with random values drawn from a uniform distribution. -The shape of the tensor is specified by the ``shape`` argument and the -range by ``low`` and ``high``. - -The data type is specified by the 'dtype' argument. The 'dtype' argument -must be one of the data types specified in the 'DataType' enum field in -the TensorProto message. - -Parameters -========== -dtype - Attribute. - The data type for the elements of the output tensor. If not specified, - default is TensorProto::FLOAT. -high - Attribute. - Upper boundary of the output values. -low - Attribute. - Lower boundary of the output values. -seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. -shape - Attribute. - The shape of the output tensor. - -Returns -======= -output : Var - Type T. - Output tensor of random values drawn from uniform distribution - -Notes -===== -Signature: ``ai.onnx@1::RandomUniform``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _RandomUniform( - _RandomUniform.Attributes( - dtype=AttrDtype(dtype, name="dtype"), - high=AttrFloat32(high, name="high"), - low=AttrFloat32(low, name="low"), - seed=AttrFloat32.maybe(seed, name="seed"), - shape=AttrInt64s(shape, name="shape"), - ), _RandomUniform.Inputs( - ), ).get_output_vars( - ).output - - -def random_uniform_like(input: Var, *, dtype: Optional[npt.DTypeLike] = None, high: float = 1.0, low: float = 0.0, seed: Optional[float] = None, ) -> Var: - r""" -Generate a tensor with random values drawn from a uniform distribution. -The shape of the output tensor is copied from the shape of the input -tensor, and the parameters of the uniform distribution are specified by -``low`` and ``high``. - -The data type is specified by the 'dtype' argument, or copied from the -input tensor if not provided. The 'dtype' argument must be one of the -data types specified in the 'DataType' enum field in the TensorProto -message and be valid as an output type. - -Parameters -========== -input - Type T1. - Input tensor to copy shape and optionally type information from. -dtype - Attribute. - (Optional) The data type for the elements of the output tensor, if not - specified, we will use the data type of the input tensor. -high - Attribute. - Upper boundary of the output values. -low - Attribute. - Lower boundary of the output values. -seed - Attribute. - (Optional) Seed to the random generator, if not specified we will auto - generate one. - -Returns -======= -output : Var - Type T2. - Output tensor of random values drawn from uniform distribution - -Notes -===== -Signature: ``ai.onnx@1::RandomUniformLike``. - -Type constraints: - - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _RandomUniformLike( - _RandomUniformLike.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - high=AttrFloat32(high, name="high"), - low=AttrFloat32(low, name="low"), - seed=AttrFloat32.maybe(seed, name="seed"), - ), _RandomUniformLike.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def range(start: Var, limit: Var, delta: Var, ) -> Var: - r""" -Generate a tensor containing a sequence of numbers that begin at -``start`` and extends by increments of ``delta`` up to ``limit`` -(exclusive). - -The number of elements in the output of range is computed as below: - -:: - - number_of_elements = max( ceil( (limit - start) / delta ) , 0 ) - -The pseudocode determining the contents of the output is shown below: - -:: - - for(int i=0; i Var: - r""" -Reciprocal takes one input data (Tensor) and produces one output data -(Tensor) where the reciprocal is, y = 1/x, is applied to the tensor -elementwise. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@13::Reciprocal``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Reciprocal( - _Reciprocal.Attributes( - ), _Reciprocal.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def reduce_l1(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the L1 norm of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields 0. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceL1``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _ReduceL1( - _ReduceL1.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceL1.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def reduce_l2(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the L2 norm of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields 0. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceL2``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _ReduceL2( - _ReduceL2.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceL2.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def reduce_log_sum(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the log sum of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields minus infinity (if -supported by the datatype) or undefined otherwise. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceLogSum``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _ReduceLogSum( - _ReduceLogSum.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceLogSum.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def reduce_log_sum_exp(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the log sum exponent of the input tensor's elements along the -provided axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields minus infinity (if -supported by the datatype) or undefined otherwise. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceLogSumExp``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _ReduceLogSumExp( - _ReduceLogSumExp.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceLogSumExp.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def reduce_max(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the max of the input tensor's elements along the provided axes. -The resulting tensor has the same rank as the input if ``keepdims`` -equals 1. If ``keepdims`` equals 0, then the resulting tensor has the -reduced dimension pruned. Input tensors of rank zero are valid. -Reduction over an empty set of values yields minus infinity (if -supported by the datatype) or the minimum value of the data type -otherwise. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceMax``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _ReduceMax( - _ReduceMax.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceMax.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def reduce_mean(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the mean of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields undefined. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceMean``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _ReduceMean( - _ReduceMean.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceMean.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def reduce_min(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the min of the input tensor's elements along the provided axes. -The resulting tensor has the same rank as the input if ``keepdims`` -equals 1. If ``keepdims`` equals 0, then the resulting tensor has the -reduced dimension pruned. Input tensors of rank zero are valid. -Reduction over an empty set of values yields plus infinity (if supported -by the datatype) or the maximum value of the data type otherwise. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceMin``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _ReduceMin( - _ReduceMin.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceMin.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def reduce_prod(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the product of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields 1. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceProd``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _ReduceProd( - _ReduceProd.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceProd.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def reduce_sum(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: - r""" -Computes the sum of the input tensor's elements along the provided axes. -The resulting tensor has the same rank as the input if ``keepdims`` -equals 1. If ``keepdims`` equals 0, then the resulting tensor has the -reduced dimension pruned. Input tensors of rank zero are valid. -Reduction over an empty set of values yields 0. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceSum``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _ReduceSum( - _ReduceSum.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceSum.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_sum_square(data: Var, *, axes: Optional[Iterable[int]] = None, keepdims: int = 1, ) -> Var: - r""" -Computes the sum square of the input tensor's elements along the -provided axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields 0. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Attribute. - A list of integers, along which to reduce. The default is to reduce over - all the dimensions of the input tensor. Accepted range is [-r, r-1] - where r = rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@13::ReduceSumSquare``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - """ - return _ReduceSumSquare( - _ReduceSumSquare.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _ReduceSumSquare.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).reduced - - -def relu(X: Var, ) -> Var: - r""" -Relu takes one input data (Tensor) and produces one output data -(Tensor) where the rectified linear function, y = max(0, x), is -applied to the tensor elementwise. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@14::Relu``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` - """ - return _Relu( - _Relu.Attributes( - ), _Relu.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def reshape(data: Var, shape: Var, *, allowzero: int = 0, ) -> Var: - r""" -Reshape the input tensor similar to numpy.reshape. First input is the -data tensor, second input is a shape tensor which specifies the output -shape. It outputs the reshaped tensor. At most one dimension of the new -shape can be -1. In this case, the value is inferred from the size of -the tensor and the remaining dimensions. A dimension could also be 0, in -which case the actual dimension value is unchanged (i.e. taken from the -input tensor). If 'allowzero' is set, and the new shape includes 0, the -dimension will be set explicitly to zero (i.e. not taken from input -tensor). Shape (second input) could be an empty shape, which means -converting to a scalar. The input tensor's shape and the output tensor's -shape are required to have the same number of elements. - -If the attribute 'allowzero' is set, it is invalid for the specified -shape to contain both a zero value and -1, as the value of the dimension -corresponding to -1 cannot be determined uniquely. - -Parameters -========== -data - Type T. - An input tensor. -shape - Type tensor(int64). - Specified shape for output. -allowzero - Attribute. - (Optional) By default, when any value in the 'shape' input is equal to - zero the corresponding dimension value is copied from the input tensor - dynamically. allowzero=1 indicates that if any value in the 'shape' - input is set to zero, the zero value is honored, similar to NumPy. - -Returns -======= -reshaped : Var - Type T. - Reshaped data. - -Notes -===== -Signature: ``ai.onnx@14::Reshape``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), _Reshape.Inputs( - data=unwrap_vars(data), shape=unwrap_vars(shape), ), ).get_output_vars( - data=get_value(data), shape=get_value(shape), ).reshaped - - -def resize(X: Var, roi: Optional[Var] = None, scales: Optional[Var] = None, sizes: Optional[Var] = None, *, coordinate_transformation_mode: str = "half_pixel", cubic_coeff_a: float = -0.75, exclude_outside: int = 0, extrapolation_value: float = 0.0, mode: str = "nearest", nearest_mode: str = "round_prefer_floor", ) -> Var: - r""" -Resize the input tensor. In general, it calculates every value in the -output tensor as a weighted average of neighborhood (a.k.a. sampling -locations) in the input tensor. Each dimension value of the output -tensor is: output_dimension = floor(input_dimension \* (roi_end - -roi_start) \* scale) if input "sizes" is not specified. - -Parameters -========== -X - Type T1. - N-D tensor -roi - Type T2. - 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is - the rank of X. The RoIs' coordinates are normalized in the coordinate - system of the input image. It only takes effect when - coordinate_transformation_mode is "tf_crop_and_resize" -scales - Type tensor(float). - The scale array along each dimension. It takes value greater than 0. If - it's less than 1, it's sampling down, otherwise, it's upsampling. The - number of elements of 'scales' should be the same as the rank of input - 'X'. One of 'scales' and 'sizes' MUST be specified and it is an error if - both are specified. If 'sizes' is needed, the user can use an empty - string as the name of 'scales' in this operator's input list. -sizes - Type tensor(int64). - The size of the output tensor. The number of elements of 'sizes' should - be the same as the rank of input 'X'. Only one of 'scales' and 'sizes' - can be specified. -coordinate_transformation_mode - Attribute. - This attribute describes how to transform the coordinate in the resized - tensor to the coordinate in the original tensor. - - The coordinate of each dimension is transformed individually. Let's - describe a case using axis x as an example. Denote x_resized as the - coordinate of axis x in the resized tensor, x_original as the coordinate - of axis x in the original tensor, length_original as the length of the - original tensor in axis x, length_resized as the length of the resized - tensor in axis x, roi_x = (start_x, end_x) of the axis x in input "roi", - scale = length_resized / length_original, - - if coordinate_transformation_mode is "half_pixel", x_original = - (x_resized + 0.5) / scale - 0.5, - - if coordinate_transformation_mode is "pytorch_half_pixel", x_original = - length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0, - - if coordinate_transformation_mode is "align_corners", x_original = - x_resized \* (length_original - 1) / (length_resized - 1), - - if coordinate_transformation_mode is "asymmetric", x_original = - x_resized / scale, - - if coordinate_transformation_mode is "tf_crop_and_resize", x_original = - length_resized > 1 ? start_x \* (length_original - 1) + x_resized \* - (end_x - start_x) \* (length_original - 1) / (length_resized - 1) : 0.5 - \* (start_x + end_x) \* (length_original - 1). -cubic_coeff_a - Attribute. - The coefficient 'a' used in cubic interpolation. Two common choice are - -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out - Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the - details. This attribute is valid only if "mode" is "cubic". -exclude_outside - Attribute. - If set to 1, the weight of sampling locations outside the tensor will be - set to 0 and the weight will be renormalized so that their sum is 1.0. - The default value is 0. -extrapolation_value - Attribute. - When coordinate_transformation_mode is "tf_crop_and_resize" and - x_original is outside the range [0, length_original - 1], this value is - used as the corresponding output value. Default is 0.0f. -mode - Attribute. - Three interpolation modes: nearest (default), linear and cubic. The - "linear" mode includes linear interpolation for 1D tensor and N-linear - interpolation for N-D tensor (for example, bilinear interpolation for 2D - tensor). The "cubic" mode includes cubic interpolation for 1D tensor and - N-cubic interpolation for N-D tensor (for example, bicubic interpolation - for 2D tensor). -nearest_mode - Attribute. - Four modes: round_prefer_floor (default, as known as round half down), - round_prefer_ceil (as known as round half up), floor, ceil. Only used by - nearest interpolation. It indicates how to get "nearest" pixel in input - tensor from x_original, so this attribute is valid only if "mode" is - "nearest". - -Returns -======= -Y : Var - Type T1. - N-D tensor after resizing - -Notes -===== -Signature: ``ai.onnx@13::Resize``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Resize( - _Resize.Attributes( - coordinate_transformation_mode=AttrString(coordinate_transformation_mode, name="coordinate_transformation_mode"), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32(extrapolation_value, name="extrapolation_value"), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), _Resize.Inputs( - X=unwrap_vars(X), roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), ).get_output_vars( - X=get_value(X), roi=get_value(roi), scales=get_value(scales), sizes=get_value(sizes), ).Y - - -def reverse_sequence(input: Var, sequence_lens: Var, *, batch_axis: int = 1, time_axis: int = 0, ) -> Var: - r""" -Reverse batch of sequences having different lengths specified by -``sequence_lens``. - -For each slice i iterating on batch axis, the operator reverses the -first sequence_lens[i] elements on time axis, and copies elements whose -index's beyond sequence_lens[i] to the output. So the output slice i -contains reversed sequences on the first sequence_lens[i] elements, then -have original values copied for the other elements. - -Example 1: input = [[0.0, 4.0, 8.0, 12.0], [1.0, 5.0, 9.0, 13.0], [2.0, -6.0, 10.0, 14.0], [3.0, 7.0, 11.0, 15.0]] sequence_lens = [4, 3, 2, 1] -time_axis = 0 batch_axis = 1 - -output = [[3.0, 6.0, 9.0, 12.0], [2.0, 5.0, 8.0, 13.0], [1.0, 4.0, 10.0, -14.0], [0.0, 7.0, 11.0, 15.0]] - -Example 2: input = [[0.0, 1.0, 2.0, 3.0 ], [4.0, 5.0, 6.0, 7.0 ], [8.0, -9.0, 10.0, 11.0], [12.0, 13.0, 14.0, 15.0]] sequence_lens = [1, 2, 3, 4] -time_axis = 1 batch_axis = 0 - -output = [[0.0, 1.0, 2.0, 3.0 ], [5.0, 4.0, 6.0, 7.0 ], [10.0, 9.0, 8.0, -11.0], [15.0, 14.0, 13.0, 12.0]] - -Parameters -========== -input - Type T. - Tensor of rank r >= 2. -sequence_lens - Type tensor(int64). - Tensor specifying lengths of the sequences in a batch. It has shape - ``[batch_size]``. -batch_axis - Attribute. - (Optional) Specify which axis is batch axis. Must be one of 1 (default), - or 0. -time_axis - Attribute. - (Optional) Specify which axis is time axis. Must be one of 0 (default), - or 1. - -Returns -======= -Y : Var - Type T. - Tensor with same shape of input. - -Notes -===== -Signature: ``ai.onnx@10::ReverseSequence``. - -Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _ReverseSequence( - _ReverseSequence.Attributes( - batch_axis=AttrInt64(batch_axis, name="batch_axis"), - time_axis=AttrInt64(time_axis, name="time_axis"), - ), _ReverseSequence.Inputs( - input=unwrap_vars(input), sequence_lens=unwrap_vars(sequence_lens), ), ).get_output_vars( - input=get_value(input), sequence_lens=get_value(sequence_lens), ).Y - - -def roi_align(X: Var, rois: Var, batch_indices: Var, *, coordinate_transformation_mode: str = "half_pixel", mode: str = "avg", output_height: int = 1, output_width: int = 1, sampling_ratio: int = 0, spatial_scale: float = 1.0, ) -> Var: - r""" -Region of Interest (RoI) align operation described in the `Mask R-CNN -paper `__. RoiAlign consumes an input -tensor X and region of interests (rois) to apply pooling across each -RoI; it produces a 4-D tensor of shape (num_rois, C, output_height, -output_width). - -RoiAlign is proposed to avoid the misalignment by removing quantizations -while converting from original image into feature map and from feature -map into RoI feature; in each ROI bin, the value of the sampled -locations are computed directly through bilinear interpolation. - -Parameters -========== -X - Type T1. - Input data tensor from the previous operator; 4-D feature map of shape - (N, C, H, W), where N is the batch size, C is the number of channels, - and H and W are the height and the width of the data. -rois - Type T1. - RoIs (Regions of Interest) to pool over; rois is 2-D input of shape - (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates - are in the coordinate system of the input image. Each coordinate set has - a 1:1 correspondence with the 'batch_indices' input. -batch_indices - Type T2. - 1-D tensor of shape (num_rois,) with each element denoting the index of - the corresponding image in the batch. -coordinate_transformation_mode - Attribute. - Allowed values are 'half_pixel' and 'output_half_pixel'. Use the value - 'half_pixel' to pixel shift the input coordinates by -0.5 (the - recommended behavior). Use the value 'output_half_pixel' to omit the - pixel shift for the input (use this for a backward-compatible behavior). -mode - Attribute. - The pooling method. Two modes are supported: 'avg' and 'max'. Default is - 'avg'. -output_height - Attribute. - default 1; Pooled output Y's height. -output_width - Attribute. - default 1; Pooled output Y's width. -sampling_ratio - Attribute. - Number of sampling points in the interpolation grid used to compute the - output value of each pooled output bin. If > 0, then exactly - sampling_ratio x sampling_ratio grid points are used. If == 0, then an - adaptive number of grid points are used (computed as ceil(roi_width / - output_width), and likewise for height). Default is 0. -spatial_scale - Attribute. - Multiplicative spatial scale factor to translate ROI coordinates from - their input spatial scale to the scale used when pooling, i.e., spatial - scale of the input feature map X relative to the input image. E.g.; - default is 1.0f. - -Returns -======= -Y : Var - Type T1. - RoI pooled output, 4-D tensor of shape (num_rois, C, output_height, - output_width). The r-th batch element Y[r-1] is a pooled feature map - corresponding to the r-th RoI X[r-1]. - -Notes -===== -Signature: ``ai.onnx@16::RoiAlign``. - -Type constraints: - - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int64)` - """ - return _RoiAlign( - _RoiAlign.Attributes( - coordinate_transformation_mode=AttrString(coordinate_transformation_mode, name="coordinate_transformation_mode"), - mode=AttrString(mode, name="mode"), - output_height=AttrInt64(output_height, name="output_height"), - output_width=AttrInt64(output_width, name="output_width"), - sampling_ratio=AttrInt64(sampling_ratio, name="sampling_ratio"), - spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), - ), _RoiAlign.Inputs( - X=unwrap_vars(X), rois=unwrap_vars(rois), batch_indices=unwrap_vars(batch_indices), ), ).get_output_vars( - X=get_value(X), rois=get_value(rois), batch_indices=get_value(batch_indices), ).Y - - -def round(X: Var, ) -> Var: - r""" -Round takes one input Tensor and rounds the values, element-wise, -meaning it finds the nearest integer for each value. In case of halves, -the rule is to round them to the nearest even integer. If input x is -integral, +0, -0, NaN, or infinite, x itself is returned. The output -tensor has the same shape and type as the input. - -Examples: - -:: - - round([0.9]) = [1.0] - round([2.5]) = [2.0] - round([2.3]) = [2.0] - round([1.5]) = [2.0] - round([-4.5]) = [-4.0] - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@11::Round``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Round( - _Round.Attributes( - ), _Round.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def stft(signal: Var, frame_step: Var, window: Optional[Var] = None, frame_length: Optional[Var] = None, *, onesided: int = 1, ) -> Var: - r""" -Computes the Short-time Fourier Transform of the signal. - -Parameters -========== -signal - Type T1. - Input tensor representing a real or complex valued signal. For real - input, the following shape is expected: [batch_size][signal_length][1]. - For complex input, the following shape is expected: - [batch_size][signal_length][2], where [batch_size][signal_length][0] - represents the real component and [batch_size][signal_length][1] - represents the imaginary component of the signal. -frame_step - Type T2. - The number of samples to step between successive DFTs. -window - Type T1. - A tensor representing the window that will be slid over the signal.The - window must have rank 1 with shape: [window_shape]. It's an optional - value. -frame_length - Type T2. - A scalar representing the size of the DFT. It's an optional value. -onesided - Attribute. - If onesided is 1, only values for w in [0, 1, 2, ..., floor(n_fft/2) + - 1] are returned because the real-to-complex Fourier transform satisfies - the conjugate symmetry, i.e., X[m, w] = X[m,w]=X[m,n_fft-w]\*. Note if - the input or window tensors are complex, then onesided output is not - possible. Enabling onesided with real inputs performs a Real-valued fast - Fourier transform (RFFT).When invoked with real or complex valued input, - the default value is 1. Values can be 0 or 1. - -Returns -======= -output : Var - Type T1. - The Short-time Fourier Transform of the signals.If onesided is 1, the - output has the shape: [batch_size][frames][dft_unique_bins][2], where - dft_unique_bins is frame_length // 2 + 1 (the unique components of the - DFT) If onesided is 0, the output has the shape: - [batch_size][frames][frame_length][2], where frame_length is the length - of the DFT. - -Notes -===== -Signature: ``ai.onnx@17::STFT``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return _STFT( - _STFT.Attributes( - onesided=AttrInt64(onesided, name="onesided"), - ), _STFT.Inputs( - signal=unwrap_vars(signal), frame_step=unwrap_vars(frame_step), window=unwrap_vars(window), frame_length=unwrap_vars(frame_length), ), ).get_output_vars( - signal=get_value(signal), frame_step=get_value(frame_step), window=get_value(window), frame_length=get_value(frame_length), ).output - - -def scan(initial_state_and_scan_inputs: Sequence[Var], *, body: Callable[..., Iterable[Var]], num_scan_inputs: int, scan_input_axes: Optional[Iterable[int]] = None, scan_input_directions: Optional[Iterable[int]] = None, scan_output_axes: Optional[Iterable[int]] = None, scan_output_directions: Optional[Iterable[int]] = None, ) -> Sequence[Var]: - r""" -Scan can be used to iterate over one or more scan_input tensors, -constructing zero or more scan_output tensors. It combines ideas from -general recurrences, functional programming constructs such as scan, -fold, map, and zip, and is intended to enable generalizations of -RNN-like constructs for sequence-to-sequence processing. Other tensors -(referred to as state_variables here) can be used to carry a state when -iterating from one element to another (similar to hidden-state in RNNs, -also referred to as loop-carried dependences in the context of loops). -Many common usages involve a single scan_input tensor (where -functionality similar to scan, fold and map can be obtained). When more -than one scan_input is used, a behavior similar to zip is obtained. - -The attribute body must be a graph, specifying the computation to be -performed in every iteration. It takes as input the current values of -the state_variables and the current iterated element of the scan_inputs. -It must return the (updated) values of the state_variables and zero or -more scan_output_element tensors. The values of the scan_output_element -tensors are concatenated over all the iterations to produce the -scan_output values of the scan construct (similar to the concatenated -intermediate hidden-state values of RNN-like constructs). All the output -tensors (state_variables as well as scan_output_element tensors) are -required to have the same shape in each iteration of the loop (a -restriction imposed to enable efficient memory allocation). - -Note that the iterated element passed to the body subgraph does not have -a sequence axis. It will have a rank one less than the rank of the -corresponding scan_input. - -The scan operation returns the final values of the state_variables as -well as the scan_outputs. - -The optional attribute scan_input_directions specifies the direction -(forward or backward) for each scan input. If this attribute is omitted, -all sequences are scanned in the forward direction. A bidirectional scan -may be performed by specifying the same tensor input twice in the -scan_inputs, once with a forward direction, and once with a backward -direction. - -The scan_output of the operation is produced by concatenating the -scan_output_element values produced by the body in each iteration. The -optional attribute scan_output_directions specifies the direction in -which scan_output is constructed (by appending or prepending the -scan_output_element to scan_output in each iteration) for each -scan_output. If this attribute is omitted, the scan_output_element is -appended to the scan_output in each iteration. - -The optional attribute scan_input_axes specifies the axis to be scanned -for each scan_input. If omitted, every scan_input will be scanned in -axis 0. For example, if axis 0 is the batch axis and axis 1 is the time -axis (to be scanned), specify an axis value of 1. Note that scanning a -non-zero axis may be less efficient than scanning axis zero. - -The optional attribute scan_output_axes specifies the axis along which -the scan_outputs are accumulated for each scan_output. For example, if -axis 1 is the time axis (to be scanned) for both inputs and outputs, -specify a scan_input axis and scan_output axis value of 1. - -Note that because of the ONNX restriction that only the last parameter -of an operator can be variadic, the initial-states and scan-inputs are -listed together as one input parameter. Similarly, the final-states and -scan-outputs are listed together as one output parameter. The attribute -num_scan_inputs indicates the number M of scan-inputs. - -The behavior of - -:: - - Scan < - num_scan_inputs = m, - body = loop-body, - scan_input_axes = [axis_1, ..., axis_m] - > (init_1, ..., init_n, scan_1, ..., scan_m) - -is equivalent to the following pseudo-code: - -:: - - // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i - // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. - sequence_length = scan_1.shape[axis_1]; - - // initialize state-variables - st_1 = init_1; ... st_n = init_n; - // initialize scan-output variables: [] denotes an empty tensor - scan_out_1 = []; ...; scan_out_k = []; - // identify number of iterations: - - // execute loop - for (int t = 0; t < sequence_length; ++t) { - // generate the scan-input elements: the notation T[t] indicates the sub-tensor - // of rank one less than T obtained by indexing T at position t along axis k. - si_1 = scan_1[t]; - ... ; - si_m = scan_m[t]; - // execute loop-body - st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) - // accumulate the scan-output elements - scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); - } - - return st_1, ..., st_n, scan_out_1, ..., scan_out_k; - -*Sample usage: Encoding RNN using a Scan* - -The following example shows how a simple RNN over an input tensor %X, -with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi -and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. -Note that the loop-body is a nested graph, and it directly computes %Wi, -%Ri, %Wbi, and %Rbi (typically constants or initializers in the body -graph). If these values are computed in the outer graph, they need to be -passed in as extra state_variables. - -:: - - graph rnn-encoding { - %H_0 = ... - %X = ... - %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) - return %Y, %Y_h - } - - graph rnn-cell-1 ( - %H_tminus1[FLOAT, tensor] - %X_t[FLOAT, tensor] - ) { - %Wi = ... - %Ri = ... - %Wbi = ... - %Rbi = ... - %t1 = X_t * (Wi^T) - %t2 = H_tminus1*(Ri^T) - %t3 = Add(%t1, %t2) - %t4 = Add(%t3, %Wbi) - %t5 = Add(%t4, %Rbi) - %Ht = Tanh(%t5) - %Accumulate = Identity(%Ht) - return %Ht, %Accumulate - } - -Parameters -========== -initial_state_and_scan_inputs - Type V. - Initial values of the loop's N state variables followed by M scan_inputs -body - Attribute. - The graph run each iteration. It has N+M inputs: (loop state - variables..., scan_input_elts...). It has N+K outputs: (loop state - variables..., scan_output_elts...). Each scan_output is created by - concatenating the value of the specified scan_output_elt value at the - end of each iteration of the loop. It is an error if the dimensions of - these values change across loop iterations. -num_scan_inputs - Attribute. - An attribute specifying the number of scan_inputs M. -scan_input_axes - Attribute. - An optional list of M flags. The i-th element of the list specifies the - axis to be scanned (the sequence axis) for the i-th scan_input. If - omitted, 0 will be used as the scan axis for every scan_input. Negative - value for an axis means counting dimensions from the back. Accepted - range is [-r, r-1] where r = rank(input). -scan_input_directions - Attribute. - An optional list of M flags. The i-th element of the list specifies the - direction to be scanned for the i-th scan_input tensor: 0 indicates - forward direction and 1 indicates reverse direction. If omitted, all - scan_input tensors will be scanned in the forward direction. -scan_output_axes - Attribute. - An optional list of K flags. The i-th element of the list specifies the - axis for the i-th scan_output. The scan outputs are accumulated along - the specified axis. If omitted, 0 will be used as the scan axis for - every scan_output. Negative value for an axis means counting dimensions - from the back. Accepted range is [-r, r-1]. -scan_output_directions - Attribute. - An optional list of K flags, one for each scan_output. The i-th element - of the list specifies whether the i-th scan_output should be constructed - by appending or prepending a new value in each iteration: 0 indicates - appending and 1 indicates prepending. If omitted, all scan_output - tensors will be produced by appending a value in each iteration. - -Returns -======= -final_state_and_scan_outputs : Sequence[Var] - Type V. - Final values of the loop's N state variables followed by K scan_outputs - -Notes -===== -Signature: ``ai.onnx@16::Scan``. - -Type constraints: - - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _body_subgraph: Graph = subgraph( - [Tensor(var.unwrap_tensor().dtype, (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape)) for var in initial_state_and_scan_inputs[:num_scan_inputs]] + [Tensor(var.unwrap_tensor().dtype) for var in initial_state_and_scan_inputs[num_scan_inputs:]], - body - ) - return _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), - scan_input_directions=AttrInt64s.maybe(scan_input_directions, name="scan_input_directions"), - scan_output_axes=AttrInt64s.maybe(scan_output_axes, name="scan_output_axes"), - scan_output_directions=AttrInt64s.maybe(scan_output_directions, name="scan_output_directions"), - ), _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), ).final_state_and_scan_outputs - - -def scatter_elements(data: Var, indices: Var, updates: Var, *, axis: int = 0, reduction: str = "none", ) -> Var: - r""" -ScatterElements takes three inputs ``data``, ``updates``, and -``indices`` of the same rank r >= 1 and an optional attribute axis that -identifies an axis of ``data`` (by default, the outer-most axis, that is -axis 0). The output of the operation is produced by creating a copy of -the input ``data``, and then updating its value to values specified by -``updates`` at specific index positions specified by ``indices``. Its -output shape is the same as the shape of ``data``. For each entry in -``updates``, the target index in ``data`` is obtained by combining the -corresponding entry in ``indices`` with the index of the entry itself: -the index-value for dimension = axis is obtained from the value of the -corresponding entry in ``indices`` and the index-value for dimension != -axis is obtained from the index of the entry itself. ``reduction`` -allows specification of an optional reduction operation, which is -applied to all values in ``updates`` tensor into ``output`` at the -specified ``indices``. In cases where ``reduction`` is set to "none", -indices should not have duplicate entries: that is, if idx1 != idx2, -then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, -the update corresponding to the [i][j] entry is performed as below: - -:: - - output[indices[i][j]][j] = updates[i][j] if axis = 0, - output[i][indices[i][j]] = updates[i][j] if axis = 1, - -When ``reduction`` is set to "add", the update corresponding to the -[i][j] entry is performed as below: - -:: - - output[indices[i][j]][j] += updates[i][j] if axis = 0, - output[i][indices[i][j]] += updates[i][j] if axis = 1, - -When ``reduction`` is set to "mul", the update corresponding to the -[i][j] entry is performed as below: - -:: - - output[indices[i][j]][j] *= updates[i][j] if axis = 0, - output[i][indices[i][j]] *= updates[i][j] if axis = 1, - -This operator is the inverse of GatherElements. It is similar to Torch's -Scatter operation. Example 1: - -:: - - data = [ - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - ] - indices = [ - [1, 0, 2], - [0, 2, 1], - ] - updates = [ - [1.0, 1.1, 1.2], - [2.0, 2.1, 2.2], - ] - output = [ - [2.0, 1.1, 0.0] - [1.0, 0.0, 2.2] - [0.0, 2.1, 1.2] - ] - -Example 2: - -:: - - data = [[1.0, 2.0, 3.0, 4.0, 5.0]] - indices = [[1, 3]] - updates = [[1.1, 2.1]] - axis = 1 - output = [[1.0, 1.1, 3.0, 2.1, 5.0]] - -Parameters -========== -data - Type T. - Tensor of rank r >= 1. -indices - Type Tind. - Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index - values are expected to be within bounds [-s, s-1] along axis of size s. - It is an error if any of the index values are out of bounds. -updates - Type T. - Tensor of rank r >=1 (same rank and shape as indices) -axis - Attribute. - Which axis to scatter on. Negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(data). -reduction - Attribute. - Type of reduction to apply: none (default), add, mul. 'none': no - reduction applied. 'add': reduction using the addition operation. 'mul': - reduction using the multiplication operation. - -Returns -======= -output : Var - Type T. - Tensor of rank r >= 1 (same rank as input). - -Notes -===== -Signature: ``ai.onnx@16::ScatterElements``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return _ScatterElements( - _ScatterElements.Attributes( - axis=AttrInt64(axis, name="axis"), - reduction=AttrString(reduction, name="reduction"), - ), _ScatterElements.Inputs( - data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), ).get_output_vars( - data=get_value(data), indices=get_value(indices), updates=get_value(updates), ).output - - -def scatter_nd(data: Var, indices: Var, updates: Var, *, reduction: str = "none", ) -> Var: - r""" -ScatterND takes three inputs ``data`` tensor of rank r >= 1, ``indices`` -tensor of rank q >= 1, and ``updates`` tensor of rank q + r - -indices.shape[-1] - 1. The output of the operation is produced by -creating a copy of the input ``data``, and then updating its value to -values specified by ``updates`` at specific index positions specified by -``indices``. Its output shape is the same as the shape of ``data``. - -``indices`` is an integer tensor. Let k denote indices.shape[-1], the -last dimension in the shape of ``indices``. ``indices`` is treated as a -(q-1)-dimensional tensor of k-tuples, where each k-tuple is a -partial-index into ``data``. Hence, k can be a value at most the rank of -``data``. When k equals rank(data), each update entry specifies an -update to a single element of the tensor. When k is less than rank(data) -each update entry specifies an update to a slice of the tensor. Index -values are allowed to be negative, as per the usual convention for -counting backwards from the end, but are expected in the valid range. - -``updates`` is treated as a (q-1)-dimensional tensor of -replacement-slice-values. Thus, the first (q-1) dimensions of -updates.shape must match the first (q-1) dimensions of indices.shape. -The remaining dimensions of ``updates`` correspond to the dimensions of -the replacement-slice-values. Each replacement-slice-value is a (r-k) -dimensional tensor, corresponding to the trailing (r-k) dimensions of -``data``. Thus, the shape of ``updates`` must equal indices.shape[0:q-1] -++ data.shape[k:r-1], where ++ denotes the concatenation of shapes. - -The ``output`` is calculated via the following equation: output = -np.copy(data) update_indices = indices.shape[:-1] for idx in -np.ndindex(update_indices): output[indices[idx]] = updates[idx] The -order of iteration in the above loop is not specified. In particular, -indices should not have duplicate entries: that is, if idx1 != idx2, -then indices[idx1] != indices[idx2]. This ensures that the output value -does not depend on the iteration order. - -``reduction`` allows specification of an optional reduction operation, -which is applied to all values in ``updates`` tensor into ``output`` at -the specified ``indices``. In cases where ``reduction`` is set to -"none", indices should not have duplicate entries: that is, if idx1 != -idx2, then indices[idx1] != indices[idx2]. This ensures that the output -value does not depend on the iteration order. When ``reduction`` is set -to "add", ``output`` is calculated as follows: output = np.copy(data) -update_indices = indices.shape[:-1] for idx in -np.ndindex(update_indices): output[indices[idx]] += updates[idx] When -``reduction`` is set to "mul", ``output`` is calculated as follows: -output = np.copy(data) update_indices = indices.shape[:-1] for idx in -np.ndindex(update_indices): output[indices[idx]] \*= updates[idx] This -operator is the inverse of GatherND. Example 1: - -:: - - data = [1, 2, 3, 4, 5, 6, 7, 8] - indices = [[4], [3], [1], [7]] - updates = [9, 10, 11, 12] - output = [1, 11, 3, 10, 9, 6, 7, 12] - -Example 2: - -:: - - data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] - indices = [[0], [2]] - updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], - [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] - output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], - [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] - -Parameters -========== -data - Type T. - Tensor of rank r >= 1. -indices - Type tensor(int64). - Tensor of rank q >= 1. -updates - Type T. - Tensor of rank q + r - indices_shape[-1] - 1. -reduction - Attribute. - Type of reduction to apply: none (default), add, mul. 'none': no - reduction applied. 'add': reduction using the addition operation. 'mul': - reduction using the multiplication operation. - -Returns -======= -output : Var - Type T. - Tensor of rank r >= 1. - -Notes -===== -Signature: ``ai.onnx@16::ScatterND``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _ScatterND( - _ScatterND.Attributes( - reduction=AttrString(reduction, name="reduction"), - ), _ScatterND.Inputs( - data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), ).get_output_vars( - data=get_value(data), indices=get_value(indices), updates=get_value(updates), ).output - - -def selu(X: Var, *, alpha: float = 1.6732631921768188, gamma: float = 1.0507010221481323, ) -> Var: - r""" -Selu takes one input data (Tensor) and produces one output data -(Tensor) where the scaled exponential linear unit function, -``y = gamma * (alpha * e^x - alpha) for x <= 0``, -``y = gamma * x for x > 0``, is applied to the tensor elementwise. - -Parameters -========== -X - Type T. - Input tensor -alpha - Attribute. - Coefficient of SELU default to 1.67326319217681884765625 (i.e., float32 - approximation of 1.6732632423543772848170429916717). -gamma - Attribute. - Coefficient of SELU default to 1.05070102214813232421875 (i.e., float32 - approximation of 1.0507009873554804934193349852946). - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@6::Selu``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Selu( - _Selu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - gamma=AttrFloat32(gamma, name="gamma"), - ), _Selu.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def sequence_at(input_sequence: Var, position: Var, ) -> Var: - r""" -Outputs a tensor copy from the tensor at 'position' in 'input_sequence'. -Accepted range for 'position' is in ``[-n, n - 1]``, where ``n`` is the -number of tensors in 'input_sequence'. Negative value means counting -positions from the back. - -Parameters -========== -input_sequence - Type S. - Input sequence. -position - Type I. - Position of the tensor in the sequence. Negative value means counting - positions from the back. Accepted range in ``[-n, n - 1]``, where ``n`` - is the number of tensors in 'input_sequence'. It is an error if any of - the index values are out of bounds. It must be a scalar(tensor of empty - shape). - -Returns -======= -tensor : Var - Type T. - Output tensor at the specified position in the input sequence. - -Notes -===== -Signature: ``ai.onnx@11::SequenceAt``. - -Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - I: `tensor(int32)`, `tensor(int64)` - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _SequenceAt( - _SequenceAt.Attributes( - ), _SequenceAt.Inputs( - input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), ), ).get_output_vars( - input_sequence=get_value(input_sequence), position=get_value(position), ).tensor - - -def sequence_construct(inputs: Sequence[Var], ) -> Var: - r""" -Construct a tensor sequence containing 'inputs' tensors. All tensors in -'inputs' must have the same data type. - -Parameters -========== -inputs - Type T. - Tensors. - -Returns -======= -output_sequence : Var - Type S. - Sequence enclosing the input tensors. - -Notes -===== -Signature: ``ai.onnx@11::SequenceConstruct``. - -Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - """ - return _SequenceConstruct( - _SequenceConstruct.Attributes( - ), _SequenceConstruct.Inputs( - inputs=unwrap_vars(inputs), ), ).get_output_vars( - inputs=get_value(inputs), ).output_sequence - - -def sequence_empty(*, dtype: Optional[npt.DTypeLike] = None, ) -> Var: - r""" -Construct an empty tensor sequence, with given data type. - -Parameters -========== -dtype - Attribute. - (Optional) The data type of the tensors in the output sequence. The - default type is 'float'. - -Returns -======= -output : Var - Type S. - Empty sequence. - -Notes -===== -Signature: ``ai.onnx@11::SequenceEmpty``. - -Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - """ - return _SequenceEmpty( - _SequenceEmpty.Attributes( - dtype=AttrDtype.maybe(dtype, name="dtype"), - ), _SequenceEmpty.Inputs( - ), ).get_output_vars( - ).output - - -def sequence_erase(input_sequence: Var, position: Optional[Var] = None, ) -> Var: - r""" -Outputs a tensor sequence that removes the tensor at 'position' from -'input_sequence'. Accepted range for 'position' is in ``[-n, n - 1]``, -where ``n`` is the number of tensors in 'input_sequence'. Negative value -means counting positions from the back. 'position' is optional, by -default it erases the last tensor from 'input_sequence'. - -Parameters -========== -input_sequence - Type S. - Input sequence. -position - Type I. - Position of the tensor in the sequence. Negative value means counting - positions from the back. Accepted range in ``[-n, n - 1]``, where ``n`` - is the number of tensors in 'input_sequence'. It is an error if any of - the index values are out of bounds. It must be a scalar(tensor of empty - shape). - -Returns -======= -output_sequence : Var - Type S. - Output sequence that has the tensor at the specified position removed. - -Notes -===== -Signature: ``ai.onnx@11::SequenceErase``. - -Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - I: `tensor(int32)`, `tensor(int64)` - """ - return _SequenceErase( - _SequenceErase.Attributes( - ), _SequenceErase.Inputs( - input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), ), ).get_output_vars( - input_sequence=get_value(input_sequence), position=get_value(position), ).output_sequence - - -def sequence_insert(input_sequence: Var, tensor: Var, position: Optional[Var] = None, ) -> Var: - r""" -Outputs a tensor sequence that inserts 'tensor' into 'input_sequence' at -'position'. 'tensor' must have the same data type as 'input_sequence'. -Accepted range for 'position' is in ``[-n, n]``, where ``n`` is the -number of tensors in 'input_sequence'. Negative value means counting -positions from the back. 'position' is optional, by default it inserts -'tensor' to the back of 'input_sequence'. - -Parameters -========== -input_sequence - Type S. - Input sequence. -tensor - Type T. - Input tensor to be inserted into the input sequence. -position - Type I. - Position in the sequence where the new tensor is inserted. It is - optional and default is to insert to the back of the sequence. Negative - value means counting positions from the back. Accepted range in - ``[-n, n]``, where ``n`` is the number of tensors in 'input_sequence'. - It is an error if any of the index values are out of bounds. It must be - a scalar(tensor of empty shape). - -Returns -======= -output_sequence : Var - Type S. - Output sequence that contains the inserted tensor at given position. - -Notes -===== -Signature: ``ai.onnx@11::SequenceInsert``. - -Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - I: `tensor(int32)`, `tensor(int64)` - """ - return _SequenceInsert( - _SequenceInsert.Attributes( - ), _SequenceInsert.Inputs( - input_sequence=unwrap_vars(input_sequence), tensor=unwrap_vars(tensor), position=unwrap_vars(position), ), ).get_output_vars( - input_sequence=get_value(input_sequence), tensor=get_value(tensor), position=get_value(position), ).output_sequence - - -def sequence_length(input_sequence: Var, ) -> Var: - r""" -Produces a scalar(tensor of empty shape) containing the number of -tensors in 'input_sequence'. - -Parameters -========== -input_sequence - Type S. - Input sequence. - -Returns -======= -length : Var - Type I. - Length of input sequence. It must be a scalar(tensor of empty shape). - -Notes -===== -Signature: ``ai.onnx@11::SequenceLength``. - -Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - I: `tensor(int64)` - """ - return _SequenceLength( - _SequenceLength.Attributes( - ), _SequenceLength.Inputs( - input_sequence=unwrap_vars(input_sequence), ), ).get_output_vars( - input_sequence=get_value(input_sequence), ).length - - -def sequence_map(input_sequence: Var, additional_inputs: Sequence[Var] = (), *, body: Callable[..., Iterable[Var]], ) -> Sequence[Var]: - r""" -Applies a sub-graph to each sample in the input sequence(s). - -Inputs can be either tensors or sequences, with the exception of the -first input which must be a sequence. The length of the first input -sequence will determine the number of samples in the outputs. Any other -sequence inputs should have the same number of samples. The number of -inputs and outputs, should match the one of the subgraph. - -For each i-th element in the output, a sample will be extracted from the -input sequence(s) at the i-th position and the sub-graph will be applied -to it. The outputs will contain the outputs of the sub-graph for each -sample, in the same order as in the input. - -This operator assumes that processing each sample is independent and -could executed in parallel or in any order. Users cannot expect any -specific ordering in which each subgraph is computed. - -Parameters -========== -input_sequence - Type S. - Input sequence. -additional_inputs - Type V. - Additional inputs to the graph -body - Attribute. - The graph to be run for each sample in the sequence(s). It should have - as many inputs and outputs as inputs and outputs to the SequenceMap - function. - -Returns -======= -out_sequence : Sequence[Var] - Type S. - Output sequence(s) - -Notes -===== -Signature: ``ai.onnx@17::SequenceMap``. - -Type constraints: - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - _body_subgraph: Graph = subgraph( - [typing_cast(SpoxSequence, input_sequence.unwrap_type()).elem_type] + [typing_cast(SpoxSequence, var.unwrap_type()).elem_type for var in additional_inputs], - body - ) - return _SequenceMap( - _SequenceMap.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), _SequenceMap.Inputs( - input_sequence=unwrap_vars(input_sequence), additional_inputs=unwrap_vars(additional_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( - input_sequence=get_value(input_sequence), additional_inputs=get_value(additional_inputs), ).out_sequence - - -def shape(data: Var, *, end: Optional[int] = None, start: int = 0, ) -> Var: - r""" -Takes a tensor as input and outputs an 1D int64 tensor containing the -shape of the input tensor. Optional attributes start and end can be used -to compute a slice of the input tensor's shape. If start axis is -omitted, the slice starts from axis 0. The end axis, if specified, is -exclusive (and the returned value will not include the size of that -axis). If the end axis is omitted, the axes upto the last one will be -included. Negative axes indicate counting back from the last axis. Note -that axes will be clamped to the range [0, r-1], where r is the rank of -the input tensor if they are out-of-range (after adding r in the case of -negative axis). Thus, specifying any end value > r is equivalent to -specifying an end value of r, and specifying any start value < -r is -equivalent to specifying a start value of 0. - -Examples: - -:: - - Input tensor with shape: [2, 3, 4] - No attributes specified. - Output: [2, 3, 4] - -:: - - Input tensor with shape: [2, 3, 4] - start: -1 - Output: [4] - -:: - - Input tensor with shape: [2, 3, 4] - end: -1 - Output: [2, 3] - -:: - - Input tensor with shape: [2, 3, 4] - start: 1 - end: 2 - Output: [3] - -Parameters -========== -data - Type T. - An input tensor. -end - Attribute. - (Optional) Ending axis for slicing the shape. Negative value means - counting dimensions from the back. If omitted, sizes of all axes upto - (including) the last one will be included. -start - Attribute. - (Optional) Starting axis for slicing the shape. Default value is - 0.Negative value means counting dimensions from the back. - -Returns -======= -shape : Var - Type T1. - Shape of the input tensor - -Notes -===== -Signature: ``ai.onnx@15::Shape``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` - """ - return _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), _Shape.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).shape - - -def shrink(input: Var, *, bias: float = 0.0, lambd: float = 0.5, ) -> Var: - r""" -Shrink takes one input data (Tensor) and produces one Tensor output, -having same datatype and shape with input. It has two attributes, lambd -and bias. The formula of this operator is: If x < -lambd, y = x + bias; -If x > lambd, y = x - bias; Otherwise, y = 0. - -Parameters -========== -input - Type T. - The input data as Tensor. -bias - Attribute. - The bias value added to output. Default is 0. -lambd - Attribute. - The lambd value for the Shrink formulation. Default is 0.5. - -Returns -======= -output : Var - Type T. - The output. - -Notes -===== -Signature: ``ai.onnx@9::Shrink``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Shrink( - _Shrink.Attributes( - bias=AttrFloat32(bias, name="bias"), - lambd=AttrFloat32(lambd, name="lambd"), - ), _Shrink.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def sigmoid(X: Var, ) -> Var: - r""" -Sigmoid takes one input data (Tensor) and produces one output data -(Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is -applied to the tensor elementwise. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@13::Sigmoid``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Sigmoid( - _Sigmoid.Attributes( - ), _Sigmoid.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def sign(input: Var, ) -> Var: - r""" -Calculate the sign of the given input tensor element-wise. If input > 0, -output 1. if input < 0, output -1. if input == 0, output 0. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The sign of the input tensor computed element-wise. It has the same - shape and type of the input. - -Notes -===== -Signature: ``ai.onnx@13::Sign``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Sign( - _Sign.Attributes( - ), _Sign.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def sin(input: Var, ) -> Var: +def blackman_window( + size: Var, + *, + output_datatype: int = 1, + periodic: int = 1, +) -> Var: r""" -Calculates the sine of the given input tensor, element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The sine of the input tensor computed element-wise + Generates a Blackman window as described in the paper + https://ieeexplore.ieee.org/document/1455106. + + Parameters + ========== + size + Type T1. + A scalar value indicating the length of the window. + output_datatype + Attribute. + The data type of the output tensor. Strictly must be one of the values + from DataType enum in TensorProto whose values correspond to T2. The + default value is 1 = FLOAT. + periodic + Attribute. + If 1, returns a window to be used as periodic function. If 0, return a + symmetric window. When 'periodic' is specified, hann computes a window + of length size + 1 and returns the first size points. The default value + is 1. + + Returns + ======= + output : Var + Type T2. + A Blackman window with length: size. The output has the shape: [size]. + + Notes + ===== + Signature: ``ai.onnx@17::BlackmanWindow``. + + Type constraints: + - T1: `tensor(int32)`, `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _BlackmanWindow( + _BlackmanWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), + _BlackmanWindow.Inputs( + size=unwrap_vars(size), + ), + ) + .get_output_vars( + size=get_value(size), + ) + .output + ) -Notes -===== -Signature: ``ai.onnx@7::Sin``. -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +def cast( + input: Var, + *, + to: npt.DTypeLike, +) -> Var: + r""" + The operator casts the elements of a given input tensor to a data type + specified by the 'to' argument and returns an output tensor of the same + size in the converted type. The 'to' argument must be one of the data + types specified in the 'DataType' enum field in the TensorProto message. + + Casting from string tensor in plain (e.g., "3.14" and "1000") and + scientific numeric representations (e.g., "1e-5" and "1E8") to float + types is supported. For example, converting string "100.5" to an integer + may yield result 100. There are some string literals reserved for + special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are + positive infinity, negative infinity, and not-a-number, respectively. + Any string which can exactly match "+INF" in a case-insensitive way + would be mapped to positive infinite. Similarly, this case-insensitive + rule is applied to "INF" and "NaN". When casting from numeric tensors to + string tensors, plain floating-point representation (such as + "314.15926") would be used. Converting non-numerical-literal string such + as "Hello World!" is an undefined behavior. Cases of converting string + representing floating-point arithmetic value, such as "2.718", to INT is + an undefined behavior. + + Conversion from a numerical type to any numerical type is always + allowed. User must be aware of precision loss and value change caused by + range difference between two types. For example, a 64-bit float + 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, + converting an integer 36 to Boolean may produce 1 because we truncate + bits which can't be stored in the targeted type. + + In more detail, the conversion among numerical types should follow these + rules: + + - Casting from floating point to: + + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. + + - Casting from fixed point to: + + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. + + - Casting from bool to: + + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. + + Parameters + ========== + input + Type T1. + Input tensor to be cast. + to + Attribute. + The data type to which the elements of the input tensor are cast. + Strictly must be one of the types from DataType enum in TensorProto + + Returns + ======= + output : Var + Type T2. + Output tensor with the same shape as input with type specified by the + 'to' argument + + Notes + ===== + Signature: ``ai.onnx@13::Cast``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Sin( - _Sin.Attributes( - ), _Sin.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Cast( + _Cast.Attributes( + to=AttrDtype(to, name="to"), + ), + _Cast.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def sinh(input: Var, ) -> Var: +def cast_like( + input: Var, + target_type: Var, +) -> Var: r""" -Calculates the hyperbolic sine of the given input tensor element-wise. + The operator casts the elements of a given input tensor (the first + input) to the same data type as the elements of the second input tensor. + See documentation of the Cast operator for further details. -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The hyperbolic sine values of the input tensor computed element-wise + Parameters + ========== + input + Type T1. + Input tensor to be cast. + target_type + Type T2. + The (first) input tensor will be cast to produce a tensor of the same + type as this (second input) tensor. + + Returns + ======= + output : Var + Type T2. + Output tensor produced by casting the first input tensor to have the + same type as the second input tensor. + + Notes + ===== + Signature: ``ai.onnx@15::CastLike``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _CastLike( + _CastLike.Attributes(), + _CastLike.Inputs( + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), + ), + ) + .get_output_vars( + input=get_value(input), + target_type=get_value(target_type), + ) + .output + ) -Notes -===== -Signature: ``ai.onnx@9::Sinh``. -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` +def ceil( + X: Var, +) -> Var: + r""" + Ceil takes one input data (Tensor) and produces one output data + (Tensor) where the ceil is, y = ceil(x), is applied to the tensor + elementwise. If x is integral, +0, -0, NaN, or infinite, x itself is + returned. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::Ceil``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Sinh( - _Sinh.Attributes( - ), _Sinh.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Ceil( + _Ceil.Attributes(), + _Ceil.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -def size(data: Var, ) -> Var: +def celu( + X: Var, + *, + alpha: float = 1.0, +) -> Var: r""" -Takes a tensor as input and outputs a int64 scalar that equals to the -total number of elements of the input tensor. + Continuously Differentiable Exponential Linear Units: Perform the linear + unit element-wise on the input tensor X using formula: + + :: + + max(0,x) + min(0,alpha*(exp(x/alpha)-1)) + + Parameters + ========== + X + Type T. + Input tensor + alpha + Attribute. + The Alpha value in Celu formula which control the shape of the unit. The + default value is 1.0. + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@12::Celu``. + + Type constraints: + - T: `tensor(float)` + """ + return ( + _Celu( + _Celu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), + _Celu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -Parameters -========== -data - Type T. - An input tensor. - -Returns -======= -size : Var - Type T1. - Total number of elements of the input tensor - -Notes -===== -Signature: ``ai.onnx@13::Size``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` - """ - return _Size( - _Size.Attributes( - ), _Size.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).size - - -def slice(data: Var, starts: Var, ends: Var, axes: Optional[Var] = None, steps: Optional[Var] = None, ) -> Var: - r""" -Produces a slice of the input tensor along multiple axes. Similar to -numpy: -https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding - -Slice uses the ``starts``, ``ends``, ``axes`` and ``steps`` inputs to -select a sub-tensor of its input ``data`` tensor. - -An effective ``starts[i]``, ``ends[i]``, and ``steps[i]`` must be -computed for each ``i`` in ``[0, ... r-1]`` where ``r = rank(input)`` as -follows: - -If ``axes`` are omitted, they are set to ``[0, ..., r-1]``. If ``steps`` -are omitted, they are set to ``[1, ..., 1]`` of length ``len(starts)`` - -The effective values are initialized as ``start[i] = 0``, -``ends[i] = dims[i]`` where ``dims`` are the dimensions of ``input`` and -``steps[i] = 1``. - -All negative elements of ``axes`` are made non-negative by adding ``r`` -to them, where ``r =rank(input)``. - -All negative values in ``starts[i]`` and ``ends[i]`` have -``dims[axes[i]]`` added to them, where ``dims`` are the dimensions of -``input``. Then ``start[axes[i]]`` is the adjusted ``starts[i]`` is -clamped into the range ``[0, dims[axes[i]]]`` for positive stepping and -``[0, dims[axes[i]]-1]`` for negative stepping. - -The clamping for the adjusted ``ends[i]`` depends on the sign of -``steps[i]`` and must accommodate copying 0 through ``dims[axes[i]]`` -elements, so for positive stepping ``ends[axes[i]]`` is clamped to -``[0, dims[axes[i]]]``, while for negative stepping it is clamped to -``[-1, dims[axes[i]]-1]``. - -Finally, ``steps[axes[i]] = steps[i]``. - -For slicing to the end of a dimension with unknown size, it is -recommended to pass in ``INT_MAX`` when slicing forward and 'INT_MIN' -when slicing backward. - -Example 1: - -:: - - data = [ - [1, 2, 3, 4], - [5, 6, 7, 8], - ] - axes = [0, 1] - starts = [1, 0] - ends = [2, 3] - steps = [1, 2] - result = [ - [5, 7], - ] - -Example 2: - -:: - - data = [ - [1, 2, 3, 4], - [5, 6, 7, 8], - ] - starts = [0, 1] - ends = [-1, 1000] - result = [ - [2, 3, 4], - ] - -Parameters -========== -data - Type T. - Tensor of data to extract slices from. -starts - Type Tind. - 1-D tensor of starting indices of corresponding axis in ``axes`` -ends - Type Tind. - 1-D tensor of ending indices (exclusive) of corresponding axis in - ``axes`` -axes - Type Tind. - 1-D tensor of axes that ``starts`` and ``ends`` apply to. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(data). Behavior is undefined if an axis is repeated. -steps - Type Tind. - 1-D tensor of slice step of corresponding axis in ``axes``. Negative - value means slicing backward. 'steps' cannot be 0. Defaults to 1s. - -Returns -======= -output : Var - Type T. - Sliced data tensor. - -Notes -===== -Signature: ``ai.onnx@13::Slice``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return _Slice( - _Slice.Attributes( - ), _Slice.Inputs( - data=unwrap_vars(data), starts=unwrap_vars(starts), ends=unwrap_vars(ends), axes=unwrap_vars(axes), steps=unwrap_vars(steps), ), ).get_output_vars( - data=get_value(data), starts=get_value(starts), ends=get_value(ends), axes=get_value(axes), steps=get_value(steps), ).output - - -def softmax(input: Var, *, axis: int = -1, ) -> Var: - r""" -The operator computes the normalized exponential values for the given -input: - -Softmax(input, axis) = Exp(input) / ReduceSum(Exp(input), axis=axis, -keepdims=1) - -The "axis" attribute indicates the dimension along which Softmax will be -performed. The output tensor has the same shape and contains the Softmax -values of the corresponding input. - -Parameters -========== -input - Type T. - The input tensor of rank >= axis. -axis - Attribute. - Describes the dimension Softmax will be performed on. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(input). - -Returns -======= -output : Var - Type T. - The output values with the same shape as the input tensor. - -Notes -===== -Signature: ``ai.onnx@13::Softmax``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Softmax( - _Softmax.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _Softmax.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def softmax_cross_entropy_loss(scores: Var, labels: Var, weights: Optional[Var] = None, *, ignore_index: Optional[int] = None, reduction: str = "mean", ) -> tuple[Var, Var]: - r""" -Loss function that measures the softmax cross entropy between 'scores' -and 'labels'. This operator first computes a loss tensor whose shape is -identical to the labels input. If the input is 2-D with shape (N, C), -the loss tensor may be a N-element vector L = (l_1, l_2, ..., l_N). If -the input is N-D tensor with shape (N, C, D1, D2, ..., Dk), the loss -tensor L may have (N, D1, D2, ..., Dk) as its shape and -L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. After L is -available, this operator can optionally do a reduction operator. - -- shape(scores): (N, C) where C is the number of classes, or (N, C, D1, - D2,..., Dk), with K >= 1 in case of K-dimensional loss. -- shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, - D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. - -The loss for one sample, l_i, can calculated as follows: - -:: - - l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes. - -or - -:: - - l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided. - -loss is zero for the case when label-value equals ignore_index. - -:: - - l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index - -where: - -:: - - p = Softmax(scores) - y = Log(p) - c = labels[i][d1][d2]...[dk] - -Finally, L is optionally reduced: - -- If reduction = 'none', the output is L with shape (N, D1, D2, ..., - Dk). -- If reduction = 'sum', the output is scalar: Sum(L). -- If reduction = 'mean', the output is scalar: ReduceMean(L), or if - weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W - is of shape ``(N, D1, D2, ..., Dk)`` and - ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. - -Parameters -========== -scores - Type T. - The predicted outputs with shape [batch_size, class_size], or - [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of - dimensions. -labels - Type Tind. - The ground truth output tensor, with shape [batch_size], or [batch_size, - D1, D2, ..., Dk], where K is the number of dimensions. Labels element - value shall be in range of [0, C). If ignore_index is specified, it may - have a value outside [0, C) and the label values should either be in the - range [0, C) or have the value ignore_index. -weights - Type T. - A manual rescaling weight given to each class. If given, it has to be a - 1D Tensor assigning weight to each of the classes. Otherwise, it is - treated as if having all ones. -ignore_index - Attribute. - Specifies a target value that is ignored and does not contribute to the - input gradient. It's an optional value. -reduction - Attribute. - Type of reduction to apply to loss: none, sum, mean(default). 'none': no - reduction will be applied, 'sum': the output will be summed. 'mean': the - sum of the output will be divided by the number of elements in the - output. - -Returns -======= -output : Var - Type T. - Weighted loss float Tensor. If reduction is 'none', this has the shape - of [batch_size], or [batch_size, D1, D2, ..., Dk] in case of - K-dimensional loss. Otherwise, it is a scalar. -log_prob : Var - Type T. - Log probability tensor. If the output of softmax is prob, its value is - log(prob). - -Notes -===== -Signature: ``ai.onnx@13::SoftmaxCrossEntropyLoss``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - Tind: `tensor(int32)`, `tensor(int64)` - """ - return _SoftmaxCrossEntropyLoss( - _SoftmaxCrossEntropyLoss.Attributes( - ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), - reduction=AttrString(reduction, name="reduction"), - ), _SoftmaxCrossEntropyLoss.Inputs( - scores=unwrap_vars(scores), labels=unwrap_vars(labels), weights=unwrap_vars(weights), ), ).get_output_vars( - scores=get_value(scores), labels=get_value(labels), weights=get_value(weights), )._unpack_to_any() - - -def softplus(X: Var, ) -> Var: - r""" -Softplus takes one input data (Tensor) and produces one output data -(Tensor) where the softplus function, y = ln(exp(x) + 1), is applied -to the tensor elementwise. - -Parameters -========== -X - Type T. - 1D input tensor - -Returns -======= -Y : Var - Type T. - 1D input tensor - -Notes -===== -Signature: ``ai.onnx@1::Softplus``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Softplus( - _Softplus.Attributes( - ), _Softplus.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def softsign(input: Var, ) -> Var: - r""" -Calculates the softsign (x/(1+|x\|)) of the given input tensor -element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The softsign (x/(1+|x\|)) values of the input tensor computed - element-wise - -Notes -===== -Signature: ``ai.onnx@1::Softsign``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Softsign( - _Softsign.Attributes( - ), _Softsign.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def space_to_depth(input: Var, *, blocksize: int, ) -> Var: - r""" -SpaceToDepth rearranges blocks of spatial data into depth. More -specifically, this op outputs a copy of the input tensor where values -from the height and width dimensions are moved to the depth dimension. - -Parameters -========== -input - Type T. - Input tensor of [N,C,H,W], where N is the batch axis, C is the channel - or depth, H is the height and W is the width. -blocksize - Attribute. - Blocks of [blocksize, blocksize] are moved. - -Returns -======= -output : Var - Type T. - Output tensor of [N, C \* blocksize \* blocksize, H/blocksize, - W/blocksize]. - -Notes -===== -Signature: ``ai.onnx@13::SpaceToDepth``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _SpaceToDepth( - _SpaceToDepth.Attributes( - blocksize=AttrInt64(blocksize, name="blocksize"), - ), _SpaceToDepth.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def split(input: Var, split: Optional[Var] = None, *, outputs_count: int, axis: int = 0, ) -> Sequence[Var]: - r""" -Split a tensor into a list of tensors, along the specified 'axis'. -Lengths of the parts can be specified using input 'split'. Otherwise, -the tensor is split to equal sized parts. - -Parameters -========== -input - Type T. - The tensor to split -split - Type tensor(int64). - Optional length of each output. Values should be >= 0.Sum of the values - must be equal to the dim value at 'axis' specified. -axis - Attribute. - Which axis to split on. A negative value means counting dimensions from - the back. Accepted range is [-rank, rank-1] where r = rank(input). -outputs_count - Specifies the number of variadic outputs of this operator. - Non-standard parameter created by the opset generator, as inference (a solution) it was not implemented or is impossible. - -Returns -======= -outputs : Sequence[Var] - Type T. - One or more outputs forming list of tensors after splitting - -Notes -===== -Signature: ``ai.onnx@13::Split``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Split( - _Split.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _Split.Inputs( - input=unwrap_vars(input), split=unwrap_vars(split), ), out_variadic=outputs_count, ).get_output_vars( - input=get_value(input), split=get_value(split), ).outputs - - -def split_to_sequence(input: Var, split: Optional[Var] = None, *, axis: int = 0, keepdims: int = 1, ) -> Var: - r""" -Split a tensor into a sequence of tensors, along the specified 'axis'. -Lengths of the parts can be specified using the optional argument -'split'. If the argument -``split' is not specified, a default scalar value of 1 is used as the value of``\ split'. -'split' must contain only positive numbers. 'split' is either a scalar -(tensor of empty shape), or a 1-D tensor. If 'split' is a scalar, then -'input' will be split into chunks all of size 'split' if possible. The -last chunk alone may be smaller than 'split' if the 'input' size along -the given axis 'axis' is not divisible by 'split'. If 'split' is a -1-dimensional tensor, the input tensor is split into 'size(split)' -chunks, with lengths of the parts on 'axis' specified in 'split'. In -this scenario, the sum of entries in 'split' must be equal to the -dimension size of input tensor on 'axis'. - -Parameters -========== -input - Type T. - The tensor to split -split - Type I. - Length of each output. It can be either a scalar(tensor of empty shape), - or a 1-D tensor. All values must be >= 0. -axis - Attribute. - Which axis to split on. A negative value means counting dimensions from - the back. Accepted range is [-rank, rank-1]. -keepdims - Attribute. - Keep the split dimension or not. Default 1, which means we keep split - dimension. If input 'split' is specified, this attribute is ignored. - -Returns -======= -output_sequence : Var - Type S. - One or more outputs forming a sequence of tensors after splitting - -Notes -===== -Signature: ``ai.onnx@11::SplitToSequence``. - -Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - I: `tensor(int32)`, `tensor(int64)` - - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - """ - return _SplitToSequence( - _SplitToSequence.Attributes( - axis=AttrInt64(axis, name="axis"), - keepdims=AttrInt64(keepdims, name="keepdims"), - ), _SplitToSequence.Inputs( - input=unwrap_vars(input), split=unwrap_vars(split), ), ).get_output_vars( - input=get_value(input), split=get_value(split), ).output_sequence - - -def sqrt(X: Var, ) -> Var: - r""" -Square root takes one input data (Tensor) and produces one output -data (Tensor) where the square root is, y = x^0.5, is applied to the -tensor elementwise. If x is negative, then it will return NaN. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@13::Sqrt``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Sqrt( - _Sqrt.Attributes( - ), _Sqrt.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def squeeze(data: Var, axes: Optional[Var] = None, ) -> Var: - r""" -Remove single-dimensional entries from the shape of a tensor. Takes an -input ``axes`` with a list of axes to squeeze. If ``axes`` is not -provided, all the single dimensions will be removed from the shape. If -an axis is selected with shape entry not equal to one, an error is -raised. - -Parameters -========== -data - Type T. - Tensors with at least max(dims) dimensions. -axes - Type tensor(int64). - List of integers indicating the dimensions to squeeze. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(data). - -Returns -======= -squeezed : Var - Type T. - Reshaped tensor with same data as input. - -Notes -===== -Signature: ``ai.onnx@13::Squeeze``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Squeeze( - _Squeeze.Attributes( - ), _Squeeze.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).squeezed - - -def string_normalizer(X: Var, *, case_change_action: str = "NONE", is_case_sensitive: int = 0, locale: Optional[str] = None, stopwords: Optional[Iterable[str]] = None, ) -> Var: - r""" -StringNormalization performs string operations for basic cleaning. This -operator has only one input (denoted by X) and only one output (denoted -by Y). This operator first examines the elements in the X, and removes -elements specified in "stopwords" attribute. After removing stop words, -the intermediate result can be further lowercased, uppercased, or just -returned depending the "case_change_action" attribute. This operator -only accepts [C]- and [1, C]-tensor. If all elements in X are dropped, -the output will be the empty value of string tensor with shape [1] if -input shape is [C] and shape [1, 1] if input shape is [1, C]. - -Parameters -========== -X - Type tensor(string). - UTF-8 strings to normalize -case_change_action - Attribute. - string enum that cases output to be lowercased/uppercases/unchanged. - Valid values are "LOWER", "UPPER", "NONE". Default is "NONE" -is_case_sensitive - Attribute. - Boolean. Whether the identification of stop words in X is - case-sensitive. Default is false -locale - Attribute. - Environment dependent string that denotes the locale according to which - output strings needs to be upper/lowercased.Default en_US or platform - specific equivalent as decided by the implementation. -stopwords - Attribute. - List of stop words. If not set, no word would be removed from X. - -Returns -======= -Y : Var - Type tensor(string). - UTF-8 Normalized strings - -Notes -===== -Signature: ``ai.onnx@10::StringNormalizer``. - - """ - return _StringNormalizer( - _StringNormalizer.Attributes( - case_change_action=AttrString(case_change_action, name="case_change_action"), - is_case_sensitive=AttrInt64(is_case_sensitive, name="is_case_sensitive"), - locale=AttrString.maybe(locale, name="locale"), - stopwords=AttrStrings.maybe(stopwords, name="stopwords"), - ), _StringNormalizer.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def sub(A: Var, B: Var, ) -> Var: - r""" -Performs element-wise binary subtraction (with Numpy-style broadcasting -support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -(Opset 14 change): Extend supported types to include uint8, int8, -uint16, and int16. - -Parameters -========== -A - Type T. - First operand. -B - Type T. - Second operand. - -Returns -======= -C : Var - Type T. - Result, has same element type as two inputs - -Notes -===== -Signature: ``ai.onnx@14::Sub``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Sub( - _Sub.Attributes( - ), _Sub.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def sum(data_0: Sequence[Var], ) -> Var: - r""" -Element-wise sum of each of the input tensors (with Numpy-style -broadcasting support). All inputs and outputs must have the same data -type. This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -data_0 - Type T. - List of tensors for sum. - -Returns -======= -sum : Var - Type T. - Output tensor. - -Notes -===== -Signature: ``ai.onnx@13::Sum``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Sum( - _Sum.Attributes( - ), _Sum.Inputs( - data_0=unwrap_vars(data_0), ), ).get_output_vars( - data_0=get_value(data_0), ).sum - - -def tan(input: Var, ) -> Var: - r""" -Calculates the tangent of the given input tensor, element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The tangent of the input tensor computed element-wise - -Notes -===== -Signature: ``ai.onnx@7::Tan``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Tan( - _Tan.Attributes( - ), _Tan.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def tanh(input: Var, ) -> Var: - r""" -Calculates the hyperbolic tangent of the given input tensor -element-wise. - -Parameters -========== -input - Type T. - Input tensor - -Returns -======= -output : Var - Type T. - The hyperbolic tangent values of the input tensor computed element-wise - -Notes -===== -Signature: ``ai.onnx@13::Tanh``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Tanh( - _Tanh.Attributes( - ), _Tanh.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def tf_idf_vectorizer(X: Var, *, max_gram_length: int, max_skip_count: int, min_gram_length: int, mode: str, ngram_counts: Iterable[int], ngram_indexes: Iterable[int], pool_int64s: Optional[Iterable[int]] = None, pool_strings: Optional[Iterable[str]] = None, weights: Optional[Iterable[float]] = None, ) -> Var: - r""" -This transform extracts n-grams from the input sequence and save them as -a vector. Input can be either a 1-D or 2-D tensor. For 1-D input, output -is the n-gram representation of that input. For 2-D input, the output is -also a 2-D tensor whose i-th row is the n-gram representation of the -i-th input row. More specifically, if input shape is [C], the -corresponding output shape would be [max(ngram_indexes) + 1]. If input -shape is [N, C], this operator produces a [N, max(ngram_indexes) + -1]-tensor. - -In contrast to standard n-gram extraction, here, the indexes of -extracting an n-gram from the original sequence are not necessarily -consecutive numbers. The discontinuity between indexes are controlled by -the number of skips. If the number of skips is 2, we should skip two -tokens when scanning through the original sequence. Let's consider an -example. Assume that input sequence is [94, 17, 36, 12, 28] and the -number of skips is 2. The associated 2-grams are [94, 12] and [17, 28] -respectively indexed by [0, 3] and [1, 4]. If the number of skips -becomes 0, the 2-grams generated are [94, 17], [17, 36], [36, 12], [12, -28] indexed by [0, 1], [1, 2], [2, 3], [3, 4], respectively. - -The output vector (denoted by Y) stores the count of each n-gram; -Y[ngram_indexes[i]] indicates the times that the i-th n-gram is found. -The attribute ngram_indexes is used to determine the mapping between -index i and the corresponding n-gram's output coordinate. If pool_int64s -is [94, 17, 17, 36], ngram_indexes is [1, 0], ngram_counts=[0, 0], then -the Y[0] (first element in Y) and Y[1] (second element in Y) are the -counts of [17, 36] and [94, 17], respectively. An n-gram which cannot be -found in pool_strings/pool_int64s should be ignored and has no effect on -the output. Note that we may consider all skips up to S when generating -the n-grams. - -The examples used above are true if mode is "TF". If mode is "IDF", all -the counts larger than 1 would be truncated to 1 and the i-th element in -weights would be used to scale (by multiplication) the count of the i-th -n-gram in pool. If mode is "TFIDF", this operator first computes the -counts of all n-grams and then scale them by the associated values in -the weights attribute. - -Only one of pool_strings and pool_int64s can be set. If pool_int64s is -set, the input should be an integer tensor. If pool_strings is set, the -input must be a string tensor. - -Parameters -========== -X - Type T. - Input for n-gram extraction -max_gram_length - Attribute. - Maximum n-gram length. If this value is 3, 3-grams will be used to - generate the output. -max_skip_count - Attribute. - Maximum number of items (integers/strings) to be skipped when - constructing an n-gram from X. If max_skip_count=1, min_gram_length=2, - max_gram_length=3, this operator may generate 2-grams with skip_count=0 - and skip_count=1, and 3-grams with skip_count=0 and skip_count=1 -min_gram_length - Attribute. - Minimum n-gram length. If this value is 2 and max_gram_length is 3, - output may contain counts of 2-grams and 3-grams. -mode - Attribute. - The weighting criteria. It can be one of "TF" (term frequency), "IDF" - (inverse document frequency), and "TFIDF" (the combination of TF and - IDF) -ngram_counts - Attribute. - The starting indexes of 1-grams, 2-grams, and so on in pool. It is - useful when determining the boundary between two consecutive collections - of n-grams. For example, if ngram_counts is [0, 17, 36], the first index - (zero-based) of 1-gram/2-gram/3-gram in pool are 0/17/36. This format is - essentially identical to CSR (or CSC) sparse matrix format, and we - choose to use this due to its popularity. -ngram_indexes - Attribute. - list of int64s (type: AttributeProto::INTS). This list is parallel to - the specified 'pool\_\*' attribute. The i-th element in ngram_indexes - indicate the coordinate of the i-th n-gram in the output tensor. -pool_int64s - Attribute. - List of int64 n-grams learned from the training set. Either this or - pool_strings attributes must be present but not both. It's an 1-D tensor - starting with the collections of all 1-grams and ending with the - collections of n-grams. The i-th element in pool stores the n-gram that - should be mapped to coordinate ngram_indexes[i] in the output vector. -pool_strings - Attribute. - List of strings n-grams learned from the training set. Either this or - pool_int64s attributes must be present but not both. It's an 1-D tensor - starting with the collections of all 1-grams and ending with the - collections of n-grams. The i-th element in pool stores the n-gram that - should be mapped to coordinate ngram_indexes[i] in the output vector. -weights - Attribute. - list of floats. This attribute stores the weight of each n-gram in pool. - The i-th element in weights is the weight of the i-th n-gram in pool. - Its length equals to the size of ngram_indexes. By default, weights is - an all-one tensor.This attribute is used when mode is "IDF" or "TFIDF" - to scale the associated word counts. - -Returns -======= -Y : Var - Type T1. - Ngram results - -Notes -===== -Signature: ``ai.onnx@9::TfIdfVectorizer``. - -Type constraints: - - T: `tensor(int32)`, `tensor(int64)`, `tensor(string)` - - T1: `tensor(float)` - """ - return _TfIdfVectorizer( - _TfIdfVectorizer.Attributes( - max_gram_length=AttrInt64(max_gram_length, name="max_gram_length"), - max_skip_count=AttrInt64(max_skip_count, name="max_skip_count"), - min_gram_length=AttrInt64(min_gram_length, name="min_gram_length"), - mode=AttrString(mode, name="mode"), - ngram_counts=AttrInt64s(ngram_counts, name="ngram_counts"), - ngram_indexes=AttrInt64s(ngram_indexes, name="ngram_indexes"), - pool_int64s=AttrInt64s.maybe(pool_int64s, name="pool_int64s"), - pool_strings=AttrStrings.maybe(pool_strings, name="pool_strings"), - weights=AttrFloat32s.maybe(weights, name="weights"), - ), _TfIdfVectorizer.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def thresholded_relu(X: Var, *, alpha: float = 1.0, ) -> Var: - r""" -ThresholdedRelu takes one input data (Tensor) and produces one output -data (Tensor) where the rectified linear function, y = x for x > -alpha, y = 0 otherwise, is applied to the tensor elementwise. - -Parameters -========== -X - Type T. - Input tensor -alpha - Attribute. - Threshold value - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@10::ThresholdedRelu``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _ThresholdedRelu( - _ThresholdedRelu.Attributes( - alpha=AttrFloat32(alpha, name="alpha"), - ), _ThresholdedRelu.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def tile(input: Var, repeats: Var, ) -> Var: - r""" -Constructs a tensor by tiling a given tensor. This is the same as -function ``tile`` in Numpy, but no broadcast. For example A = [[1, 2], -[3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]] - -Parameters -========== -input - Type T. - Input tensor of any shape. -repeats - Type T1. - 1D int64 tensor of the same length as input's dimension number, includes - numbers of repeated copies along input's dimensions. - -Returns -======= -output : Var - Type T. - Output tensor of the same dimensions and type as tensor input. - output_dim[i] = input_dim[i] \* repeats[i] - -Notes -===== -Signature: ``ai.onnx@13::Tile``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` - """ - return _Tile( - _Tile.Attributes( - ), _Tile.Inputs( - input=unwrap_vars(input), repeats=unwrap_vars(repeats), ), ).get_output_vars( - input=get_value(input), repeats=get_value(repeats), ).output - - -def top_k(X: Var, K: Var, *, axis: int = -1, largest: int = 1, sorted: int = 1, ) -> tuple[Var, Var]: - r""" -Retrieve the top-K largest or smallest elements along a specified axis. -Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer -argument k, return two outputs: - -- Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a\_{n-1}] which contains the values of the top k elements along - the specified axis - -- Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a\_{n-1}] which contains the indices of the top k elements - (original indices from the input tensor). - -- If "largest" is 1 (the default value) then the k largest elements are - returned. - -- If "sorted" is 1 (the default value) then the resulting k elements - will be sorted. - -- If "sorted" is 0, order of returned 'Values' and 'Indices' are - undefined. - -Given two equivalent values, this operator uses the indices along the -axis as a tiebreaker. That is, the element with the lower index will -appear first. - -Parameters -========== -X - Type T. - Tensor of shape [a_0, a_1, ..., a\_{n-1}] -K - Type tensor(int64). - A 1-D tensor containing a single positive value corresponding to the - number of top elements to retrieve -axis - Attribute. - Dimension on which to do the sort. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). -largest - Attribute. - Whether to return the top-K largest or smallest elements. -sorted - Attribute. - Whether to return the elements in sorted order. - -Returns -======= -Values : Var - Type T. - Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] containing top K values from the input tensor -Indices : Var - Type I. - Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] containing the corresponding input tensor indices for the top - K values. - -Notes -===== -Signature: ``ai.onnx@11::TopK``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - I: `tensor(int64)` - """ - return _TopK( - _TopK.Attributes( - axis=AttrInt64(axis, name="axis"), - largest=AttrInt64(largest, name="largest"), - sorted=AttrInt64(sorted, name="sorted"), - ), _TopK.Inputs( - X=unwrap_vars(X), K=unwrap_vars(K), ), ).get_output_vars( - X=get_value(X), K=get_value(K), )._unpack_to_any() - - -def transpose(data: Var, *, perm: Optional[Iterable[int]] = None, ) -> Var: - r""" -Transpose the input tensor similar to numpy.transpose. For example, when -perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output -shape will be (2, 1, 3). - -Parameters -========== -data - Type T. - An input tensor. -perm - Attribute. - A list of integers. By default, reverse the dimensions, otherwise - permute the axes according to the values given. - -Returns -======= -transposed : Var - Type T. - Transposed output. - -Notes -===== -Signature: ``ai.onnx@13::Transpose``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Transpose( - _Transpose.Attributes( - perm=AttrInt64s.maybe(perm, name="perm"), - ), _Transpose.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).transposed - - -def trilu(input: Var, k: Optional[Var] = None, *, upper: int = 1, ) -> Var: - r""" -Given a 2-D matrix or batches of 2-D matrices, returns the upper or -lower triangular part of the tensor(s). The attribute "upper" determines -whether the upper or lower part is retained. If set to true, the upper -triangular matrix is retained. Lower triangular matrix is retained -otherwise. Default value for the "upper" attribute is true. Trilu takes -one input tensor of shape [\*, N, M], where \* is zero or more batch -dimensions. The upper triangular part consists of the elements on and -above the given diagonal (k). The lower triangular part consists of -elements on and below the diagonal. All other elements in the matrix are -set to zero. If k = 0, the triangular part on and above/below the main -diagonal is retained. If upper is set to true, a positive k retains the -upper triangular matrix excluding the main diagonal and (k-1) diagonals -above it. A negative k value retains the main diagonal and \|k\| -diagonals below it. If upper is set to false, a positive k retains the -lower triangular matrix including the main diagonal and k diagonals -above it. A negative k value excludes the main diagonal and (\|k\|-1) -diagonals below it. - -Parameters -========== -input - Type T. - Input tensor of rank 2 or higher. -k - Type tensor(int64). - A 0-D tensor containing a single value corresponding to the number - diagonals above or below the main diagonal to exclude or include. - Default value is 0 if it's not specified. -upper - Attribute. - Boolean. Indicates whether upper or lower part of matrix is retained. - Default is true. - -Returns -======= -output : Var - Type T. - Output tensor of the same type and shape as the input tensor. - -Notes -===== -Signature: ``ai.onnx@14::Trilu``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Trilu( - _Trilu.Attributes( - upper=AttrInt64(upper, name="upper"), - ), _Trilu.Inputs( - input=unwrap_vars(input), k=unwrap_vars(k), ), ).get_output_vars( - input=get_value(input), k=get_value(k), ).output - - -def unique(X: Var, *, axis: Optional[int] = None, sorted: int = 1, ) -> tuple[Var, Var, Var, Var]: - r""" -Find the unique elements of a tensor. When an optional attribute 'axis' -is provided, unique subtensors sliced along the 'axis' are returned. -Otherwise the input tensor is flattened and unique values of the -flattened tensor are returned. -This operator returns the unique values or sliced unique subtensors of -the input tensor and three optional outputs. The first output tensor 'Y' -contains all unique values or subtensors of the input. The second -optional output tensor 'indices' contains indices of 'Y' elements' first -occurrence in 'X'. The third optional output tensor 'inverse_indices' -contains, for elements of 'X', its corresponding indices in 'Y'. The -fourth optional output tensor 'counts' contains the count of each -element of 'Y' in the input. +def clip( + input: Var, + min: Optional[Var] = None, + max: Optional[Var] = None, +) -> Var: + r""" + Clip operator limits the given input within an interval. The interval is + specified by the inputs 'min' and 'max'. They default to + numeric_limits::lowest() and numeric_limits::max(), respectively. + + Parameters + ========== + input + Type T. + Input tensor whose elements to be clipped + min + Type T. + Minimum value, under which element is replaced by min. It must be a + scalar(tensor of empty shape). + max + Type T. + Maximum value, above which element is replaced by max. It must be a + scalar(tensor of empty shape). + + Returns + ======= + output : Var + Type T. + Output tensor with clipped input elements + + Notes + ===== + Signature: ``ai.onnx@13::Clip``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Clip( + _Clip.Attributes(), + _Clip.Inputs( + input=unwrap_vars(input), + min=unwrap_vars(min), + max=unwrap_vars(max), + ), + ) + .get_output_vars( + input=get_value(input), + min=get_value(min), + max=get_value(max), + ) + .output + ) + + +def compress( + input: Var, + condition: Var, + *, + axis: Optional[int] = None, +) -> Var: + r""" + Selects slices from an input tensor along a given axis where condition + evaluates to True for each axis index. In case axis is not provided, + input is flattened before elements are selected. Compress behaves like + numpy.compress: + https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html + + Parameters + ========== + input + Type T. + Tensor of rank r >= 1. + condition + Type T1. + Rank 1 tensor of booleans to indicate which slices or data elements to + be selected. Its length can be less than the input length along the axis + or the flattened input size if axis is not specified. In such cases data + slices or elements exceeding the condition length are discarded. + axis + Attribute. + (Optional) Axis along which to take slices. If not specified, input is + flattened before elements being selected. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + + Returns + ======= + output : Var + Type T. + Tensor of rank r if axis is specified. Otherwise output is a Tensor of + rank 1. + + Notes + ===== + Signature: ``ai.onnx@11::Compress``. + + Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return ( + _Compress( + _Compress.Attributes( + axis=AttrInt64.maybe(axis, name="axis"), + ), + _Compress.Inputs( + input=unwrap_vars(input), + condition=unwrap_vars(condition), + ), + ) + .get_output_vars( + input=get_value(input), + condition=get_value(condition), + ) + .output + ) + + +def concat( + inputs: Sequence[Var], + *, + axis: int, +) -> Var: + r""" + Concatenate a list of tensors into a single tensor. All input tensors + must have the same shape, except for the dimension size of the axis to + concatenate on. + + Parameters + ========== + inputs + Type T. + List of tensors for concatenation + axis + Attribute. + Which axis to concat on. A negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(inputs).. + + Returns + ======= + concat_result : Var + Type T. + Concatenated tensor + + Notes + ===== + Signature: ``ai.onnx@13::Concat``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Concat( + _Concat.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Concat.Inputs( + inputs=unwrap_vars(inputs), + ), + ) + .get_output_vars( + inputs=get_value(inputs), + ) + .concat_result + ) + + +def concat_from_sequence( + input_sequence: Var, + *, + axis: int, + new_axis: int = 0, +) -> Var: + r""" + Concatenate a sequence of tensors into a single tensor. All input + tensors must have the same shape, except for the dimension size of the + axis to concatenate on. By default 'new_axis' is 0, the behavior is + similar to numpy.concatenate. When 'new_axis' is 1, the behavior is + similar to numpy.stack. + + Parameters + ========== + input_sequence + Type S. + Sequence of tensors for concatenation + axis + Attribute. + Which axis to concat on. Accepted range in ``[-r, r - 1]``, where ``r`` + is the rank of input tensors. When ``new_axis`` is 1, accepted range is + ``[-r - 1, r]``. + new_axis + Attribute. + Insert and concatenate on a new axis or not, default 0 means do not + insert new axis. + + Returns + ======= + concat_result : Var + Type T. + Concatenated tensor + + Notes + ===== + Signature: ``ai.onnx@11::ConcatFromSequence``. + + Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _ConcatFromSequence( + _ConcatFromSequence.Attributes( + axis=AttrInt64(axis, name="axis"), + new_axis=AttrInt64(new_axis, name="new_axis"), + ), + _ConcatFromSequence.Inputs( + input_sequence=unwrap_vars(input_sequence), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + ) + .concat_result + ) + + +def constant( + *, + value: Optional[np.ndarray] = None, + value_float: Optional[float] = None, + value_floats: Optional[Iterable[float]] = None, + value_int: Optional[int] = None, + value_ints: Optional[Iterable[int]] = None, + value_string: Optional[str] = None, + value_strings: Optional[Iterable[str]] = None, +) -> Var: + r""" + This operator produces a constant tensor. Exactly one of the provided + attributes, either value, sparse_value, or value\_\* must be specified. + + Parameters + ========== + sparse_value + Attribute. + The value for the elements of the output tensor in sparse format. + value + Attribute. + The value for the elements of the output tensor. + value_float + Attribute. + The value for the sole element for the scalar, float32, output tensor. + value_floats + Attribute. + The values for the elements for the 1D, float32, output tensor. + value_int + Attribute. + The value for the sole element for the scalar, int64, output tensor. + value_ints + Attribute. + The values for the elements for the 1D, int64, output tensor. + value_string + Attribute. + The value for the sole element for the scalar, UTF-8 string, output + tensor. + value_strings + Attribute. + The values for the elements for the 1D, UTF-8 string, output tensor. + + Returns + ======= + output : Var + Type T. + Output tensor containing the same value of the provided tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Constant``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), + _Constant.Inputs(), + ) + .get_output_vars() + .output + ) + + +def constant_of_shape( + input: Var, + *, + value: Optional[np.ndarray] = None, +) -> Var: + r""" + Generate a tensor with given value and shape. + + Parameters + ========== + input + Type T1. + 1D tensor. The shape of the expected output tensor. If empty tensor is + given, the output would be a scalar. All values must be >= 0. + value + Attribute. + (Optional) The value of the output elements.Should be a one-element + tensor. If not specified, it defaults to a tensor of value 0 and + datatype float32 + + Returns + ======= + output : Var + Type T2. + Output tensor of shape specified by 'input'.If attribute 'value' is + specified, the value and datatype of the output tensor is taken from + 'value'.If attribute 'value' is not specified, the value in the output + defaults to 0, and the datatype defaults to float32. + + Notes + ===== + Signature: ``ai.onnx@9::ConstantOfShape``. + + Type constraints: + - T1: `tensor(int64)` + - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), + _ConstantOfShape.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def conv( + X: Var, + W: Var, + B: Optional[Var] = None, + *, + auto_pad: str = "NOTSET", + dilations: Optional[Iterable[int]] = None, + group: int = 1, + kernel_shape: Optional[Iterable[int]] = None, + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: + r""" + The convolution operator consumes an input tensor and a filter, and + computes the output. + + Parameters + ========== + X + Type T. + Input data tensor from previous layer; has size (N x C x H x W), where N + is the batch size, C is the number of channels, and H and W are the + height and width. Note that this is for the 2D image. Otherwise the size + is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in + effect, the operation expects input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. + W + Type T. + The weight tensor that will be used in the convolutions; has size (M x + C/group x kH x kW), where C is the number of channels, and kH and kW are + the height and width of the kernel, and M is the number of feature maps. + For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x + k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. + Optionally, if dimension denotation is in effect, the operation expects + the weight tensor to arrive with the dimension denotation of + [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL + ...]. Assuming zero based indices for the shape array, X.shape[1] == + (W.shape[1] \* group) == C and W.shape[0] mod G == 0. Or in other words + FILTER_IN_CHANNEL multiplied by the number of groups should be equal to + DATA_CHANNEL and the number of feature maps M should be a multiple of + the number of groups G. + B + Type T. + Optional 1D bias to be added to the convolution, has size of M. + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. + dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults is 1 along each spatial axis. + group + Attribute. + number of groups input channels and output channels are divided into. + kernel_shape + Attribute. + The shape of the convolution kernel. If not present, should be inferred + from input W. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults is 1 + along each spatial axis. + + Returns + ======= + Y : Var + Type T. + Output data tensor that contains the result of the convolution. The + output dimensions are functions of the kernel size, stride size, and pad + lengths. + + Notes + ===== + Signature: ``ai.onnx@11::Conv``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Conv( + _Conv.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _Conv.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + B=get_value(B), + ) + .Y + ) + + +def conv_integer( + x: Var, + w: Var, + x_zero_point: Optional[Var] = None, + w_zero_point: Optional[Var] = None, + *, + auto_pad: str = "NOTSET", + dilations: Optional[Iterable[int]] = None, + group: int = 1, + kernel_shape: Optional[Iterable[int]] = None, + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: + r""" + The integer convolution operator consumes an input tensor, its + zero-point, a filter, and its zero-point, and computes the output. The + production MUST never overflow. The accumulation may overflow if and + only if in 32 bits. + + Parameters + ========== + x + Type T1. + Input data tensor from previous layer; has size (N x C x H x W), where N + is the batch size, C is the number of channels, and H and W are the + height and width. Note that this is for the 2D image. Otherwise the size + is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in + effect, the operation expects input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. + w + Type T2. + The weight tensor that will be used in the convolutions; has size (M x + C/group x kH x kW), where C is the number of channels, and kH and kW are + the height and width of the kernel, and M is the number of feature maps. + For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x + k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. + Optionally, if dimension denotation is in effect, the operation expects + the weight tensor to arrive with the dimension denotation of + [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL + ...]. X.shape[1] == (W.shape[1] \* group) == C (assuming zero based + indices for the shape array). Or in other words FILTER_IN_CHANNEL should + be equal to DATA_CHANNEL. + x_zero_point + Type T1. + Zero point tensor for input 'x'. It's optional and default value is 0. + It's a scalar, which means a per-tensor/layer quantization. + w_zero_point + Type T2. + Zero point tensor for input 'w'. It's optional and default value is 0. + It could be a scalar or a 1-D tensor, which means a per-tensor/layer or + per output channel quantization. If it's a 1-D tensor, its number of + elements should be equal to the number of output channels (M) + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. + dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults to 1 along each axis. + group + Attribute. + number of groups input channels and output channels are divided into. + default is 1. + kernel_shape + Attribute. + The shape of the convolution kernel. If not present, should be inferred + from input 'w'. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0.The value represent the number + of pixels added to the beginning and end part of the corresponding + axis.\ ``pads`` format should be as follow [x1_begin, x2_begin...x1_end, + x2_end,...], where xi_begin the number ofpixels added at the beginning + of axis ``i`` and xi_end, the number of pixels added at the end of axis + ``i``.This attribute cannot be used simultaneously with auto_pad + attribute. If not present, the padding defaultsto 0 along start and end + of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each axis. + + Returns + ======= + y : Var + Type T3. + Output data tensor that contains the result of the convolution. The + output dimensions are functions of the kernel size, stride size, and pad + lengths. + + Notes + ===== + Signature: ``ai.onnx@10::ConvInteger``. + + Type constraints: + - T1: `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(int32)` + """ + return ( + _ConvInteger( + _ConvInteger.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _ConvInteger.Inputs( + x=unwrap_vars(x), + w=unwrap_vars(w), + x_zero_point=unwrap_vars(x_zero_point), + w_zero_point=unwrap_vars(w_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + w=get_value(w), + x_zero_point=get_value(x_zero_point), + w_zero_point=get_value(w_zero_point), + ) + .y + ) + + +def conv_transpose( + X: Var, + W: Var, + B: Optional[Var] = None, + *, + auto_pad: str = "NOTSET", + dilations: Optional[Iterable[int]] = None, + group: int = 1, + kernel_shape: Optional[Iterable[int]] = None, + output_padding: Optional[Iterable[int]] = None, + output_shape: Optional[Iterable[int]] = None, + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: + r""" + The convolution transpose operator consumes an input tensor and a + filter, and computes the output. + + If the pads parameter is provided the shape of the output is calculated + via the following equation: + + output_shape[i] = stride[i] \* (input_size[i] - 1) + output_padding[i] + + ((kernel_shape[i] - 1) \* dilations[i] + 1) - pads[start_i] - + pads[end_i] + + output_shape can also be explicitly specified in which case pads values + are auto generated using these equations: + + total_padding[i] = stride[i] \* (input_size[i] - 1) + output_padding[i] + + ((kernel_shape[i] - 1) \* dilations[i] + 1) - output_shape[i] If + (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; + pads[end_i] = total_padding[i] - (total_padding[i]/2) Else: + pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = + (total_padding[i]/2). + + Parameters + ========== + X + Type T. + Input data tensor from previous layer; has size (N x C x H x W), where N + is the batch size, C is the number of channels, and H and W are the + height and width. Note that this is for the 2D image. Otherwise the size + is (N x C x D1 x D2 ... x Dn) + W + Type T. + The weight tensor that will be used in the convolutions; has size (C x + M/group x kH x kW), where C is the number of channels, and kH and kW are + the height and width of the kernel, and M is the number of feature maps. + For more than 2 dimensions, the weight shape will be (C x M/group x k1 x + k2 x ... x kn), where (k1 x k2 x ... x kn) is the dimension of the + kernel. The number of channels in the output should be equal to + W.shape[1] \* group (assuming zero based indices of the shape array) + B + Type T. + Optional 1D bias to be added to the convolution, has size of M. + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = input_shape[i] * strides[i]`` for each axis ``i``. + The padding is split between the two sides equally or almost equally + (depending on whether it is even or odd). In case the padding is an odd + number, the extra padding is added at the end for SAME_UPPER and at the + beginning for SAME_LOWER. + dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults to 1 along each spatial axis. + group + Attribute. + number of groups input channels and output channels are divided into. + kernel_shape + Attribute. + The shape of the convolution kernel. If not present, should be inferred + from input W. + output_padding + Attribute. + Additional elements added to the side with higher coordinate indices in + the output. Each padding value in "output_padding" must be less than the + corresponding stride/dilation dimension. By default, this attribute is a + zero vector. Note that this attribute doesn't directly affect the + computed output values. It only controls the selection of the computed + values, so changing this attribute only adds or removes output elements. + If "output_shape" is explicitly provided, "output_padding" does not + contribute additional size to "output_shape" but participates in the + computation of the needed padding amount. This is also called adjs or + adjustment in some frameworks. + output_shape + Attribute. + The shape of the output can be explicitly set which will cause pads + values to be auto generated. If output_shape is specified pads values + are ignored. See doc for details for equations to generate pads. Note + that the output_shape attribute value should not include dimensions for + batch size and channels, which are automatically inferred. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + + Returns + ======= + Y : Var + Type T. + Output data tensor that contains the result of the convolution. The + output dimensions are functions of the kernel size, stride size, pad + lengths and group count. The number of channels in the output should be + equal to W.shape[1] \* group (assuming zero based indices of the shape + array) + + Notes + ===== + Signature: ``ai.onnx@11::ConvTranspose``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _ConvTranspose( + _ConvTranspose.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + output_padding=AttrInt64s.maybe(output_padding, name="output_padding"), + output_shape=AttrInt64s.maybe(output_shape, name="output_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _ConvTranspose.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + B=get_value(B), + ) + .Y + ) + + +def cos( + input: Var, +) -> Var: + r""" + Calculates the cosine of the given input tensor, element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The cosine of the input tensor computed element-wise + + Notes + ===== + Signature: ``ai.onnx@7::Cos``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Cos( + _Cos.Attributes(), + _Cos.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def cosh( + input: Var, +) -> Var: + r""" + Calculates the hyperbolic cosine of the given input tensor element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The hyperbolic cosine values of the input tensor computed element-wise + + Notes + ===== + Signature: ``ai.onnx@9::Cosh``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Cosh( + _Cosh.Attributes(), + _Cosh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def cumsum( + x: Var, + axis: Var, + *, + exclusive: int = 0, + reverse: int = 0, +) -> Var: + r""" + Performs cumulative sum of the input elements along the given axis. By + default, it will do the sum inclusively meaning the first element is + copied as is. Through an ``exclusive`` attribute, this behavior can + change to exclude the first element. It can also perform summation in + the opposite direction of the axis. For that, set ``reverse`` attribute + to 1. + + Example: + + :: + + input_x = [1, 2, 3] + axis=0 + output = [1, 3, 6] + exclusive=1 + output = [0, 1, 3] + exclusive=0 + reverse=1 + output = [6, 5, 3] + exclusive=1 + reverse=1 + output = [5, 3, 0] + + Parameters + ========== + x + Type T. + An input tensor that is to be processed. + axis + Type T2. + A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value + means counting dimensions from the back. + exclusive + Attribute. + If set to 1 will return exclusive sum in which the top element is not + included. In other terms, if set to 1, the j-th output element would be + the sum of the first (j-1) elements. Otherwise, it would be the sum of + the first j elements. + reverse + Attribute. + If set to 1 will perform the sums in reverse direction. + + Returns + ======= + y : Var + Type T. + Output tensor of the same type as 'x' with cumulative sums of the x's + elements + + Notes + ===== + Signature: ``ai.onnx@14::CumSum``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return ( + _CumSum( + _CumSum.Attributes( + exclusive=AttrInt64(exclusive, name="exclusive"), + reverse=AttrInt64(reverse, name="reverse"), + ), + _CumSum.Inputs( + x=unwrap_vars(x), + axis=unwrap_vars(axis), + ), + ) + .get_output_vars( + x=get_value(x), + axis=get_value(axis), + ) + .y + ) + + +def dft( + input: Var, + dft_length: Optional[Var] = None, + *, + axis: int = 1, + inverse: int = 0, + onesided: int = 0, +) -> Var: + r""" + Computes the discrete Fourier transform of input. + + Parameters + ========== + input + Type T1. + For real input, the following shape is expected: + [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][1]. For complex + input, the following shape is expected: + [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][2]. The first + dimension is the batch dimension. The following N dimensions correspond + to the signal's dimensions. The final dimension represents the real and + imaginary parts of the value in that order. + dft_length + Type T2. + The length of the signal as a scalar. If greater than the axis + dimension, the signal will be zero-padded up to dft_length. If less than + the axis dimension, only the first dft_length values will be used as the + signal. It's an optional value. + axis + Attribute. + The axis on which to perform the DFT. By default this value is set to 1, + which corresponds to the first dimension after the batch index. Negative + value means counting dimensions from the back. Accepted range is + :math:`[-r, -2] \cup [0, r-2]` where ``r = rank(input)``. The last + dimension is for representing complex numbers and thus is an invalid + axis. + inverse + Attribute. + Whether to perform the inverse discrete fourier transform. By default + this value is set to 0, which corresponds to false. + onesided + Attribute. + If onesided is 1, only values for w in [0, 1, 2, ..., floor(n_fft/2) + + 1] are returned because the real-to-complex Fourier transform satisfies + the conjugate symmetry, i.e., X[m, w] = X[m, n_fft-w]\*. Note if the + input or window tensors are complex, then onesided output is not + possible. Enabling onesided with real inputs performs a Real-valued fast + Fourier transform (RFFT). When invoked with real or complex valued + input, the default value is 0. Values can be 0 or 1. + + Returns + ======= + output : Var + Type T1. + The Fourier Transform of the input vector. If onesided is 0, the + following shape is expected: + [batch_idx][signal_dim1][signal_dim2]...[signal_dimN][2]. If axis=1 and + onesided is 1, the following shape is expected: + [batch_idx][floor(signal_dim1/2)+1][signal_dim2]...[signal_dimN][2]. If + axis=2 and onesided is 1, the following shape is expected: + [batch_idx][signal_dim1][floor(signal_dim2/2)+1]...[signal_dimN][2]. If + axis=N and onesided is 1, the following shape is expected: + [batch_idx][signal_dim1][signal_dim2]...[floor(signal_dimN/2)+1][2]. The + signal_dim at the specified axis is equal to the dft_length. + + Notes + ===== + Signature: ``ai.onnx@17::DFT``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return ( + _DFT( + _DFT.Attributes( + axis=AttrInt64(axis, name="axis"), + inverse=AttrInt64(inverse, name="inverse"), + onesided=AttrInt64(onesided, name="onesided"), + ), + _DFT.Inputs( + input=unwrap_vars(input), + dft_length=unwrap_vars(dft_length), + ), + ) + .get_output_vars( + input=get_value(input), + dft_length=get_value(dft_length), + ) + .output + ) + + +def depth_to_space( + input: Var, + *, + blocksize: int, + mode: str = "DCR", +) -> Var: + r""" + DepthToSpace rearranges (permutes) data from depth into blocks of + spatial data. This is the reverse transformation of SpaceToDepth. More + specifically, this op outputs a copy of the input tensor where values + from the depth dimension are moved in spatial blocks to the height and + width dimensions. By default, ``mode`` = ``DCR``. In the DCR mode, + elements along the depth dimension from the input tensor are rearranged + in the following order: depth, column, and then row. The output y is + computed from the input x as below: + + :: + + b, c, h, w = x.shape + tmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w]) + tmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2]) + y = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize]) + + In the CRD mode, elements along the depth dimension from the input + tensor are rearranged in the following order: column, row, and the + depth. The output y is computed from the input x as below: + + :: + + b, c, h, w = x.shape + tmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w]) + tmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3]) + y = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize]) + + Parameters + ========== + input + Type T. + Input tensor of [N,C,H,W], where N is the batch axis, C is the channel + or depth, H is the height and W is the width. + blocksize + Attribute. + Blocks of [blocksize, blocksize] are moved. + mode + Attribute. + DCR (default) for depth-column-row order re-arrangement. Use CRD for + column-row-depth order. + + Returns + ======= + output : Var + Type T. + Output tensor of [N, C/(blocksize \* blocksize), H \* blocksize, W \* + blocksize]. + + Notes + ===== + Signature: ``ai.onnx@13::DepthToSpace``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _DepthToSpace( + _DepthToSpace.Attributes( + blocksize=AttrInt64(blocksize, name="blocksize"), + mode=AttrString(mode, name="mode"), + ), + _DepthToSpace.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def dequantize_linear( + x: Var, + x_scale: Var, + x_zero_point: Optional[Var] = None, + *, + axis: int = 1, +) -> Var: + r""" + The linear dequantization operator. It consumes a quantized tensor, a + scale, and a zero point to compute the full precision tensor. The + dequantization formula is ``y = (x - x_zero_point) * x_scale``. + ``x_scale`` and ``x_zero_point`` must have same shape, and can be either + a scalar for per-tensor / per layer quantization, or a 1-D tensor for + per-axis quantization. ``x_zero_point`` and ``x`` must have same type. + ``x`` and ``y`` must have same shape. In the case of dequantizing int32, + there's no zero point (zero point is supposed to be 0). + + Parameters + ========== + x + Type T. + N-D quantized input tensor to be de-quantized. + x_scale + Type tensor(float). + Scale for input 'x'. It can be a scalar, which means a per-tensor/layer + dequantization, or a 1-D tensor for per-axis dequantization. + x_zero_point + Type T. + Zero point for input 'x'. Shape must match x_scale. It's optional. Zero + point is 0 when it's not specified. + axis + Attribute. + (Optional) The axis of the dequantizing dimension of the input tensor. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + + Returns + ======= + y : Var + Type tensor(float). + N-D full precision output tensor. It has same shape as input 'x'. + + Notes + ===== + Signature: ``ai.onnx@13::DequantizeLinear``. + + Type constraints: + - T: `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` + """ + return ( + _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _DequantizeLinear.Inputs( + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + ) + .y + ) + + +def det( + X: Var, +) -> Var: + r""" + Det calculates determinant of a square matrix or batches of square + matrices. Det takes one input tensor of shape ``[*, M, M]``, where ``*`` + is zero or more batch dimensions, and the inner-most 2 dimensions form + square matrices. The output is a tensor of shape ``[*]``, containing the + determinants of all input submatrices. e.g., When the input is 2-D, the + output is a scalar(shape is empty: ``[]``). + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@11::Det``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Det( + _Det.Attributes(), + _Det.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def div( + A: Var, + B: Var, +) -> Var: + r""" + Performs element-wise binary division (with Numpy-style broadcasting + support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + (Opset 14 change): Extend supported types to include uint8, int8, + uint16, and int16. + + Parameters + ========== + A + Type T. + First operand. + B + Type T. + Second operand. + + Returns + ======= + C : Var + Type T. + Result, has same element type as two inputs + + Notes + ===== + Signature: ``ai.onnx@14::Div``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Div( + _Div.Attributes(), + _Div.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def dropout( + data: Var, + ratio: Optional[Var] = None, + training_mode: Optional[Var] = None, + *, + seed: Optional[int] = None, +) -> tuple[Var, Var]: + r""" + Dropout takes an input floating-point tensor, an optional input ratio + (floating-point scalar) and an optional input training_mode (boolean + scalar). It produces two tensor outputs, output (floating-point tensor) + and mask (optional ``Tensor``). If ``training_mode`` is true then + the output Y will be a random dropout; Note that this Dropout scales the + masked input data by the following equation, so to convert the trained + model into inference mode, the user can simply not pass + ``training_mode`` input or set it to false. + + :: + + output = scale * data * mask, + + where + + :: + + scale = 1. / (1. - ratio). + + This operator has **optional** inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty string + may be used in the place of an actual argument's name to indicate a + missing argument. Trailing optional arguments (those not followed by an + argument that is present) may also be simply omitted. + + Parameters + ========== + data + Type T. + The input data as Tensor. + ratio + Type T1. + The ratio of random dropout, with value in [0, 1). If this input was not + set, or if it was set to 0, the output would be a simple copy of the + input. If it's non-zero, output will be a random dropout of the scaled + input, which is typically the case during training. It is an optional + value, if not specified it will default to 0.5. + training_mode + Type T2. + If set to true then it indicates dropout is being used for training. It + is an optional value hence unless specified explicitly, it is false. If + it is false, ratio is ignored and the operation mimics inference mode + where nothing will be dropped from the input data and if mask is + requested as output it will contain all ones. + seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + + Returns + ======= + output : Var + Type T. + The output. + mask : Var + Type T2. + The output mask. + + Notes + ===== + Signature: ``ai.onnx@13::Dropout``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(bool)` + """ + return ( + _Dropout( + _Dropout.Attributes( + seed=AttrInt64.maybe(seed, name="seed"), + ), + _Dropout.Inputs( + data=unwrap_vars(data), + ratio=unwrap_vars(ratio), + training_mode=unwrap_vars(training_mode), + ), + ) + .get_output_vars( + data=get_value(data), + ratio=get_value(ratio), + training_mode=get_value(training_mode), + ) + ._unpack_to_any() + ) + + +def dynamic_quantize_linear( + x: Var, +) -> tuple[Var, Var, Var]: + r""" + A Function to fuse calculation for Scale, Zero Point and FP32->8Bit + conversion of FP32 Input data. Outputs Scale, ZeroPoint and Quantized + Input for a given FP32 Input. Scale is calculated as: + + :: + + y_scale = (maximum(0, max(x)) - minimum(0, min(x))) / (qmax - qmin) + + - where qmax and qmin are max and min values for quantization range + i.e. [0, 255] in case of uint8 + - data range is adjusted to include 0. + + Zero point is calculated as: + + :: + + intermediate_zero_point = qmin - min(x)/y_scale + y_zero_point = cast(round(saturate(itermediate_zero_point))) + + - where qmax and qmin are max and min values for quantization range + .i.e [0, 255] in case of uint8 + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, + 127] if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. + + Data quantization formula is: + + :: + + y = saturate (round (x / y_scale) + y_zero_point) + + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, + 127] if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. + + Parameters + ========== + x + Type T1. + Input tensor + + Returns + ======= + y : Var + Type T2. + Quantized output tensor + y_scale : Var + Type tensor(float). + Output scale. It's a scalar, which means a per-tensor/layer + quantization. + y_zero_point : Var + Type T2. + Output zero point. It's a scalar, which means a per-tensor/layer + quantization. + + Notes + ===== + Signature: ``ai.onnx@11::DynamicQuantizeLinear``. + + Type constraints: + - T1: `tensor(float)` + - T2: `tensor(uint8)` + """ + return ( + _DynamicQuantizeLinear( + _DynamicQuantizeLinear.Attributes(), + _DynamicQuantizeLinear.Inputs( + x=unwrap_vars(x), + ), + ) + .get_output_vars( + x=get_value(x), + ) + ._unpack_to_any() + ) + + +def einsum( + Inputs: Sequence[Var], + *, + equation: str, +) -> Var: + r""" + An einsum of the form ``term1, term2 -> output-term`` produces an output + tensor using the following equation + + :: + + output[output-term] = reduce-sum( input1[term1] * input2[term2] ) + + where the reduce-sum performs a summation over all the indices occurring + in the input terms (term1, term2) that do not occur in the output-term. + + The Einsum operator evaluates algebraic tensor operations on a sequence + of tensors, using the Einstein summation convention. The equation string + contains a comma-separated sequence of lower case letters. Each term + corresponds to an operand tensor, and the characters within the terms + correspond to operands dimensions. + + This sequence may be followed by "->" to separate the left and right + hand side of the equation. If the equation contains "->" followed by the + right-hand side, the explicit (not classical) form of the Einstein + summation is performed, and the right-hand side indices indicate output + tensor dimensions. In other cases, output indices are (implicitly) set + to the alphabetically sorted sequence of indices appearing exactly once + in the equation. + + When a dimension character is repeated in the left-hand side, it + represents summation along the dimension. + + The equation may contain ellipsis ("...") to enable broadcasting. + Ellipsis must indicate a fixed number of dimensions. Specifically, every + occurrence of ellipsis in the equation must represent the same number of + dimensions. The right-hand side may contain exactly one ellipsis. In + implicit mode, the ellipsis dimensions are set to the beginning of the + output. The equation string may contain space (U+0020) character. + + Parameters + ========== + Inputs + Type T. + Operands + equation + Attribute. + Einsum expression string. + + Returns + ======= + Output : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@12::Einsum``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Einsum( + _Einsum.Attributes( + equation=AttrString(equation, name="equation"), + ), + _Einsum.Inputs( + Inputs=unwrap_vars(Inputs), + ), + ) + .get_output_vars( + Inputs=get_value(Inputs), + ) + .Output + ) + + +def elu( + X: Var, + *, + alpha: float = 1.0, +) -> Var: + r""" + Elu takes one input data (Tensor) and produces one output data + (Tensor) where the function + ``f(x) = alpha * (exp(x) - 1.) for x < 0``, ``f(x) = x for x >= 0``., is + applied to the tensor elementwise. + + Parameters + ========== + X + Type T. + 1D input tensor + alpha + Attribute. + Coefficient of ELU. + + Returns + ======= + Y : Var + Type T. + 1D output tensor + + Notes + ===== + Signature: ``ai.onnx@6::Elu``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Elu( + _Elu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), + _Elu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def equal( + A: Var, + B: Var, +) -> Var: + r""" + Returns the tensor resulted from performing the ``equal`` logical + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Equal``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return ( + _Equal( + _Equal.Attributes(), + _Equal.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def erf( + input: Var, +) -> Var: + r""" + Computes the error function of the given input tensor element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The error function of the input tensor computed element-wise. It has the + same shape and type of the input. + + Notes + ===== + Signature: ``ai.onnx@13::Erf``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Erf( + _Erf.Attributes(), + _Erf.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def exp( + input: Var, +) -> Var: + r""" + Calculates the exponential of the given input tensor, element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The exponential of the input tensor computed element-wise + + Notes + ===== + Signature: ``ai.onnx@13::Exp``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Exp( + _Exp.Attributes(), + _Exp.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def expand( + input: Var, + shape: Var, +) -> Var: + r""" + Broadcast the input tensor following the given shape and the broadcast + rule. The broadcast rule is similar to numpy.array(input) \* + numpy.ones(shape): Dimensions are right alignment; Two corresponding + dimensions must have the same value, or one of them is equal to 1. Also, + this operator is similar to numpy.broadcast_to(input, shape), but the + major difference is numpy.broadcast_to() does not allow shape to be + smaller than input.size(). It is possible that the output.shape is not + equal to shape, when some dimensions in shape is equal to 1, or the + shape.ndim < input.shape.ndim. + + Parameters + ========== + input + Type T. + Input tensor + shape + Type tensor(int64). + A 1-D tensor indicates the shape you want to expand to, following the + broadcast rule + + Returns + ======= + output : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::Expand``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Expand( + _Expand.Attributes(), + _Expand.Inputs( + input=unwrap_vars(input), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + input=get_value(input), + shape=get_value(shape), + ) + .output + ) + + +def eye_like( + input: Var, + *, + dtype: Optional[npt.DTypeLike] = None, + k: int = 0, +) -> Var: + r""" + Generate a 2D tensor (matrix) with ones on the diagonal and zeros + everywhere else. Only 2D tensors are supported, i.e. input T1 must be of + rank 2. The shape of the output tensor is the same as the input tensor. + The data type can be specified by the 'dtype' argument. If 'dtype' is + not specified, then the type of input tensor is used. By default, the + main diagonal is populated with ones, but attribute 'k' can be used to + populate upper or lower diagonals. The 'dtype' argument must be one of + the data types specified in the 'DataType' enum field in the TensorProto + message and be valid as an output type. + + Parameters + ========== + input + Type T1. + 2D input tensor to copy shape, and optionally, type information from. + dtype + Attribute. + (Optional) The data type for the elements of the output tensor. If not + specified,the data type of the input tensor T1 is used. If input tensor + T1 is also notspecified, then type defaults to 'float'. + k + Attribute. + (Optional) Index of the diagonal to be populated with ones. Default is + 0. If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the + main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a + lower diagonal. + + Returns + ======= + output : Var + Type T2. + Output tensor, same shape as input tensor T1. + + Notes + ===== + Signature: ``ai.onnx@9::EyeLike``. + + Type constraints: + - T1: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _EyeLike( + _EyeLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + k=AttrInt64(k, name="k"), + ), + _EyeLike.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def flatten( + input: Var, + *, + axis: int = 1, +) -> Var: + r""" + Flattens the input tensor into a 2D matrix. If input tensor has shape + (d_0, d_1, ... d_n) then the output will have shape (d_0 X d_1 ... + d\_(axis-1), d_axis X d\_(axis+1) ... X dn). + + Parameters + ========== + input + Type T. + A tensor of rank >= axis. + axis + Attribute. + Indicate up to which input dimensions (exclusive) should be flattened to + the outer dimension of the output. The value for axis must be in the + range [-r, r], where r is the rank of the input tensor. Negative value + means counting dimensions from the back. When axis = 0, the shape of the + output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input + tensor is (d_0, d_1, ... d_n). + + Returns + ======= + output : Var + Type T. + A 2D tensor with the contents of the input tensor, with input dimensions + up to axis flattened to the outer dimension of the output and remaining + input dimensions flattened into the inner dimension of the output. + + Notes + ===== + Signature: ``ai.onnx@13::Flatten``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Flatten( + _Flatten.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Flatten.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def floor( + X: Var, +) -> Var: + r""" + Floor takes one input data (Tensor) and produces one output data + (Tensor) where the floor is, y = floor(x), is applied to the tensor + elementwise. If x is integral, +0, -0, NaN, or infinite, x itself is + returned. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::Floor``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Floor( + _Floor.Attributes(), + _Floor.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def gru( + X: Var, + W: Var, + R: Var, + B: Optional[Var] = None, + sequence_lens: Optional[Var] = None, + initial_h: Optional[Var] = None, + *, + activation_alpha: Optional[Iterable[float]] = None, + activation_beta: Optional[Iterable[float]] = None, + activations: Optional[Iterable[str]] = None, + clip: Optional[float] = None, + direction: str = "forward", + hidden_size: Optional[int] = None, + layout: int = 0, + linear_before_reset: int = 0, +) -> tuple[Var, Var]: + r""" + Computes an one-layer GRU. This operator is usually supported via some + custom implementation such as CuDNN. + + Notations: + + - ``X`` - input tensor + - ``z`` - update gate + - ``r`` - reset gate + - ``h`` - hidden gate + - ``t`` - time step (t-1 means previous time step) + - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden + gates + - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden + gates + - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates + - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates + - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, + and hidden gates + - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, + and hidden gates + - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden + gates + - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden + gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 + + Activation functions: + + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) + + NOTE: Below are optional + + - Affine(x) - alpha \* x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha \* Tanh(beta \* x) + - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh): + + - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) + - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when + linear_before_reset = 0 + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when + linear_before_reset != 0 + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** + inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. + + Parameters + ========== + X + Type T. + The input sequences packed (and potentially padded) into one 3-D tensor + with the shape of ``[seq_length, batch_size, input_size]``. + W + Type T. + The weight tensor for the gates. Concatenation of ``W[zrh]`` and + ``WB[zrh]`` (if bidirectional) along dimension 0. This tensor has shape + ``[num_directions, 3*hidden_size, input_size]``. + R + Type T. + The recurrence weight tensor. Concatenation of ``R[zrh]`` and + ``RB[zrh]`` (if bidirectional) along dimension 0. This tensor has shape + ``[num_directions, 3*hidden_size, hidden_size]``. + B + Type T. + The bias tensor for the gates. Concatenation of ``[Wb[zrh], Rb[zrh]]`` + and ``[WBb[zrh], RBb[zrh]]`` (if bidirectional) along dimension 0. This + tensor has shape ``[num_directions, 6*hidden_size]``. Optional: If not + specified - assumed to be 0 + sequence_lens + Type T1. + Optional tensor specifying lengths of the sequences in a batch. If not + specified - assumed all sequences in the batch to have length + ``seq_length``. It has shape ``[batch_size]``. + initial_h + Type T. + Optional initial value of the hidden. If not specified - assumed to be + 0. It has shape ``[num_directions, batch_size, hidden_size]``. + activation_alpha + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX + operators.For example with LeakyRelu, the default alpha is 0.01. + activation_beta + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX operators. + activations + Attribute. + A list of 2 (or 4 if bidirectional) activation functions for update, + reset, and hidden gates. The activation functions must be one of the + activation functions specified above. Optional: See the equations for + default if not specified. + clip + Attribute. + Cell clip threshold. Clipping bounds the elements of a tensor in the + range of [-threshold, +threshold] and is applied to the input of + activations. No clip if not specified. + direction + Attribute. + Specify if the RNN is forward, reverse, or bidirectional. Must be one of + forward (default), reverse, or bidirectional. + hidden_size + Attribute. + Number of neurons in the hidden layer + layout + Attribute. + The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the + following shapes are expected: X.shape = [seq_length, batch_size, + input_size], Y.shape = [seq_length, num_directions, batch_size, + hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, + hidden_size]. If 1, the following shapes are expected: X.shape = + [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, + num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, + num_directions, hidden_size]. + linear_before_reset + Attribute. + When computing the output of the hidden gate, apply the linear + transformation before multiplying by the output of the reset gate. + + Returns + ======= + Y : Var + Type T. + A tensor that concats all the intermediate output values of the hidden. + It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. + Y_h : Var + Type T. + The last output value of the hidden. It has shape + ``[num_directions, batch_size, hidden_size]``. + + Notes + ===== + Signature: ``ai.onnx@14::GRU``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(int32)` + """ + return ( + _GRU( + _GRU.Attributes( + activation_alpha=AttrFloat32s.maybe( + activation_alpha, name="activation_alpha" + ), + activation_beta=AttrFloat32s.maybe( + activation_beta, name="activation_beta" + ), + activations=AttrStrings.maybe(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + layout=AttrInt64(layout, name="layout"), + linear_before_reset=AttrInt64( + linear_before_reset, name="linear_before_reset" + ), + ), + _GRU.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + R=unwrap_vars(R), + B=unwrap_vars(B), + sequence_lens=unwrap_vars(sequence_lens), + initial_h=unwrap_vars(initial_h), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + R=get_value(R), + B=get_value(B), + sequence_lens=get_value(sequence_lens), + initial_h=get_value(initial_h), + ) + ._unpack_to_any() + ) + + +def gather( + data: Var, + indices: Var, + *, + axis: int = 0, +) -> Var: + r""" + Given ``data`` tensor of rank r >= 1, and ``indices`` tensor of rank q, + gather entries of the axis dimension of ``data`` (by default outer-most + one as axis=0) indexed by ``indices``, and concatenates them in an + output tensor of rank q + (r - 1). + + If ``axis = 0``, let ``k = indices[i_{0}, ..., i_{q-1}]`` then + ``output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]``: + + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + indices = [ + [0, 1], + [1, 2], + ] + output = [ + [ + [1.0, 1.2], + [2.3, 3.4], + ], + [ + [2.3, 3.4], + [4.5, 5.7], + ], + ] + + If ``axis = 1``, let ``k = indices[i_{0}, ..., i_{q-1}]`` then + ``output[j_{0}, i_{0}, ..., i_{q-1}, j_{1}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]``: + + :: + + data = [ + [1.0, 1.2, 1.9], + [2.3, 3.4, 3.9], + [4.5, 5.7, 5.9], + ] + indices = [ + [0, 2], + ] + axis = 1, + output = [ + [[1.0, 1.9]], + [[2.3, 3.9]], + [[4.5, 5.9]], + ] + + Parameters + ========== + data + Type T. + Tensor of rank r >= 1. + indices + Type Tind. + Tensor of int32/int64 indices, of any rank q. All index values are + expected to be within bounds [-s, s-1] along axis of size s. It is an + error if any of the index values are out of bounds. + axis + Attribute. + Which axis to gather on. Negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(data). + + Returns + ======= + output : Var + Type T. + Tensor of rank q + (r - 1). + + Notes + ===== + Signature: ``ai.onnx@13::Gather``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return ( + _Gather( + _Gather.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Gather.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + ) + .output + ) + + +def gather_elements( + data: Var, + indices: Var, + *, + axis: int = 0, +) -> Var: + r""" + GatherElements takes two inputs ``data`` and ``indices`` of the same + rank r >= 1 and an optional attribute ``axis`` that identifies an axis + of ``data`` (by default, the outer-most axis, that is axis 0). It is an + indexing operation that produces its output by indexing into the input + data tensor at index positions determined by elements of the ``indices`` + tensor. Its output shape is the same as the shape of ``indices`` and + consists of one value (gathered from the ``data``) for each element in + ``indices``. + + For instance, in the 3-D case (r = 3), the output produced is determined + by the following equations: + + :: + + out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0, + out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1, + out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2, + + This operator is also the inverse of ScatterElements. It is similar to + Torch's gather operation. + + Example 1: + + :: + + data = [ + [1, 2], + [3, 4], + ] + indices = [ + [0, 0], + [1, 0], + ] + axis = 1 + output = [ + [1, 1], + [4, 3], + ] + + Example 2: + + :: + + data = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + ] + indices = [ + [1, 2, 0], + [2, 0, 0], + ] + axis = 0 + output = [ + [4, 8, 3], + [7, 2, 3], + ] + + Parameters + ========== + data + Type T. + Tensor of rank r >= 1. + indices + Type Tind. + Tensor of int32/int64 indices, with the same rank r as the input. All + index values are expected to be within bounds [-s, s-1] along axis of + size s. It is an error if any of the index values are out of bounds. + axis + Attribute. + Which axis to gather on. Negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(data). + + Returns + ======= + output : Var + Type T. + Tensor of the same shape as indices. + + Notes + ===== + Signature: ``ai.onnx@13::GatherElements``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return ( + _GatherElements( + _GatherElements.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _GatherElements.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + ) + .output + ) + + +def gather_nd( + data: Var, + indices: Var, + *, + batch_dims: int = 0, +) -> Var: + r""" + Given ``data`` tensor of rank ``r`` >= 1, ``indices`` tensor of rank + ``q`` >= 1, and ``batch_dims`` integer ``b``, this operator gathers + slices of ``data`` into an output tensor of rank + ``q + r - indices_shape[-1] - 1 - b``. + + ``indices`` is an q-dimensional integer tensor, best thought of as a + ``(q-1)``-dimensional tensor of index-tuples into ``data``, where each + element defines a slice of ``data`` + + ``batch_dims`` (denoted as ``b``) is an integer indicating the number of + batch dimensions, i.e the leading ``b`` number of dimensions of ``data`` + tensor and ``indices`` are representing the batches, and the gather + starts from the ``b+1`` dimension. + + Some salient points about the inputs' rank and shape: + + 1) r >= 1 and q >= 1 are to be honored. There is no dependency condition + to be met between ranks ``r`` and ``q`` + + 2) The first ``b`` dimensions of the shape of ``indices`` tensor and + ``data`` tensor must be equal. + + 3) b < min(q, r) is to be honored. + + 4) The ``indices_shape[-1]`` should have a value between 1 (inclusive) + and rank ``r-b`` (inclusive) + + 5) All values in ``indices`` are expected to be within bounds [-s, s-1] + along axis of size ``s`` (i.e.) + ``-data_shape[i] <= indices[...,i] <= data_shape[i] - 1``. It is an + error if any of the index values are out of bounds. + + The output is computed as follows: + + The output tensor is obtained by mapping each index-tuple in the + ``indices`` tensor to the corresponding slice of the input ``data``. + + 1) If ``indices_shape[-1] > r-b`` => error condition + + 2) If ``indices_shape[-1] == r-b``, since the rank of ``indices`` is + ``q``, ``indices`` can be thought of as ``N`` ``(q-b-1)``-dimensional + tensors containing 1-D tensors of dimension ``r-b``, where ``N`` is + an integer equals to the product of 1 and all the elements in the + batch dimensions of the indices_shape. Let us think of each such + ``r-b`` ranked tensor as ``indices_slice``. Each *scalar value* + corresponding to ``data[0:b-1,indices_slice]`` is filled into the + corresponding location of the ``(q-b-1)``-dimensional tensor to form + the ``output`` tensor (Example 1 below) + + 3) If ``indices_shape[-1] < r-b``, since the rank of ``indices`` is + ``q``, ``indices`` can be thought of as ``N`` ``(q-b-1)``-dimensional + tensor containing 1-D tensors of dimension ``< r-b``. Let us think of + each such tensors as ``indices_slice``. Each *tensor slice* + corresponding to ``data[0:b-1, indices_slice , :]`` is filled into + the corresponding location of the ``(q-b-1)``-dimensional tensor to + form the ``output`` tensor (Examples 2, 3, 4 and 5 below) + + This operator is the inverse of ``ScatterND``. + + **Example 1** + + :: + + batch_dims = 0 + data = [[0,1],[2,3]] # data_shape = [2, 2] + indices = [[0,0],[1,1]] # indices_shape = [2, 2] + output = [0,3] # output_shape = [2] + + **Example 2** + + :: + + batch_dims = 0 + data = [[0,1],[2,3]] # data_shape = [2, 2] + indices = [[1],[0]] # indices_shape = [2, 1] + output = [[2,3],[0,1]] # output_shape = [2, 2] + + **Example 3** + + :: + + batch_dims = 0 + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + indices = [[0,1],[1,0]] # indices_shape = [2, 2] + output = [[2,3],[4,5]] # output_shape = [2, 2] + + **Example 4** + + :: + + batch_dims = 0 + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2] + output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2] + + **Example 5** + + :: + + batch_dims = 1 + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + indices = [[1],[0]] # indices_shape = [2, 1] + output = [[2,3],[4,5]] # output_shape = [2, 2] + + Parameters + ========== + data + Type T. + Tensor of rank r >= 1. + indices + Type tensor(int64). + Tensor of rank q >= 1. All index values are expected to be within bounds + [-s, s-1] along axis of size s. It is an error if any of the index + values are out of bounds. + batch_dims + Attribute. + The number of batch dimensions. The gather of indexing starts from + dimension of data[batch_dims:] + + Returns + ======= + output : Var + Type T. + Tensor of rank q + r - indices_shape[-1] - 1. + + Notes + ===== + Signature: ``ai.onnx@13::GatherND``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _GatherND( + _GatherND.Attributes( + batch_dims=AttrInt64(batch_dims, name="batch_dims"), + ), + _GatherND.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + ) + .output + ) + + +def gemm( + A: Var, + B: Var, + C: Optional[Var] = None, + *, + alpha: float = 1.0, + beta: float = 1.0, + transA: int = 0, + transB: int = 0, +) -> Var: + r""" + General Matrix multiplication: + https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + + - A' = transpose(A) if transA else A + - B' = transpose(B) if transB else B + + Compute Y = alpha \* A' \* B' + beta \* C, where input tensor A has + shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input + tensor C is broadcastable to shape (M, N), and output tensor Y has shape + (M, N). A will be transposed before doing the computation if attribute + transA is non-zero, same for B and transB. This operator supports + **unidirectional broadcasting** (tensor C should be unidirectional + broadcastable to tensor A \* B); for more details please check `the + doc `__. + This operator has **optional** inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty string + may be used in the place of an actual argument's name to indicate a + missing argument. Trailing optional arguments (those not followed by an + argument that is present) may also be simply omitted. + + Parameters + ========== + A + Type T. + Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, + M) if transA is non-zero. + B + Type T. + Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, + K) if transB is non-zero. + C + Type T. + Optional input tensor C. If not specified, the computation is done as if + C is a scalar 0. The shape of C should be unidirectional broadcastable + to (M, N). + alpha + Attribute. + Scalar multiplier for the product of input tensors A \* B. + beta + Attribute. + Scalar multiplier for input tensor C. + transA + Attribute. + Whether A should be transposed + transB + Attribute. + Whether B should be transposed + + Returns + ======= + Y : Var + Type T. + Output tensor of shape (M, N). + + Notes + ===== + Signature: ``ai.onnx@13::Gemm``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _Gemm( + _Gemm.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + transA=AttrInt64(transA, name="transA"), + transB=AttrInt64(transB, name="transB"), + ), + _Gemm.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + C=unwrap_vars(C), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + C=get_value(C), + ) + .Y + ) + + +def global_average_pool( + X: Var, +) -> Var: + r""" + GlobalAveragePool consumes an input tensor X and applies average pooling + across the values in the same channel. This is equivalent to AveragePool + with kernel size equal to the spatial dimension of input tensor. + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. + + Returns + ======= + Y : Var + Type T. + Output data tensor from pooling across the input tensor. The output + tensor has the same rank as the input. The first two dimensions of + output shape are the same as the input (N x C), while the other + dimensions are all 1. + + Notes + ===== + Signature: ``ai.onnx@1::GlobalAveragePool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _GlobalAveragePool( + _GlobalAveragePool.Attributes(), + _GlobalAveragePool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def global_lp_pool( + X: Var, + *, + p: int = 2, +) -> Var: + r""" + GlobalLpPool consumes an input tensor X and applies lp pool pooling + across the values in the same channel. This is equivalent to LpPool with + kernel size equal to the spatial dimension of input tensor. + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. + p + Attribute. + p value of the Lp norm used to pool over the input data. + + Returns + ======= + Y : Var + Type T. + Output data tensor from pooling across the input tensor. The output + tensor has the same rank as the input. The first two dimensions of + output shape are the same as the input (N x C), while the other + dimensions are all 1. + + Notes + ===== + Signature: ``ai.onnx@2::GlobalLpPool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _GlobalLpPool( + _GlobalLpPool.Attributes( + p=AttrInt64(p, name="p"), + ), + _GlobalLpPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def global_max_pool( + X: Var, +) -> Var: + r""" + GlobalMaxPool consumes an input tensor X and applies max pooling across + the values in the same channel. This is equivalent to MaxPool with + kernel size equal to the spatial dimension of input tensor. + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. + + Returns + ======= + Y : Var + Type T. + Output data tensor from pooling across the input tensor. The output + tensor has the same rank as the input. The first two dimensions of + output shape are the same as the input (N x C), while the other + dimensions are all 1. + + Notes + ===== + Signature: ``ai.onnx@1::GlobalMaxPool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _GlobalMaxPool( + _GlobalMaxPool.Attributes(), + _GlobalMaxPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def greater( + A: Var, + B: Var, +) -> Var: + r""" + Returns the tensor resulted from performing the ``greater`` logical + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Greater``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return ( + _Greater( + _Greater.Attributes(), + _Greater.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def greater_or_equal( + A: Var, + B: Var, +) -> Var: + r""" + Returns the tensor resulted from performing the ``greater_equal`` + logical operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@16::GreaterOrEqual``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return ( + _GreaterOrEqual( + _GreaterOrEqual.Attributes(), + _GreaterOrEqual.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def grid_sample( + X: Var, + grid: Var, + *, + align_corners: int = 0, + mode: str = "bilinear", + padding_mode: str = "zeros", +) -> Var: + r""" + Given an input ``X`` and a flow-field ``grid``, computes the output + ``Y`` using ``X`` values and pixel locations from ``grid``. Currently, + only spatial (4-D) inputs are supported. For input ``X`` with shape (N, + C, H, W) and ``grid`` with shape (N, H_out, W_out, 2), the output ``Y`` + will have shape (N, C, H_out, W_out). + + The tensor ``X`` contains values at centers of square pixels in a H by W + 2-dimensional image. The tensor ``grid`` describes normalized positions + where the output ``Y`` is to be computed using a specified interpolation + method (the mode) and a padding mode (for grid positions falling outside + the 2-dimensional image). + + Elements in ``grid[N, H_out, W_out]`` are size-2 vectors specifying + positions in the 2-dimensional space of ``X``. They are used to + interpolate output values of ``Y[N, C, H_out, W_out]``. + + The GridSample operator is often used in doing grid generator and + sampler in the `Spatial Transformer + Networks `__. See also in + `torch.nn.functional.grid_sample `__. + + Parameters + ========== + X + Type T1. + 4-D tensor of shape (N, C, H, W), where N is the batch size, C is the + numbers of channels, H and W are the height and width of the input data. + grid + Type T2. + Input offset, 4-D tensor of shape (N, H_out, W_out, 2), where H_out and + W_out are the height and width of grid and output, Grid specifies the + sampling pixel locations normalized by the input spatial dimensions. + Therefore, it should have most values in the range of [-1, 1]. If grid + has values outside the range of [-1, 1], the corresponding outputs will + be handled as defined by padding_mode. + align_corners + Attribute. + If align_corners=1, the extrema (-1 and 1) are considered as referring + to the center points of the input's corner pixels. If align_corners=0, + they are instead considered as referring to the corner points of the + input's corner pixels, making the sampling more resolution agnostic. + mode + Attribute. + Three interpolation modes: bilinear (default), nearest and bicubic. + padding_mode + Attribute. + Support padding modes for outside grid values: ``zeros``\ (default), + ``border``, ``reflection``. zeros: use 0 for out-of-bound grid + locations, border: use border values for out-of-bound grid locations, + reflection: use values at locations reflected by the border for + out-of-bound grid locations. If index 0 represents the margin pixel, the + reflected value at index -1 will be the same as the value at index 1. + For location far away from the border, it will keep being reflected + until becoming in bound. If pixel location x = -3.5 reflects by border + -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = + 0.5. + + Returns + ======= + Y : Var + Type T1. + 4-D tensor of shape (N, C, H_out, W_out) of sampled values. For integer + input types, intermediate values are computed as floating point and cast + to integer at the end. + + Notes + ===== + Signature: ``ai.onnx@16::GridSample``. + + Type constraints: + - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _GridSample( + _GridSample.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + mode=AttrString(mode, name="mode"), + padding_mode=AttrString(padding_mode, name="padding_mode"), + ), + _GridSample.Inputs( + X=unwrap_vars(X), + grid=unwrap_vars(grid), + ), + ) + .get_output_vars( + X=get_value(X), + grid=get_value(grid), + ) + .Y + ) + + +def hamming_window( + size: Var, + *, + output_datatype: int = 1, + periodic: int = 1, +) -> Var: + r""" + Generates a Hamming window as described in the paper + https://ieeexplore.ieee.org/document/1455106. + + Parameters + ========== + size + Type T1. + A scalar value indicating the length of the window. + output_datatype + Attribute. + The data type of the output tensor. Strictly must be one of the values + from DataType enum in TensorProto whose values correspond to T2. The + default value is 1 = FLOAT. + periodic + Attribute. + If 1, returns a window to be used as periodic function. If 0, return a + symmetric window. When 'periodic' is specified, hann computes a window + of length size + 1 and returns the first size points. The default value + is 1. + + Returns + ======= + output : Var + Type T2. + A Hamming window with length: size. The output has the shape: [size]. + + Notes + ===== + Signature: ``ai.onnx@17::HammingWindow``. + + Type constraints: + - T1: `tensor(int32)`, `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _HammingWindow( + _HammingWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), + _HammingWindow.Inputs( + size=unwrap_vars(size), + ), + ) + .get_output_vars( + size=get_value(size), + ) + .output + ) + + +def hann_window( + size: Var, + *, + output_datatype: int = 1, + periodic: int = 1, +) -> Var: + r""" + Generates a Hann window as described in the paper + https://ieeexplore.ieee.org/document/1455106. + + Parameters + ========== + size + Type T1. + A scalar value indicating the length of the window. + output_datatype + Attribute. + The data type of the output tensor. Strictly must be one of the values + from DataType enum in TensorProto whose values correspond to T2. The + default value is 1 = FLOAT. + periodic + Attribute. + If 1, returns a window to be used as periodic function. If 0, return a + symmetric window. When 'periodic' is specified, hann computes a window + of length size + 1 and returns the first size points. The default value + is 1. + + Returns + ======= + output : Var + Type T2. + A Hann window with length: size. The output has the shape: [size]. + + Notes + ===== + Signature: ``ai.onnx@17::HannWindow``. + + Type constraints: + - T1: `tensor(int32)`, `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _HannWindow( + _HannWindow.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + periodic=AttrInt64(periodic, name="periodic"), + ), + _HannWindow.Inputs( + size=unwrap_vars(size), + ), + ) + .get_output_vars( + size=get_value(size), + ) + .output + ) + + +def hard_sigmoid( + X: Var, + *, + alpha: float = 0.20000000298023224, + beta: float = 0.5, +) -> Var: + r""" + HardSigmoid takes one input data (Tensor) and produces one output + data (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha + \* x + beta)), is applied to the tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + alpha + Attribute. + Value of alpha. + beta + Attribute. + Value of beta. + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@6::HardSigmoid``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _HardSigmoid( + _HardSigmoid.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + ), + _HardSigmoid.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def hard_swish( + X: Var, +) -> Var: + r""" + HardSwish takes one input data (Tensor) and produces one output data + (Tensor) where the HardSwish function, y = x \* max(0, min(1, alpha + \* x + beta)) = x \* HardSigmoid(x), where alpha = 1/6 and + beta = 0.5, is applied to the tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@14::HardSwish``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _HardSwish( + _HardSwish.Attributes(), + _HardSwish.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def hardmax( + input: Var, + *, + axis: int = -1, +) -> Var: + r""" + The operator computes the hardmax values for the given input: + + Hardmax(element in input, axis) = 1 if the element is the first maximum + value along the specified axis, 0 otherwise + + The "axis" attribute indicates the dimension along which Hardmax will be + performed. The output tensor has the same shape and contains the Hardmax + values of the corresponding input. + + Parameters + ========== + input + Type T. + The input tensor of rank >= axis. + axis + Attribute. + Describes the dimension Hardmax will be performed on. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(input). + + Returns + ======= + output : Var + Type T. + The output values with the same shape as the input tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Hardmax``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Hardmax( + _Hardmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Hardmax.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def identity( + input: Var, +) -> Var: + r""" + Identity operator + + Parameters + ========== + input + Type V. + Input tensor + + Returns + ======= + output : Var + Type V. + Tensor to copy input into. + + Notes + ===== + Signature: ``ai.onnx@16::Identity``. + + Type constraints: + - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Identity( + _Identity.Attributes(), + _Identity.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def if_( + cond: Var, + *, + else_branch: Callable[[], Iterable[Var]], + then_branch: Callable[[], Iterable[Var]], +) -> Sequence[Var]: + r""" + If conditional + + Parameters + ========== + cond + Type B. + Condition for the if. The tensor must contain a single element. + else_branch + Attribute. + Graph to run if condition is false. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the then_branch. + then_branch + Attribute. + Graph to run if condition is true. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the else_branch. + + Returns + ======= + outputs : Sequence[Var] + Type V. + Values that are live-out to the enclosing scope. The return values in + the ``then_branch`` and ``else_branch`` must be of the same data type. + The ``then_branch`` and ``else_branch`` may produce tensors with the + same element type and different shapes. If corresponding outputs from + the then-branch and the else-branch have static shapes S1 and S2, then + the shape of the corresponding output variable of the if-node (if + present) must be compatible with both S1 and S2 as it represents the + union of both possible shapes.For example, if in a model file, the first + output of ``then_branch`` is typed float tensor with shape [2] and the + first output of ``else_branch`` is another float tensor with shape [3], + If's first output should have (a) no shape set, or (b) a shape of rank 1 + with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank + 1 with a unique ``dim_param``. In contrast, the first output cannot have + the shape [2] since [2] and [3] are not compatible. + + Notes + ===== + Signature: ``ai.onnx@16::If``. + + Type constraints: + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + _else_branch_subgraph: Graph = subgraph((), else_branch) + _then_branch_subgraph: Graph = subgraph((), then_branch) + return ( + _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), + _If.Inputs( + cond=unwrap_vars(cond), + ), + out_variadic=len(_else_branch_subgraph.requested_results), + ) + .get_output_vars( + cond=get_value(cond), + ) + .outputs + ) + + +def instance_normalization( + input: Var, + scale: Var, + B: Var, + *, + epsilon: float = 9.999999747378752e-06, +) -> Var: + r""" + Carries out instance normalization as described in the paper + https://arxiv.org/abs/1607.08022. + + y = scale \* (x - mean) / sqrt(variance + epsilon) + B, where mean and + variance are computed per instance per channel. + + Parameters + ========== + input + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. + scale + Type T. + The input 1-dimensional scale tensor of size C. + B + Type T. + The input 1-dimensional bias tensor of size C. + epsilon + Attribute. + The epsilon value to use to avoid division by zero. + + Returns + ======= + output : Var + Type T. + The output tensor of the same shape as input. + + Notes + ===== + Signature: ``ai.onnx@6::InstanceNormalization``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _InstanceNormalization( + _InstanceNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + ), + _InstanceNormalization.Inputs( + input=unwrap_vars(input), + scale=unwrap_vars(scale), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + input=get_value(input), + scale=get_value(scale), + B=get_value(B), + ) + .output + ) + + +def isinf( + X: Var, + *, + detect_negative: int = 1, + detect_positive: int = 1, +) -> Var: + r""" + Map infinity to true and other values to false. + + Parameters + ========== + X + Type T1. + input + detect_negative + Attribute. + (Optional) Whether map negative infinity to true. Default to 1 so that + negative infinity induces true. Set this attribute to 0 if negative + infinity should be mapped to false. + detect_positive + Attribute. + (Optional) Whether map positive infinity to true. Default to 1 so that + positive infinity induces true. Set this attribute to 0 if positive + infinity should be mapped to false. + + Returns + ======= + Y : Var + Type T2. + output + + Notes + ===== + Signature: ``ai.onnx@10::IsInf``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)` + - T2: `tensor(bool)` + """ + return ( + _IsInf( + _IsInf.Attributes( + detect_negative=AttrInt64(detect_negative, name="detect_negative"), + detect_positive=AttrInt64(detect_positive, name="detect_positive"), + ), + _IsInf.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def isnan( + X: Var, +) -> Var: + r""" + Returns which elements of the input are NaN. + + Parameters + ========== + X + Type T1. + input + + Returns + ======= + Y : Var + Type T2. + output + + Notes + ===== + Signature: ``ai.onnx@13::IsNaN``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(bool)` + """ + return ( + _IsNaN( + _IsNaN.Attributes(), + _IsNaN.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def lrn( + X: Var, + *, + alpha: float = 9.999999747378752e-05, + beta: float = 0.75, + bias: float = 1.0, + size: int, +) -> Var: + r""" + Local Response Normalization proposed in the `AlexNet + paper `__. + It normalizes over local input regions. The local region is defined + across the channels. For an element ``X[n, c, d1, ..., dk]`` in a tensor + of shape ``(N x C x D1 x D2, ..., Dk)``, its region is + ``{X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}``. + + ``square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2)``, where + ``max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))``. + + ``Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta`` + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. Optionally, if dimension denotation is in + effect, the operation expects the input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. + alpha + Attribute. + Scaling parameter. + beta + Attribute. + The exponent. + bias + Attribute. + + size + Attribute. + The number of channels to sum over + + Returns + ======= + Y : Var + Type T. + Output tensor, which has the shape and type as input tensor + + Notes + ===== + Signature: ``ai.onnx@13::LRN``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _LRN( + _LRN.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + beta=AttrFloat32(beta, name="beta"), + bias=AttrFloat32(bias, name="bias"), + size=AttrInt64(size, name="size"), + ), + _LRN.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def lstm( + X: Var, + W: Var, + R: Var, + B: Optional[Var] = None, + sequence_lens: Optional[Var] = None, + initial_h: Optional[Var] = None, + initial_c: Optional[Var] = None, + P: Optional[Var] = None, + *, + activation_alpha: Optional[Iterable[float]] = None, + activation_beta: Optional[Iterable[float]] = None, + activations: Optional[Iterable[str]] = None, + clip: Optional[float] = None, + direction: str = "forward", + hidden_size: Optional[int] = None, + input_forget: int = 0, + layout: int = 0, +) -> tuple[Var, Var, Var]: + r""" + Computes an one-layer LSTM. This operator is usually supported via some + custom implementation such as CuDNN. + + Notations: + + - ``X`` - input tensor + - ``i`` - input gate + - ``o`` - output gate + - ``f`` - forget gate + - ``c`` - cell gate + - ``t`` - time step (t-1 means previous time step) + - ``W[iofc]`` - W parameter weight matrix for input, output, forget, + and cell gates + - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, + and cell gates + - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell + gates + - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell + gates + - ``P[iof]`` - P peephole weight vector for input, output, and forget + gates + - ``WB[iofc]`` - W parameter weight matrix for backward input, output, + forget, and cell gates + - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, + forget, and cell gates + - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, + and cell gates + - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, + and cell gates + - ``PB[iof]`` - P peephole weight vector for backward input, output, + and forget gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 + + Activation functions: + + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) + + NOTE: Below are optional + + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): + + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + - Ct = ft (.) Ct-1 + it (.) ct + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See + `the doc `__ for + more details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. + + Parameters + ========== + X + Type T. + The input sequences packed (and potentially padded) into one 3-D tensor + with the shape of ``[seq_length, batch_size, input_size]``. + W + Type T. + The weight tensor for the gates. Concatenation of ``W[iofc]`` and + ``WB[iofc]`` (if bidirectional) along dimension 0. The tensor has shape + ``[num_directions, 4*hidden_size, input_size]``. + R + Type T. + The recurrence weight tensor. Concatenation of ``R[iofc]`` and + ``RB[iofc]`` (if bidirectional) along dimension 0. This tensor has shape + ``[num_directions, 4*hidden_size, hidden_size]``. + B + Type T. + The bias tensor for input gate. Concatenation of + ``[Wb[iofc], Rb[iofc]]``, and ``[WBb[iofc], RBb[iofc]]`` (if + bidirectional) along dimension 0. This tensor has shape + ``[num_directions, 8*hidden_size]``. Optional: If not specified - + assumed to be 0. + sequence_lens + Type T1. + Optional tensor specifying lengths of the sequences in a batch. If not + specified - assumed all sequences in the batch to have length + ``seq_length``. It has shape ``[batch_size]``. + initial_h + Type T. + Optional initial value of the hidden. If not specified - assumed to be + 0. It has shape ``[num_directions, batch_size, hidden_size]``. + initial_c + Type T. + Optional initial value of the cell. If not specified - assumed to be 0. + It has shape ``[num_directions, batch_size, hidden_size]``. + P + Type T. + The weight tensor for peepholes. Concatenation of ``P[iof]`` and + ``PB[iof]`` (if bidirectional) along dimension 0. It has shape + ``[num_directions, 3*hidde_size]``. Optional: If not specified - assumed + to be 0. + activation_alpha + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX + operators.For example with LeakyRelu, the default alpha is 0.01. + activation_beta + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX operators. + activations + Attribute. + A list of 3 (or 6 if bidirectional) activation functions for input, + output, forget, cell, and hidden. The activation functions must be one + of the activation functions specified above. Optional: See the equations + for default if not specified. + clip + Attribute. + Cell clip threshold. Clipping bounds the elements of a tensor in the + range of [-threshold, +threshold] and is applied to the input of + activations. No clip if not specified. + direction + Attribute. + Specify if the RNN is forward, reverse, or bidirectional. Must be one of + forward (default), reverse, or bidirectional. + hidden_size + Attribute. + Number of neurons in the hidden layer + input_forget + Attribute. + Couple the input and forget gates if 1. + layout + Attribute. + The shape format of inputs X, initial_h, initial_c and outputs Y, Y_h, + Y_c. If 0, the following shapes are expected: X.shape = [seq_length, + batch_size, input_size], Y.shape = [seq_length, num_directions, + batch_size, hidden_size], initial_h.shape = Y_h.shape = initial_c.shape + = Y_c.shape = [num_directions, batch_size, hidden_size]. If 1, the + following shapes are expected: X.shape = [batch_size, seq_length, + input_size], Y.shape = [batch_size, seq_length, num_directions, + hidden_size], initial_h.shape = Y_h.shape = initial_c.shape = Y_c.shape + = [batch_size, num_directions, hidden_size]. + + Returns + ======= + Y : Var + Type T. + A tensor that concats all the intermediate output values of the hidden. + It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. + Y_h : Var + Type T. + The last output value of the hidden. It has shape + ``[num_directions, batch_size, hidden_size]``. + Y_c : Var + Type T. + The last output value of the cell. It has shape + ``[num_directions, batch_size, hidden_size]``. + + Notes + ===== + Signature: ``ai.onnx@14::LSTM``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(int32)` + """ + return ( + _LSTM( + _LSTM.Attributes( + activation_alpha=AttrFloat32s.maybe( + activation_alpha, name="activation_alpha" + ), + activation_beta=AttrFloat32s.maybe( + activation_beta, name="activation_beta" + ), + activations=AttrStrings.maybe(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + input_forget=AttrInt64(input_forget, name="input_forget"), + layout=AttrInt64(layout, name="layout"), + ), + _LSTM.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + R=unwrap_vars(R), + B=unwrap_vars(B), + sequence_lens=unwrap_vars(sequence_lens), + initial_h=unwrap_vars(initial_h), + initial_c=unwrap_vars(initial_c), + P=unwrap_vars(P), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + R=get_value(R), + B=get_value(B), + sequence_lens=get_value(sequence_lens), + initial_h=get_value(initial_h), + initial_c=get_value(initial_c), + P=get_value(P), + ) + ._unpack_to_any() + ) + + +def layer_normalization( + X: Var, + Scale: Var, + B: Optional[Var] = None, + *, + axis: int = -1, + epsilon: float = 9.999999747378752e-06, + stash_type: int = 1, +) -> tuple[Var, Var, Var]: + r""" + This is layer normalization defined in ONNX as function. The overall + computation can be split into two stages. The first stage is + standardization, which makes the normalized elements have zero mean and + unit variances. The computation required by standardization can be + described by the following equations. + ``Mean = ReduceMean(X) D = Sub(X, Mean) DD = Mul(D, D) Var = ReduceMean(DD) VarEps = Add(Var, epsilon) StdDev = Sqrt(VarEps) InvStdDev = Reciprocal(StdDev) Normalized = Mul(D, InvStdDev)`` + where ``normalized_axes`` is ``[axis, ..., rank of X - 1]``. The + variables ``Var`` and ``StdDev`` stand for variance and standard + deviation, respectively. The second output is ``Mean`` and the last one + is ``InvStdDev``. Depending on ``stash_type`` attribute, the actual + computation must happen in different floating-point precision. For + example, if ``stash_type`` is 1, this operator casts all input variables + to 32-bit float, perform the computation, and finally cast + ``Normalized`` back to the original type of ``X``. The second stage then + scales and shifts the outcome of the first stage using + ``NormalizedScaled = Mul(Normalized, Scale) Y = Add(NormalizedScaled, B)`` + The second stage doesn't depends on ``stash_type``. All equations are in + `this syntax `__. + The same variable (i.e., input, output, and attribute) uses the same + name in the equations above and this operator's definition. Let ``d[i]`` + indicate the i-th dimension of ``X``. If ``X``'s shape is + ``[d[0], ..., d[axis-1], d[axis], ..., d[rank-1]]``, the shape of + ``Mean`` and ``InvStdDev`` is ``[d[0], ..., d[axis-1], 1, ..., 1]``. + ``Y`` and ``X`` have the same shape. This operator supports + unidirectional broadcasting (tensors ``Scale`` and ``B`` should be + unidirectional broadcastable to tensor ``X``); for more details please + check `the + doc `__. + + Parameters + ========== + X + Type T. + Tensor to be normalized. + Scale + Type T. + Scale tensor. + B + Type T. + Bias tensor. + axis + Attribute. + The first normalization dimension. If rank(X) is r, axis' allowed range + is [-r, r). Negative value means counting dimensions from the back. + epsilon + Attribute. + The epsilon value to use to avoid division by zero. + stash_type + Attribute. + Type of Mean and InvStdDev. This also specifies stage one's computation + precision. + + Returns + ======= + Y : Var + Type T. + Normalized tensor. + Mean : Var + Type U. + Saved mean used during training to speed up gradient computation + InvStdDev : Var + Type U. + Saved inverse standard deviation used during training to speed up + gradient computation. + + Notes + ===== + Signature: ``ai.onnx@17::LayerNormalization``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - U: `tensor(bfloat16)`, `tensor(float)` + """ + return ( + _LayerNormalization( + _LayerNormalization.Attributes( + axis=AttrInt64(axis, name="axis"), + epsilon=AttrFloat32(epsilon, name="epsilon"), + stash_type=AttrInt64(stash_type, name="stash_type"), + ), + _LayerNormalization.Inputs( + X=unwrap_vars(X), + Scale=unwrap_vars(Scale), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + X=get_value(X), + Scale=get_value(Scale), + B=get_value(B), + ) + ._unpack_to_any() + ) + + +def leaky_relu( + X: Var, + *, + alpha: float = 0.009999999776482582, +) -> Var: + r""" + LeakyRelu takes input data (Tensor) and an argument alpha, and + produces one output data (Tensor) where the function + ``f(x) = alpha * x for x < 0``, ``f(x) = x for x >= 0``, is applied to + the data tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + alpha + Attribute. + Coefficient of leakage. + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@16::LeakyRelu``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _LeakyRelu( + _LeakyRelu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), + _LeakyRelu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def less( + A: Var, + B: Var, +) -> Var: + r""" + Returns the tensor resulted from performing the ``less`` logical + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Less``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return ( + _Less( + _Less.Attributes(), + _Less.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def less_or_equal( + A: Var, + B: Var, +) -> Var: + r""" + Returns the tensor resulted from performing the ``less_equal`` logical + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@16::LessOrEqual``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` + """ + return ( + _LessOrEqual( + _LessOrEqual.Attributes(), + _LessOrEqual.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def log( + input: Var, +) -> Var: + r""" + Calculates the natural log of the given input tensor, element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The natural log of the input tensor computed element-wise + + Notes + ===== + Signature: ``ai.onnx@13::Log``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Log( + _Log.Attributes(), + _Log.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def log_softmax( + input: Var, + *, + axis: int = -1, +) -> Var: + r""" + The operator computes the log of softmax values for the given input: + + LogSoftmax(input, axis) = Log(Softmax(input, axis=axis)) + + The "axis" attribute indicates the dimension along which LogSoftmax will + be performed. The output tensor has the same shape and contains the + LogSoftmax values of the corresponding input. + + Parameters + ========== + input + Type T. + The input tensor of rank >= axis. + axis + Attribute. + Describes the dimension LogSoftmax will be performed on. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(input). + + Returns + ======= + output : Var + Type T. + The output values with the same shape as the input tensor. + + Notes + ===== + Signature: ``ai.onnx@13::LogSoftmax``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _LogSoftmax( + _LogSoftmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _LogSoftmax.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def loop( + M: Optional[Var] = None, + cond: Optional[Var] = None, + v_initial: Sequence[Var] = (), + *, + body: Callable[..., Iterable[Var]], +) -> Sequence[Var]: + r""" + Generic Looping construct. This loop has multiple termination + conditions: + + 1) Trip count. Iteration count specified at runtime. Set by specifying + the input M. Optional. Set to empty string to omit. Note that a + static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. + 2) Loop termination condition. This is an input to the op that + determines whether to run the first iteration and also a loop-carried + dependency for the body graph. The body graph must yield a value for + the condition variable, whether this input is provided or not. + + This table summarizes the operating modes of this operator with + equivalent C-style code: + + Operator inputs defined as (max_trip_count, condition_var). + + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } + + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } + + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } + + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } + + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } + + *Sample usage - cond as well as trip count* + + :: + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + + *Sample equivalent C code* + + :: + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + + There are several things of note in this code snippet: + + 1) Values from the enclosing scope (i.e. variable "a" here) are in scope + and can be referenced in the inputs of the loop. + 2) Any values computed in the loop body that needs to be used in a + subsequent iteration or after the loop are modelled using a pair of + variables in the loop-body, consisting of an input variable (eg., + b_in) and an output variable (eg., b_out). These are referred to as + loop-carried dependences. The loop operation node supplies the input + value of the input variable for the first iteration, and returns the + output value of the output variable produced by the final iteration. + 3) Scan_output variables are used to implicitly concatenate values + computed across all the iterations. In the above example, the value + of user_defined_val computed over all iterations are concatenated and + returned as the value of user_defined_vals after the loop. + 4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + + Note that the semantics of this op support "diagonal" or "wavefront" + execution. (See Step 3 here for an example: + https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). + Frontends should emit multi-layer RNNs as a series of While operators + (with time being the inner looping dimension), with each successive + layer consuming the scan_outputs from the previous layer, possibly going + through several point-wise operators (e.g. dropout, residual + connections, linear layer). + + The input/output of subgraph (produced by loop node) matching is based + on order instead of name. The implementation will figure out the names + based on this order. + + Parameters + ========== + M + Type I. + A maximum trip-count for the loop specified at runtime. Optional. Pass + empty string to skip. + cond + Type B. + A boolean termination condition. Optional. Pass empty string to skip. + v_initial + Type V. + The initial values of any loop-carried dependencies (values that change + across loop iterations) + body + Attribute. + The graph run each iteration. It has 2+N inputs: (iteration_num, + condition, loop carried dependencies...). It has 1+N+K outputs: + (condition, loop carried dependencies..., scan_outputs...). Each + scan_output is created by concatenating the value of the specified + output value at the end of each iteration of the loop. It is an error if + the dimensions or data type of these scan_outputs change across loop + iterations. + + Returns + ======= + v_final_and_scan_outputs : Sequence[Var] + Type V. + Final N loop carried dependency values then K scan_outputs. Scan outputs + must be Tensors. + + Notes + ===== + Signature: ``ai.onnx@16::Loop``. + + Type constraints: + - I: `tensor(int64)` + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + _body_subgraph: Graph = subgraph( + typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))]) + + [var.unwrap_type() for var in v_initial], + body, + ) + return ( + _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), + _Loop.Inputs( + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), + ), + out_variadic=len(_body_subgraph.requested_results) - 1, + initializers={ + "M": get_value(M), + "cond": get_value(cond), + "v_initial": get_value(v_initial), + }, + ) + .get_output_vars( + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), + ) + .v_final_and_scan_outputs + ) + + +def lp_normalization( + input: Var, + *, + axis: int = -1, + p: int = 2, +) -> Var: + r""" + Given a matrix, apply Lp-normalization along the provided axis. + + Parameters + ========== + input + Type T. + Input matrix + axis + Attribute. + The axis on which to apply normalization, -1 mean last axis. + p + Attribute. + The order of the normalization, only 1 or 2 are supported. + + Returns + ======= + output : Var + Type T. + Matrix after normalization + + Notes + ===== + Signature: ``ai.onnx@1::LpNormalization``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _LpNormalization( + _LpNormalization.Attributes( + axis=AttrInt64(axis, name="axis"), + p=AttrInt64(p, name="p"), + ), + _LpNormalization.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def lp_pool( + X: Var, + *, + auto_pad: str = "NOTSET", + kernel_shape: Iterable[int], + p: int = 2, + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: + r""" + LpPool consumes an input tensor X and applies Lp pooling across the + tensor according to kernel sizes, stride sizes, and pad lengths. Lp + pooling consisting of computing the Lp norm on all values of a subset of + the input tensor according to the kernel size and downsampling the data + into the output tensor Y for further processing. + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. + kernel_shape + Attribute. + The size of the kernel along each axis. + p + Attribute. + p value of the Lp norm used to pool over the input data. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + + Returns + ======= + Y : Var + Type T. + Output data tensor from Lp pooling across the input tensor. Dimensions + will vary based on various kernel, stride, and pad sizes. + + Notes + ===== + Signature: ``ai.onnx@11::LpPool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _LpPool( + _LpPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + p=AttrInt64(p, name="p"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _LpPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def matmul( + A: Var, + B: Var, +) -> Var: + r""" + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + + Parameters + ========== + A + Type T. + N-dimensional matrix A + B + Type T. + N-dimensional matrix B + + Returns + ======= + Y : Var + Type T. + Matrix multiply results from A \* B + + Notes + ===== + Signature: ``ai.onnx@13::MatMul``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _MatMul( + _MatMul.Attributes(), + _MatMul.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .Y + ) + + +def matmul_integer( + A: Var, + B: Var, + a_zero_point: Optional[Var] = None, + b_zero_point: Optional[Var] = None, +) -> Var: + r""" + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + The production MUST never overflow. The accumulation may overflow if and + only if in 32 bits. + + Parameters + ========== + A + Type T1. + N-dimensional matrix A + B + Type T2. + N-dimensional matrix B + a_zero_point + Type T1. + Zero point tensor for input 'A'. It's optional and default value is 0. + It could be a scalar or N-D tensor. Scalar refers to per tensor + quantization whereas N-D refers to per row quantization. If the input is + 2D of shape [M, K] then zero point tensor may be an M element vector + [zp_1, zp_2, ..., zp_M]. If the input is N-D tensor with shape [D1, D2, + M, K] then zero point tensor may have shape [D1, D2, M, 1]. + b_zero_point + Type T2. + Zero point tensor for input 'B'. It's optional and default value is 0. + It could be a scalar or a N-D tensor, Scalar refers to per tensor + quantization whereas N-D refers to per col quantization. If the input is + 2D of shape [K, N] then zero point tensor may be an N element vector + [zp_1, zp_2, ..., zp_N]. If the input is N-D tensor with shape [D1, D2, + K, N] then zero point tensor may have shape [D1, D2, 1, N]. + + Returns + ======= + Y : Var + Type T3. + Matrix multiply results from A \* B + + Notes + ===== + Signature: ``ai.onnx@10::MatMulInteger``. + + Type constraints: + - T1: `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(int32)` + """ + return ( + _MatMulInteger( + _MatMulInteger.Attributes(), + _MatMulInteger.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + a_zero_point=unwrap_vars(a_zero_point), + b_zero_point=unwrap_vars(b_zero_point), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + a_zero_point=get_value(a_zero_point), + b_zero_point=get_value(b_zero_point), + ) + .Y + ) + + +def max( + data_0: Sequence[Var], +) -> Var: + r""" + Element-wise max of each of the input tensors (with Numpy-style + broadcasting support). All inputs and outputs must have the same data + type. This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + data_0 + Type T. + List of tensors for max. + + Returns + ======= + max : Var + Type T. + Output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Max``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Max( + _Max.Attributes(), + _Max.Inputs( + data_0=unwrap_vars(data_0), + ), + ) + .get_output_vars( + data_0=get_value(data_0), + ) + .max + ) + + +def max_pool( + X: Var, + *, + auto_pad: str = "NOTSET", + ceil_mode: int = 0, + dilations: Optional[Iterable[int]] = None, + kernel_shape: Iterable[int], + pads: Optional[Iterable[int]] = None, + storage_order: int = 0, + strides: Optional[Iterable[int]] = None, +) -> tuple[Var, Var]: + r""" + MaxPool consumes an input tensor X and applies max pooling across the + tensor according to kernel sizes, stride sizes, and pad lengths. max + pooling consisting of computing the max on all values of a subset of the + input tensor according to the kernel size and downsampling the data into + the output tensor Y for further processing. The output spatial shape is + calculated differently depending on whether explicit padding is used, + where pads is employed, or auto padding is used, where auto_pad is + utilized. With explicit padding + (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): + + :: + + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + + or + + :: + + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + + if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis + ``i``. Sliding windows that would start in the right padded region are + ignored. + + ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, + the output spatial shape will be following when ceil_mode is enabled: + + :: + + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + + or when ceil_mode is disabled + (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): + + :: + + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 + + And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: + + :: + + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + + The output of each pooling window is maximum number of elements exclude + pad. + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. Optionally, if dimension denotation is in + effect, the operation expects the input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. + ceil_mode + Attribute. + Whether to use ceil or floor (default) to compute the output shape. + dilations + Attribute. + Dilation value along each spatial axis of filter. If not present, the + dilation defaults to 1 along each spatial axis. + kernel_shape + Attribute. + The size of the kernel along each axis. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. + storage_order + Attribute. + The storage order of the tensor. 0 is row major, and 1 is column major. + This attribute is used only to convert an n-tuple index value into a + single integer value for producing the second output. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + + Returns + ======= + Y : Var + Type T. + Output data tensor from average or max pooling across the input tensor. + Dimensions will vary based on various kernel, stride, and pad sizes. + Floor value of the dimension is used + Indices : Var + Type I. + Indices tensor from max pooling across the input tensor. The dimensions + of indices are the same as output tensor. The values in indices of are + the indices of the selected values during pooling. The indices are + computed as flatten 1-D tensor, and the indices do not consider padding. + So the values in indices are in [0, N x C x D1 x ... x Dn). + + Notes + ===== + Signature: ``ai.onnx@12::MaxPool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int8)`, `tensor(uint8)` + - I: `tensor(int64)` + """ + return ( + _MaxPool( + _MaxPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + storage_order=AttrInt64(storage_order, name="storage_order"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _MaxPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) + + +def max_roi_pool( + X: Var, + rois: Var, + *, + pooled_shape: Iterable[int], + spatial_scale: float = 1.0, +) -> Var: + r""" + ROI max pool consumes an input tensor X and region of interests (RoIs) + to apply max pooling across each RoI, to produce output 4-D tensor of + shape (num_rois, channels, pooled_shape[0], pooled_shape[1]). + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. + rois + Type T. + RoIs (Regions of Interest) to pool over. Should be a 2-D tensor of shape + (num_rois, 5) given as [[batch_id, x1, y1, x2, y2], ...]. + pooled_shape + Attribute. + ROI pool output shape (height, width). + spatial_scale + Attribute. + Multiplicative spatial scale factor to translate ROI coordinates from + their input scale to the scale used when pooling. + + Returns + ======= + Y : Var + Type T. + RoI pooled output 4-D tensor of shape (num_rois, channels, + pooled_shape[0], pooled_shape[1]). + + Notes + ===== + Signature: ``ai.onnx@1::MaxRoiPool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _MaxRoiPool( + _MaxRoiPool.Attributes( + pooled_shape=AttrInt64s(pooled_shape, name="pooled_shape"), + spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), + ), + _MaxRoiPool.Inputs( + X=unwrap_vars(X), + rois=unwrap_vars(rois), + ), + ) + .get_output_vars( + X=get_value(X), + rois=get_value(rois), + ) + .Y + ) + + +def max_unpool( + X: Var, + I: Var, + output_shape: Optional[Var] = None, + *, + kernel_shape: Iterable[int], + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: + r""" + MaxUnpool essentially computes the partial inverse of the MaxPool op. + The input information to this op is typically the output information + from a MaxPool op. The first input tensor X is the tensor that needs to + be unpooled, which is typically the pooled tensor (first output) from + MaxPool. The second input tensor, I, contains the indices to the + (locally maximal) elements corresponding to the elements in the first + input tensor X. Input tensor I is typically the second output of the + MaxPool op. The third (optional) input is a tensor that specifies the + output size of the unpooling operation. + + MaxUnpool is intended to do 'partial' inverse of the MaxPool op. + 'Partial' because all the non-maximal values from the original input to + MaxPool are set to zero in the output of the MaxUnpool op. Pooling the + result of an unpooling operation should give back the original input to + the unpooling op. + + MaxUnpool can produce the same output size for several input sizes, + which makes unpooling op ambiguous. The third input argument, + output_size, is meant to disambiguate the op and produce output tensor + of known/predictable size. + + In addition to the inputs, MaxUnpool takes three attributes, namely + kernel_shape, strides, and pads, which define the exact unpooling op. + The attributes typically have the same values as the corresponding + pooling op that the unpooling op is trying to invert. + + Parameters + ========== + X + Type T1. + Input data tensor that has to be unpooled. This tensor is typically the + first output of the MaxPool op.Dimensions for image case are (N x C x H + x W), where N is the batch size, C is the number of channels, and H and + W are the height and the width of the data. For non-image case, the + dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the + batch size. Optionally, if dimension denotation is in effect, the + operation expects the input data tensor to arrive with the dimension + denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE + ...]. + I + Type T2. + Input data tensor containing the indices corresponding to elements in + the first input tensor X.This tensor is typically the second output of + the MaxPool op.Dimensions must be the same as input tensor X. The + indices are linear, i.e. computed considering the tensor as flattened + 1-D tensor, assuming row-major storage. Also, the linear indices should + not consider padding. So the values in indices are in the range [0, N x + C x D1 x ... x Dn). + output_shape + Type T2. + The shape of the output can be explicitly set which will cause pads + values to be auto generated. If 'output_shape' is specified, 'pads' + values are ignored. + kernel_shape + Attribute. + The size of the kernel along each axis. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + + Returns + ======= + output : Var + Type T1. + Output data tensor that contains the result of the unpooling. + + Notes + ===== + Signature: ``ai.onnx@11::MaxUnpool``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int64)` + """ + return ( + _MaxUnpool( + _MaxUnpool.Attributes( + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _MaxUnpool.Inputs( + X=unwrap_vars(X), + I=unwrap_vars(I), + output_shape=unwrap_vars(output_shape), + ), + ) + .get_output_vars( + X=get_value(X), + I=get_value(I), + output_shape=get_value(output_shape), + ) + .output + ) + + +def mean( + data_0: Sequence[Var], +) -> Var: + r""" + Element-wise mean of each of the input tensors (with Numpy-style + broadcasting support). All inputs and outputs must have the same data + type. This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + data_0 + Type T. + List of tensors for mean. + + Returns + ======= + mean : Var + Type T. + Output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Mean``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Mean( + _Mean.Attributes(), + _Mean.Inputs( + data_0=unwrap_vars(data_0), + ), + ) + .get_output_vars( + data_0=get_value(data_0), + ) + .mean + ) + + +def mean_variance_normalization( + X: Var, + *, + axes: Iterable[int] = (0, 2, 3), +) -> Var: + r""" + A MeanVarianceNormalization Function: Perform mean variance + normalization on the input tensor X using formula: + ``(X-EX)/sqrt(E(X-EX)^2)`` + + Parameters + ========== + X + Type T. + Input tensor + axes + Attribute. + A list of integers, along which to reduce. The default is to calculate + along axes [0,2,3] for calculating mean and variance along each channel. + Two variables with the same C-coordinate are associated with the same + mean and variance. + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::MeanVarianceNormalization``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _MeanVarianceNormalization( + _MeanVarianceNormalization.Attributes( + axes=AttrInt64s(axes, name="axes"), + ), + _MeanVarianceNormalization.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def mel_weight_matrix( + num_mel_bins: Var, + dft_length: Var, + sample_rate: Var, + lower_edge_hertz: Var, + upper_edge_hertz: Var, + *, + output_datatype: int = 1, +) -> Var: + r""" + Generate a MelWeightMatrix that can be used to re-weight a Tensor + containing a linearly sampled frequency spectra (from DFT or STFT) into + num_mel_bins frequency information based on the [lower_edge_hertz, + upper_edge_hertz] range on the mel scale. This function defines the mel + scale in terms of a frequency in hertz according to the following + formula: + + :: + + mel(f) = 2595 * log10(1 + f/700) + + In the returned matrix, all the triangles (filterbanks) have a peak + value of 1.0. + + The returned MelWeightMatrix can be used to right-multiply a spectrogram + S of shape [frames, num_spectrogram_bins] of linear scale spectrum + values (e.g. STFT magnitudes) to generate a "mel spectrogram" M of shape + [frames, num_mel_bins]. + + Parameters + ========== + num_mel_bins + Type T1. + The number of bands in the mel spectrum. + dft_length + Type T1. + The size of the original DFT. The size of the original DFT is used to + infer the size of the onesided DFT, which is understood to be + floor(dft_length/2) + 1, i.e. the spectrogram only contains the + nonredundant DFT bins. + sample_rate + Type T1. + Samples per second of the input signal used to create the spectrogram. + Used to figure out the frequencies corresponding to each spectrogram + bin, which dictates how they are mapped into the mel scale. + lower_edge_hertz + Type T2. + Lower bound on the frequencies to be included in the mel spectrum. This + corresponds to the lower edge of the lowest triangular band. + upper_edge_hertz + Type T2. + The desired top edge of the highest frequency band. + output_datatype + Attribute. + The data type of the output tensor. Strictly must be one of the values + from DataType enum in TensorProto whose values correspond to T3. The + default value is 1 = FLOAT. + + Returns + ======= + output : Var + Type T3. + The Mel Weight Matrix. The output has the shape: [floor(dft_length/2) + + 1][num_mel_bins]. + + Notes + ===== + Signature: ``ai.onnx@17::MelWeightMatrix``. + + Type constraints: + - T1: `tensor(int32)`, `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T3: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _MelWeightMatrix( + _MelWeightMatrix.Attributes( + output_datatype=AttrInt64(output_datatype, name="output_datatype"), + ), + _MelWeightMatrix.Inputs( + num_mel_bins=unwrap_vars(num_mel_bins), + dft_length=unwrap_vars(dft_length), + sample_rate=unwrap_vars(sample_rate), + lower_edge_hertz=unwrap_vars(lower_edge_hertz), + upper_edge_hertz=unwrap_vars(upper_edge_hertz), + ), + ) + .get_output_vars( + num_mel_bins=get_value(num_mel_bins), + dft_length=get_value(dft_length), + sample_rate=get_value(sample_rate), + lower_edge_hertz=get_value(lower_edge_hertz), + upper_edge_hertz=get_value(upper_edge_hertz), + ) + .output + ) + + +def min( + data_0: Sequence[Var], +) -> Var: + r""" + Element-wise min of each of the input tensors (with Numpy-style + broadcasting support). All inputs and outputs must have the same data + type. This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + data_0 + Type T. + List of tensors for min. + + Returns + ======= + min : Var + Type T. + Output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Min``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Min( + _Min.Attributes(), + _Min.Inputs( + data_0=unwrap_vars(data_0), + ), + ) + .get_output_vars( + data_0=get_value(data_0), + ) + .min + ) + + +def mod( + A: Var, + B: Var, + *, + fmod: int = 0, +) -> Var: + r""" + Performs element-wise binary modulus (with Numpy-style broadcasting + support). The sign of the remainder is the same as that of the Divisor. + + Mod operator can also behave like C fmod() or numpy.fmod. In this case, + the sign of the remainder however, will be the same as the Dividend (in + contrast to integer mod). To force a behavior like numpy.fmod() an + 'fmod' Attribute is provided. This attribute is set to 0 by default + causing the behavior to be like integer mod. Setting this attribute to 1 + causes the remainder to be calculated similar to that of numpy.fmod(). + + If the input type is floating point, then ``fmod`` attribute must be set + to 1. + + In case of dividend being zero, the results will be platform dependent. + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + Dividend tensor + B + Type T. + Divisor tensor + fmod + Attribute. + Whether the operator should behave like fmod (default=0 meaning it will + do integer mods); Set this to 1 to force fmod treatment + + Returns + ======= + C : Var + Type T. + Remainder tensor + + Notes + ===== + Signature: ``ai.onnx@13::Mod``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Mod( + _Mod.Attributes( + fmod=AttrInt64(fmod, name="fmod"), + ), + _Mod.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def mul( + A: Var, + B: Var, +) -> Var: + r""" + Performs element-wise binary multiplication (with Numpy-style + broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + (Opset 14 change): Extend supported types to include uint8, int8, + uint16, and int16. + + Parameters + ========== + A + Type T. + First operand. + B + Type T. + Second operand. + + Returns + ======= + C : Var + Type T. + Result, has same element type as two inputs + + Notes + ===== + Signature: ``ai.onnx@14::Mul``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Mul( + _Mul.Attributes(), + _Mul.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def multinomial( + input: Var, + *, + dtype: npt.DTypeLike = np.int32, + sample_size: int = 1, + seed: Optional[float] = None, +) -> Var: + r""" + Generate a tensor of samples from a multinomial distribution according + to the probabilities of each of the possible outcomes. + + Parameters + ========== + input + Type T1. + Input tensor with shape [batch_size, class_size], where class_size is + the number of all possible outcomes. Each value along the axis zero + represents the unnormalized log-probability of each corresponding + outcome in a batch. + dtype + Attribute. + (Optional) The data type for the elements of the output tensor, if not + specified, we will use int32. + sample_size + Attribute. + Number of times to sample. + seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + + Returns + ======= + output : Var + Type T2. + Output tensor with shape [batch_size, sample_size], where sample_size is + the number of times to sample. Each value along the axis zero represents + the outcome of the corresponding sample in a batch. + + Notes + ===== + Signature: ``ai.onnx@7::Multinomial``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return ( + _Multinomial( + _Multinomial.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + sample_size=AttrInt64(sample_size, name="sample_size"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), + _Multinomial.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def neg( + X: Var, +) -> Var: + r""" + Neg takes one input data (Tensor) and produces one output data + (Tensor) where each element flipped sign, y = -x, is applied to the + tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::Neg``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` + """ + return ( + _Neg( + _Neg.Attributes(), + _Neg.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def negative_log_likelihood_loss( + input: Var, + target: Var, + weight: Optional[Var] = None, + *, + ignore_index: Optional[int] = None, + reduction: str = "mean", +) -> Var: + r""" + A NegativeLogLikelihoodLoss operator computes (weighted) negative log + likelihood loss. Its "input" tensor has the shape of (N, C, d1, d2, ..., + dk) where k >= 0. The "input" tensor contains log-probabilities for + input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). The + operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). + It encodes class labels (one of C classes) or it may contain a special + value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x + dk samples. The loss value for input[n, :, d_1, d_2,...d_k] being + classified as class c = target[n][d_1][d_2]...[d_k] is computed as: + + :: + + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. + + When an optional "weight" is provided, the sample loss is calculated as: + + :: + + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. + + loss is zero for the case when target-value equals ignore_index. + + :: + + loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index + + If "reduction" attribute is set to "none", the operator's output will be + the above loss with shape (N, d1, d2, ..., dk). If "reduction" attribute + is set to "mean" (the default attribute value), the output loss is + (weight) averaged: + + :: + + mean(loss), if "weight" is not provided, + + or if weight is provided, + + :: + + sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. + + If "reduction" attribute is set to "sum", the output is a scalar: + ``sum(loss)``. + + See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. + + Example 1: + + :: + + // negative log likelihood loss, "none" reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] + + // print(loss) + // [[-3. -2.] + // [-0. -2.]] + + Example 2: + + :: + + // weighted negative log likelihood loss, sum reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + + loss = np.sum(loss) + // print(loss) + // -1.1 + + Example 3: + + :: + + // weighted negative log likelihood loss, mean reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + weight_total = 0 + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + weight_total = weight_total + weight[c] + + loss = np.sum(loss) / weight_total + // print(loss) + // -1.57 + + Parameters + ========== + input + Type T. + Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk). + target + Type Tind. + Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value + shall be in range of [0, C). If ignore_index is specified, it may have a + value outside [0, C) and the target values should either be in the range + [0, C) or have the value ignore_index. + weight + Type T. + Optional rescaling weight tensor. If given, it has to be a tensor of + size C. Otherwise, it is treated as if having all ones. + ignore_index + Attribute. + Specifies a target value that is ignored and does not contribute to the + input gradient. It's an optional value. + reduction + Attribute. + Type of reduction to apply to loss: none, sum, mean (default). 'none': + the output is the loss for each sample. 'sum': the output will be + summed. 'mean': the sum of the output will be divided by the sum of + applied weights. + + Returns + ======= + loss : Var + Type T. + The negative log likelihood loss + + Notes + ===== + Signature: ``ai.onnx@13::NegativeLogLikelihoodLoss``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return ( + _NegativeLogLikelihoodLoss( + _NegativeLogLikelihoodLoss.Attributes( + ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), + reduction=AttrString(reduction, name="reduction"), + ), + _NegativeLogLikelihoodLoss.Inputs( + input=unwrap_vars(input), + target=unwrap_vars(target), + weight=unwrap_vars(weight), + ), + ) + .get_output_vars( + input=get_value(input), + target=get_value(target), + weight=get_value(weight), + ) + .loss + ) + + +def non_max_suppression( + boxes: Var, + scores: Var, + max_output_boxes_per_class: Optional[Var] = None, + iou_threshold: Optional[Var] = None, + score_threshold: Optional[Var] = None, + *, + center_point_box: int = 0, +) -> Var: + r""" + Filter out boxes that have high intersection-over-union (IOU) overlap + with previously selected boxes. Bounding boxes with score less than + score_threshold are removed. Bounding box format is indicated by + attribute center_point_box. Note that this algorithm is agnostic to + where the origin is in the coordinate system and more generally is + invariant to orthogonal transformations and translations of the + coordinate system; thus translating or reflections of the coordinate + system result in the same boxes being selected by the algorithm. The + selected_indices output is a set of integers indexing into the input + collection of bounding boxes representing the selected boxes. The + bounding box coordinates corresponding to the selected indices can then + be obtained using the Gather or GatherND operation. + + Parameters + ========== + boxes + Type tensor(float). + An input tensor with shape [num_batches, spatial_dimension, 4]. The + single box data format is indicated by center_point_box. + scores + Type tensor(float). + An input tensor with shape [num_batches, num_classes, spatial_dimension] + max_output_boxes_per_class + Type tensor(int64). + Integer representing the maximum number of boxes to be selected per + batch per class. It is a scalar. Default to 0, which means no output. + iou_threshold + Type tensor(float). + Float representing the threshold for deciding whether boxes overlap too + much with respect to IOU. It is scalar. Value range [0, 1]. Default to + 0. + score_threshold + Type tensor(float). + Float representing the threshold for deciding when to remove boxes based + on score. It is a scalar. + center_point_box + Attribute. + Integer indicate the format of the box data. The default is 0. 0 - the + box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are + the coordinates of any diagonal pair of box corners and the coordinates + can be provided as normalized (i.e., lying in the interval [0, 1]) or + absolute. Mostly used for TF models. 1 - the box data is supplied as + [x_center, y_center, width, height]. Mostly used for Pytorch models. + + Returns + ======= + selected_indices : Var + Type tensor(int64). + selected indices from the boxes tensor. [num_selected_indices, 3], the + selected index format is [batch_index, class_index, box_index]. + + Notes + ===== + Signature: ``ai.onnx@11::NonMaxSuppression``. + + """ + return ( + _NonMaxSuppression( + _NonMaxSuppression.Attributes( + center_point_box=AttrInt64(center_point_box, name="center_point_box"), + ), + _NonMaxSuppression.Inputs( + boxes=unwrap_vars(boxes), + scores=unwrap_vars(scores), + max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), + iou_threshold=unwrap_vars(iou_threshold), + score_threshold=unwrap_vars(score_threshold), + ), + ) + .get_output_vars( + boxes=get_value(boxes), + scores=get_value(scores), + max_output_boxes_per_class=get_value(max_output_boxes_per_class), + iou_threshold=get_value(iou_threshold), + score_threshold=get_value(score_threshold), + ) + .selected_indices + ) + + +def non_zero( + X: Var, +) -> Var: + r""" + Returns the indices of the elements that are non-zero (in row-major + order - by dimension). NonZero behaves similar to numpy.nonzero: + https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html, + but for scalar input, NonZero produces output shape (0, N) instead of + (1, N), which is different from Numpy's behavior. + + Parameters + ========== + X + Type T. + input + + Returns + ======= + Y : Var + Type tensor(int64). + output + + Notes + ===== + Signature: ``ai.onnx@13::NonZero``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _NonZero( + _NonZero.Attributes(), + _NonZero.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def not_( + X: Var, +) -> Var: + r""" + Returns the negation of the input tensor element-wise. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@1::Not``. + + Type constraints: + - T: `tensor(bool)` + """ + return ( + _Not( + _Not.Attributes(), + _Not.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def one_hot( + indices: Var, + depth: Var, + values: Var, + *, + axis: int = -1, +) -> Var: + r""" + Produces a one-hot tensor based on inputs. The locations represented by + the index values in the 'indices' input tensor will have 'on_value' and + the other locations will have 'off_value' in the output tensor, where + 'on_value' and 'off_value' are specified as part of required input + argument 'values', which is a two-element tensor of format [off_value, + on_value]. The rank of the output tensor will be one greater than the + rank of the input tensor. The additional dimension is for one-hot + representation. The additional dimension will be inserted at the + position specified by 'axis'. If 'axis' is not specified then then + additional dimension will be inserted as the innermost dimension, i.e. + axis=-1. The size of the additional dimension is specified by required + scalar input 'depth'. The type of the output tensor is the same as the + type of the 'values' input. Any entries in the 'indices' input tensor + with values outside the range [-depth, depth-1] will result in one-hot + representation with all 'off_value' values in the output tensor. + + :: + + when axis = 0: + output[input[i, j, k], i, j, k] = 1 for all i, j, k and 0 otherwise. + + when axis = -1: + output[i, j, k, input[i, j, k]] = 1 for all i, j, k and 0 otherwise. + + Parameters + ========== + indices + Type T1. + Input tensor containing indices. Any entries in the 'indices' input + tensor with values outside the range [-depth, depth-1] will result in + one-hot representation with all 'off_value' values in the output + tensor.In case 'indices' is of non-integer type, the values will be + casted to int64 before use. + depth + Type T2. + Scalar or Rank 1 tensor containing exactly one element, specifying the + number of classes in one-hot tensor. This is also the size of the + one-hot dimension (specified by 'axis' attribute) added on in the output + tensor. The values in the 'indices' input tensor are expected to be in + the range [-depth, depth-1]. In case 'depth' is of non-integer type, it + will be casted to int64 before use. + values + Type T3. + Rank 1 tensor containing exactly two elements, in the format [off_value, + on_value], where 'on_value' is the value used for filling locations + specified in 'indices' input tensor, and 'off_value' is the value used + for filling locations other than those specified in 'indices' input + tensor. + axis + Attribute. + (Optional) Axis along which one-hot representation in added. Default: + axis=-1. axis=-1 means that the additional dimension will be inserted as + the innermost/last dimension in the output tensor. Negative value means + counting dimensions from the back. Accepted range is [-r-1, r] where r = + rank(indices). + + Returns + ======= + output : Var + Type T3. + Tensor of rank one greater than input tensor 'indices', i.e. + rank(output) = rank(indices) + 1. The data type for the elements of the + output tensor is the same as the type of input 'values' is used. + + Notes + ===== + Signature: ``ai.onnx@11::OneHot``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T3: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _OneHot( + _OneHot.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _OneHot.Inputs( + indices=unwrap_vars(indices), + depth=unwrap_vars(depth), + values=unwrap_vars(values), + ), + ) + .get_output_vars( + indices=get_value(indices), + depth=get_value(depth), + values=get_value(values), + ) + .output + ) + + +def optional( + input: Optional[Var] = None, + *, + type: Optional[Type] = None, +) -> Var: + r""" + Constructs an optional-type value containing either an empty optional of + a certain type specified by the attribute, or a non-empty value + containing the input element. + + Parameters + ========== + input + Type V. + The input element. + type + Attribute. + Type of the element in the optional output + + Returns + ======= + output : Var + Type O. + The optional output enclosing the input element. + + Notes + ===== + Signature: ``ai.onnx@15::Optional``. + + Type constraints: + - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` + """ + return ( + _Optional( + _Optional.Attributes( + type=AttrType.maybe(type, name="type"), + ), + _Optional.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def optional_get_element( + input: Var, +) -> Var: + r""" + Outputs the element in the optional-type input. It is an error if the + input value does not have an element and the behavior is undefined in + this case. + + Parameters + ========== + input + Type O. + The optional input. + + Returns + ======= + output : Var + Type V. + Output element in the optional input. + + Notes + ===== + Signature: ``ai.onnx@15::OptionalGetElement``. + + Type constraints: + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` + - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _OptionalGetElement( + _OptionalGetElement.Attributes(), + _OptionalGetElement.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def optional_has_element( + input: Var, +) -> Var: + r""" + Returns true if the optional-type input contains an element. If it is an + empty optional-type, this op returns false. + + Parameters + ========== + input + Type O. + The optional input. + + Returns + ======= + output : Var + Type B. + A scalar boolean tensor. If true, it indicates that optional-type input + contains an element. Otherwise, it is empty. + + Notes + ===== + Signature: ``ai.onnx@15::OptionalHasElement``. + + Type constraints: + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` + - B: `tensor(bool)` + """ + return ( + _OptionalHasElement( + _OptionalHasElement.Attributes(), + _OptionalHasElement.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def or_( + A: Var, + B: Var, +) -> Var: + r""" + Returns the tensor resulted from performing the ``or`` logical operation + elementwise on the input tensors ``A`` and ``B`` (with Numpy-style + broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@7::Or``. + + Type constraints: + - T: `tensor(bool)` + - T1: `tensor(bool)` + """ + return ( + _Or( + _Or.Attributes(), + _Or.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def prelu( + X: Var, + slope: Var, +) -> Var: + r""" + PRelu takes input data (Tensor) and slope tensor as input, and + produces one output data (Tensor) where the function + ``f(x) = slope * x for x < 0``, ``f(x) = x for x >= 0``., is applied to + the data tensor elementwise. This operator supports **unidirectional + broadcasting** (tensor slope should be unidirectional broadcastable to + input tensor X); for more details please check `the + doc `__. + + Parameters + ========== + X + Type T. + Input tensor + slope + Type T. + Slope tensor. The shape of slope can be smaller than first input X; if + so, its shape must be unidirectional broadcastable to X + + Returns + ======= + Y : Var + Type T. + Output tensor (same size as X) + + Notes + ===== + Signature: ``ai.onnx@16::PRelu``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _PRelu( + _PRelu.Attributes(), + _PRelu.Inputs( + X=unwrap_vars(X), + slope=unwrap_vars(slope), + ), + ) + .get_output_vars( + X=get_value(X), + slope=get_value(slope), + ) + .Y + ) + + +def pad( + data: Var, + pads: Var, + constant_value: Optional[Var] = None, + *, + mode: str = "constant", +) -> Var: + r""" + Given a tensor containing the data to be padded (``data``), a tensor + containing the number of start and end pad values for axis (``pads``), + (optionally) a ``mode``, and (optionally) ``constant_value``, a padded + tensor (``output``) is generated. + + The three supported ``modes`` are (similar to corresponding modes + supported by ``numpy.pad``): + + 1) ``constant``\ (default) - pads with a given constant value as + specified by ``constant_value`` (which defaults to 0, empty string, + or False) + + 2) ``reflect`` - pads with the reflection of the vector mirrored on the + first and last values of the vector along each axis + + 3) ``edge`` - pads with the edge values of array + + Example 1 (``constant`` mode): Insert 0 pads to the beginning of the + second dimension. + + data = [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], ] + + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = [ [0.0, 0.0, 1.0, 1.2], [0.0, 0.0, 2.3, 3.4], [0.0, 0.0, 4.5, + 5.7], ] + + Example 2 (``reflect`` mode): data = [ [1.0, 1.2], [2.3, 3.4], [4.5, + 5.7], ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = [ [1.0, 1.2, 1.0, 1.2], [2.3, 3.4, 2.3, 3.4], [4.5, 5.7, 4.5, + 5.7], ] + + Example 3 (``edge`` mode): data = [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = [ [1.0, 1.0, 1.0, 1.2], [2.3, 2.3, 2.3, 3.4], [4.5, 4.5, 4.5, + 5.7], ] + + Parameters + ========== + data + Type T. + Input tensor. + pads + Type tensor(int64). + Tensor of integers indicating the number of padding elements to add or + remove (if negative) at the beginning and end of each axis. For 2D input + tensor, it is the number of pixels. ``pads`` should be a 1D tensor of + shape [2 \* input_rank]. ``pads`` format should be: [x1_begin, + x2_begin,...,x1_end, x2_end,...], where xi_begin is the number of pad + values added at the beginning of axis ``i`` and xi_end, the number of + pad values added at the end of axis ``i``. + constant_value + Type T. + (Optional) A scalar value to be used if the mode chosen is ``constant`` + (by default it is 0, empty string or False). + mode + Attribute. + Supported modes: ``constant``\ (default), ``reflect``, ``edge`` + + Returns + ======= + output : Var + Type T. + Tensor after padding. + + Notes + ===== + Signature: ``ai.onnx@13::Pad``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), + _Pad.Inputs( + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + ), + ) + .get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + ) + .output + ) + + +def pow( + X: Var, + Y: Var, +) -> Var: + r""" + Pow takes input data (Tensor) and exponent Tensor, and produces one + output data (Tensor) where the function ``f(x) = x^exponent``, is + applied to the data tensor elementwise. This operator supports + **multidirectional (i.e., Numpy-style) broadcasting**; for more details + please check `the + doc `__. + + Parameters + ========== + X + Type T. + First operand, base of the exponent. + Y + Type T1. + Second operand, power of the exponent. + + Returns + ======= + Z : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@15::Pow``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)` + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Pow( + _Pow.Attributes(), + _Pow.Inputs( + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + X=get_value(X), + Y=get_value(Y), + ) + .Z + ) + + +def qlinear_conv( + x: Var, + x_scale: Var, + x_zero_point: Var, + w: Var, + w_scale: Var, + w_zero_point: Var, + y_scale: Var, + y_zero_point: Var, + B: Optional[Var] = None, + *, + auto_pad: str = "NOTSET", + dilations: Optional[Iterable[int]] = None, + group: int = 1, + kernel_shape: Optional[Iterable[int]] = None, + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: + r""" + The convolution operator consumes a quantized input tensor, its scale + and zero point, a quantized filter, its scale and zero point, and + output's scale and zero point, and computes the quantized output. Each + scale and zero-point pair must have same shape. It means they must be + either scalars (per tensor) or 1-D tensors (per output channel). Each + input or output and its related zero point must have same type. When + bias is present it must be quantized using scale = input scale \* weight + scale and zero point as 0. + + Parameters + ========== + x + Type T1. + Input data tensor from previous layer; has size (N x C x H x W), where N + is the batch size, C is the number of channels, and H and W are the + height and width. Note that this is for the 2D image. Otherwise the size + is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in + effect, the operation expects input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. + x_scale + Type tensor(float). + Scale tensor for input 'x'. It's a scalar, which means a + per-tensor/layer quantization. + x_zero_point + Type T1. + Zero point tensor for input 'x'. It's a scalar, which means a + per-tensor/layer quantization. + w + Type T2. + The weight tensor that will be used in the convolutions; has size (M x + C/group x kH x kW), where C is the number of channels, and kH and kW are + the height and width of the kernel, and M is the number of feature maps. + For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x + k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. + Optionally, if dimension denotation is in effect, the operation expects + the weight tensor to arrive with the dimension denotation of + [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL + ...]. X.shape[1] == (W.shape[1] \* group) == C (assuming zero based + indices for the shape array). Or in other words FILTER_IN_CHANNEL should + be equal to DATA_CHANNEL. + w_scale + Type tensor(float). + Scale tensor for input 'w'. It could be a scalar or a 1-D tensor, which + means a per-tensor/layer or per output channel quantization. If it's a + 1-D tensor, its number of elements should be equal to the number of + output channels (M). + w_zero_point + Type T2. + Zero point tensor for input 'w'. It could be a scalar or a 1-D tensor, + which means a per-tensor/layer or per output channel quantization. If + it's a 1-D tensor, its number of elements should be equal to the number + of output channels (M). + y_scale + Type tensor(float). + Scale tensor for output 'y'. It's a scalar, which means a + per-tensor/layer quantization. + y_zero_point + Type T3. + Zero point tensor for output 'y'. It's a scalar, which means a + per-tensor/layer quantization. + B + Type T4. + Optional 1D bias to be added to the convolution, has size of M. Bias + must be quantized using scale = x_scale \* w_scale and zero_point = 0 + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. + dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults to 1 along each spatial axis. + group + Attribute. + number of groups input channels and output channels are divided into. + default is 1. + kernel_shape + Attribute. + The shape of the convolution kernel. If not present, should be inferred + from input 'w'. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0.The value represent the number + of pixels added to the beginning and end part of the corresponding + axis.\ ``pads`` format should be as follow [x1_begin, x2_begin...x1_end, + x2_end,...], where xi_begin the number ofpixels added at the beginning + of axis ``i`` and xi_end, the number of pixels added at the end of axis + ``i``.This attribute cannot be used simultaneously with auto_pad + attribute. If not present, the padding defaultsto 0 along start and end + of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + + Returns + ======= + y : Var + Type T3. + Output data tensor that contains the result of the convolution. The + output dimensions are functions of the kernel size, stride size, and pad + lengths. + + Notes + ===== + Signature: ``ai.onnx@10::QLinearConv``. + + Type constraints: + - T1: `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(int8)`, `tensor(uint8)` + - T4: `tensor(int32)` + """ + return ( + _QLinearConv( + _QLinearConv.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _QLinearConv.Inputs( + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + w=unwrap_vars(w), + w_scale=unwrap_vars(w_scale), + w_zero_point=unwrap_vars(w_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + w=get_value(w), + w_scale=get_value(w_scale), + w_zero_point=get_value(w_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + B=get_value(B), + ) + .y + ) + + +def qlinear_matmul( + a: Var, + a_scale: Var, + a_zero_point: Var, + b: Var, + b_scale: Var, + b_zero_point: Var, + y_scale: Var, + y_zero_point: Var, +) -> Var: + r""" + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + It consumes two quantized input tensors, their scales and zero points, + scale and zero point of output, and computes the quantized output. The + quantization formula is y = saturate((x / y_scale) + y_zero_point). For + (x / y_scale), it is rounding to nearest ties to even. Refer to + https://en.wikipedia.org/wiki/Rounding for details. Scale and zero point + must have same shape. They must be either scalar (per tensor) or N-D + tensor (per row for 'a' and per column for 'b'). Scalar refers to per + tensor quantization whereas N-D refers to per row or per column + quantization. If the input is 2D of shape [M, K] then zero point and + scale tensor may be an M element vector [v_1, v_2, ..., v_M] for per row + quantization and K element vector of shape [v_1, v_2, ..., v_K] for per + column quantization. If the input is N-D tensor with shape [D1, D2, M, + K] then zero point and scale tensor may have shape [D1, D2, M, 1] for + per row quantization and shape [D1, D2, 1, K] for per column + quantization. Production must never overflow, and accumulation may + overflow if and only if in 32 bits. + + Parameters + ========== + a + Type T1. + N-dimensional quantized matrix a + a_scale + Type tensor(float). + scale of quantized input a + a_zero_point + Type T1. + zero point of quantized input a + b + Type T2. + N-dimensional quantized matrix b + b_scale + Type tensor(float). + scale of quantized input b + b_zero_point + Type T2. + zero point of quantized input b + y_scale + Type tensor(float). + scale of quantized output y + y_zero_point + Type T3. + zero point of quantized output y + + Returns + ======= + y : Var + Type T3. + Quantized matrix multiply results from a \* b + + Notes + ===== + Signature: ``ai.onnx@10::QLinearMatMul``. + + Type constraints: + - T1: `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(int8)`, `tensor(uint8)` + """ + return ( + _QLinearMatMul( + _QLinearMatMul.Attributes(), + _QLinearMatMul.Inputs( + a=unwrap_vars(a), + a_scale=unwrap_vars(a_scale), + a_zero_point=unwrap_vars(a_zero_point), + b=unwrap_vars(b), + b_scale=unwrap_vars(b_scale), + b_zero_point=unwrap_vars(b_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + a=get_value(a), + a_scale=get_value(a_scale), + a_zero_point=get_value(a_zero_point), + b=get_value(b), + b_scale=get_value(b_scale), + b_zero_point=get_value(b_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) + + +def quantize_linear( + x: Var, + y_scale: Var, + y_zero_point: Optional[Var] = None, + *, + axis: int = 1, +) -> Var: + r""" + The linear quantization operator. It consumes a high precision tensor, a + scale, and a zero point to compute the low precision / quantized tensor. + The scale factor and zero point must have same shape, and can be either + a scalar for per-tensor / per layer quantization, or a 1-D tensor for + per-axis quantization. The quantization formula is y = saturate ((x / + y_scale) + y_zero_point). For saturation, it saturates to [0, 255] if + it's uint8, or [-128, 127] if it's int8. For (x / y_scale), it's + rounding to the nearest even. Refer to + https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and + 'y' must have same type. + + Parameters + ========== + x + Type T1. + N-D full precision Input tensor to be quantized. + y_scale + Type tensor(float). + Scale for doing quantization to get 'y'. It can be a scalar, which means + per-tensor/layer quantization, or a 1-D Tensor for per-axis + quantization. + y_zero_point + Type T2. + Zero point for doing quantization to get 'y'. Shape must match y_scale. + Default is uint8 with zero point of 0 if it's not specified. + axis + Attribute. + (Optional) The axis of the quantization dimension of the input tensor. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + + Returns + ======= + y : Var + Type T2. + N-D quantized output tensor. It has same shape as input 'x'. + + Notes + ===== + Signature: ``ai.onnx@13::QuantizeLinear``. + + Type constraints: + - T1: `tensor(float)`, `tensor(int32)` + - T2: `tensor(int8)`, `tensor(uint8)` + """ + return ( + _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _QuantizeLinear.Inputs( + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) + + +def rnn( + X: Var, + W: Var, + R: Var, + B: Optional[Var] = None, + sequence_lens: Optional[Var] = None, + initial_h: Optional[Var] = None, + *, + activation_alpha: Optional[Iterable[float]] = None, + activation_beta: Optional[Iterable[float]] = None, + activations: Iterable[str] = ("Tanh", "Tanh"), + clip: Optional[float] = None, + direction: str = "forward", + hidden_size: Optional[int] = None, + layout: int = 0, +) -> tuple[Var, Var]: + r""" + Computes an one-layer simple RNN. This operator is usually supported via + some custom implementation such as CuDNN. + + Notations: + + - ``X`` - input tensor + - ``i`` - input gate + - ``t`` - time step (t-1 means previous time step) + - ``Wi`` - W parameter weight matrix for input gate + - ``Ri`` - R recurrence weight matrix for input gate + - ``Wbi`` - W parameter bias vector for input gate + - ``Rbi`` - R parameter bias vector for input gate + - ``WBi`` - W parameter weight matrix for backward input gate + - ``RBi`` - R recurrence weight matrix for backward input gate + - ``WBbi`` - WR bias vectors for backward input gate + - ``RBbi`` - RR bias vectors for backward input gate + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 + + Activation functions: + + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) + + NOTE: Below are optional + + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) + + Equations (Default: f=Tanh): + + - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has + **optional** inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. + + Parameters + ========== + X + Type T. + The input sequences packed (and potentially padded) into one 3-D tensor + with the shape of ``[seq_length, batch_size, input_size]``. + W + Type T. + The weight tensor for input gate. Concatenation of ``Wi`` and ``WBi`` + (if bidirectional). The tensor has shape + ``[num_directions, hidden_size, input_size]``. + R + Type T. + The recurrence weight tensor. Concatenation of ``Ri`` and ``RBi`` (if + bidirectional). The tensor has shape + ``[num_directions, hidden_size, hidden_size]``. + B + Type T. + The bias tensor for input gate. Concatenation of ``[Wbi, Rbi]`` and + ``[WBbi, RBbi]`` (if bidirectional). The tensor has shape + ``[num_directions, 2*hidden_size]``. Optional: If not specified - + assumed to be 0. + sequence_lens + Type T1. + Optional tensor specifying lengths of the sequences in a batch. If not + specified - assumed all sequences in the batch to have length + ``seq_length``. It has shape ``[batch_size]``. + initial_h + Type T. + Optional initial value of the hidden. If not specified - assumed to be + 0. It has shape ``[num_directions, batch_size, hidden_size]``. + activation_alpha + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX + operators.For example with LeakyRelu, the default alpha is 0.01. + activation_beta + Attribute. + Optional scaling values used by some activation functions. The values + are consumed in the order of activation functions, for example (f, g, h) + in LSTM. Default values are the same as of corresponding ONNX operators. + activations + Attribute. + One (or two if bidirectional) activation function for input gate. The + activation function must be one of the activation functions specified + above. Optional: Default ``Tanh`` if not specified. + clip + Attribute. + Cell clip threshold. Clipping bounds the elements of a tensor in the + range of [-threshold, +threshold] and is applied to the input of + activations. No clip if not specified. + direction + Attribute. + Specify if the RNN is forward, reverse, or bidirectional. Must be one of + forward (default), reverse, or bidirectional. + hidden_size + Attribute. + Number of neurons in the hidden layer + layout + Attribute. + The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the + following shapes are expected: X.shape = [seq_length, batch_size, + input_size], Y.shape = [seq_length, num_directions, batch_size, + hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, + hidden_size]. If 1, the following shapes are expected: X.shape = + [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, + num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, + num_directions, hidden_size]. + + Returns + ======= + Y : Var + Type T. + A tensor that concats all the intermediate output values of the hidden. + It has shape ``[seq_length, num_directions, batch_size, hidden_size]``. + Y_h : Var + Type T. + The last output value of the hidden. It has shape + ``[num_directions, batch_size, hidden_size]``. + + Notes + ===== + Signature: ``ai.onnx@14::RNN``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T1: `tensor(int32)` + """ + return ( + _RNN( + _RNN.Attributes( + activation_alpha=AttrFloat32s.maybe( + activation_alpha, name="activation_alpha" + ), + activation_beta=AttrFloat32s.maybe( + activation_beta, name="activation_beta" + ), + activations=AttrStrings(activations, name="activations"), + clip=AttrFloat32.maybe(clip, name="clip"), + direction=AttrString(direction, name="direction"), + hidden_size=AttrInt64.maybe(hidden_size, name="hidden_size"), + layout=AttrInt64(layout, name="layout"), + ), + _RNN.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + R=unwrap_vars(R), + B=unwrap_vars(B), + sequence_lens=unwrap_vars(sequence_lens), + initial_h=unwrap_vars(initial_h), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + R=get_value(R), + B=get_value(B), + sequence_lens=get_value(sequence_lens), + initial_h=get_value(initial_h), + ) + ._unpack_to_any() + ) + + +def random_normal( + *, + dtype: npt.DTypeLike = np.float32, + mean: float = 0.0, + scale: float = 1.0, + seed: Optional[float] = None, + shape: Iterable[int], +) -> Var: + r""" + Generate a tensor with random values drawn from a normal distribution. + The shape of the tensor is specified by the ``shape`` argument and the + parameter of the normal distribution specified by ``mean`` and + ``scale``. + + The data type is specified by the 'dtype' argument. The 'dtype' argument + must be one of the data types specified in the 'DataType' enum field in + the TensorProto message. + + Parameters + ========== + dtype + Attribute. + The data type for the elements of the output tensor. Default is + TensorProto::FLOAT. + mean + Attribute. + The mean of the normal distribution. + scale + Attribute. + The standard deviation of the normal distribution. + seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + shape + Attribute. + The shape of the output tensor. + + Returns + ======= + output : Var + Type T. + Output tensor of random values drawn from normal distribution + + Notes + ===== + Signature: ``ai.onnx@1::RandomNormal``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _RandomNormal( + _RandomNormal.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + mean=AttrFloat32(mean, name="mean"), + scale=AttrFloat32(scale, name="scale"), + seed=AttrFloat32.maybe(seed, name="seed"), + shape=AttrInt64s(shape, name="shape"), + ), + _RandomNormal.Inputs(), + ) + .get_output_vars() + .output + ) + + +def random_normal_like( + input: Var, + *, + dtype: Optional[npt.DTypeLike] = None, + mean: float = 0.0, + scale: float = 1.0, + seed: Optional[float] = None, +) -> Var: + r""" + Generate a tensor with random values drawn from a normal distribution. + The shape of the output tensor is copied from the shape of the input + tensor, and the parameters of the normal distribution are specified by + ``mean`` and ``scale``. + + The data type is specified by the 'dtype' argument, or copied from the + input tensor if not provided. The 'dtype' argument must be one of the + data types specified in the 'DataType' enum field in the TensorProto + message, and be valid as an output type. + + Parameters + ========== + input + Type T1. + Input tensor to copy shape and optionally type information from. + dtype + Attribute. + (Optional) The data type for the elements of the output tensor, if not + specified, we will use the data type of the input tensor. + mean + Attribute. + The mean of the normal distribution. + scale + Attribute. + The standard deviation of the normal distribution. + seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + + Returns + ======= + output : Var + Type T2. + Output tensor of random values drawn from normal distribution + + Notes + ===== + Signature: ``ai.onnx@1::RandomNormalLike``. + + Type constraints: + - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _RandomNormalLike( + _RandomNormalLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + mean=AttrFloat32(mean, name="mean"), + scale=AttrFloat32(scale, name="scale"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), + _RandomNormalLike.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def random_uniform( + *, + dtype: npt.DTypeLike = np.float32, + high: float = 1.0, + low: float = 0.0, + seed: Optional[float] = None, + shape: Iterable[int], +) -> Var: + r""" + Generate a tensor with random values drawn from a uniform distribution. + The shape of the tensor is specified by the ``shape`` argument and the + range by ``low`` and ``high``. + + The data type is specified by the 'dtype' argument. The 'dtype' argument + must be one of the data types specified in the 'DataType' enum field in + the TensorProto message. + + Parameters + ========== + dtype + Attribute. + The data type for the elements of the output tensor. If not specified, + default is TensorProto::FLOAT. + high + Attribute. + Upper boundary of the output values. + low + Attribute. + Lower boundary of the output values. + seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + shape + Attribute. + The shape of the output tensor. + + Returns + ======= + output : Var + Type T. + Output tensor of random values drawn from uniform distribution + + Notes + ===== + Signature: ``ai.onnx@1::RandomUniform``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _RandomUniform( + _RandomUniform.Attributes( + dtype=AttrDtype(dtype, name="dtype"), + high=AttrFloat32(high, name="high"), + low=AttrFloat32(low, name="low"), + seed=AttrFloat32.maybe(seed, name="seed"), + shape=AttrInt64s(shape, name="shape"), + ), + _RandomUniform.Inputs(), + ) + .get_output_vars() + .output + ) + + +def random_uniform_like( + input: Var, + *, + dtype: Optional[npt.DTypeLike] = None, + high: float = 1.0, + low: float = 0.0, + seed: Optional[float] = None, +) -> Var: + r""" + Generate a tensor with random values drawn from a uniform distribution. + The shape of the output tensor is copied from the shape of the input + tensor, and the parameters of the uniform distribution are specified by + ``low`` and ``high``. + + The data type is specified by the 'dtype' argument, or copied from the + input tensor if not provided. The 'dtype' argument must be one of the + data types specified in the 'DataType' enum field in the TensorProto + message and be valid as an output type. + + Parameters + ========== + input + Type T1. + Input tensor to copy shape and optionally type information from. + dtype + Attribute. + (Optional) The data type for the elements of the output tensor, if not + specified, we will use the data type of the input tensor. + high + Attribute. + Upper boundary of the output values. + low + Attribute. + Lower boundary of the output values. + seed + Attribute. + (Optional) Seed to the random generator, if not specified we will auto + generate one. + + Returns + ======= + output : Var + Type T2. + Output tensor of random values drawn from uniform distribution + + Notes + ===== + Signature: ``ai.onnx@1::RandomUniformLike``. + + Type constraints: + - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _RandomUniformLike( + _RandomUniformLike.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + high=AttrFloat32(high, name="high"), + low=AttrFloat32(low, name="low"), + seed=AttrFloat32.maybe(seed, name="seed"), + ), + _RandomUniformLike.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def range( + start: Var, + limit: Var, + delta: Var, +) -> Var: + r""" + Generate a tensor containing a sequence of numbers that begin at + ``start`` and extends by increments of ``delta`` up to ``limit`` + (exclusive). + + The number of elements in the output of range is computed as below: + + :: + + number_of_elements = max( ceil( (limit - start) / delta ) , 0 ) + + The pseudocode determining the contents of the output is shown below: + + :: + + for(int i=0; i Var: + r""" + Reciprocal takes one input data (Tensor) and produces one output data + (Tensor) where the reciprocal is, y = 1/x, is applied to the tensor + elementwise. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::Reciprocal``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Reciprocal( + _Reciprocal.Attributes(), + _Reciprocal.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def reduce_l1( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the L1 norm of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields 0. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceL1``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _ReduceL1( + _ReduceL1.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceL1.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def reduce_l2( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the L2 norm of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields 0. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceL2``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _ReduceL2( + _ReduceL2.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceL2.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def reduce_log_sum( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the log sum of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields minus infinity (if + supported by the datatype) or undefined otherwise. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceLogSum``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _ReduceLogSum( + _ReduceLogSum.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceLogSum.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def reduce_log_sum_exp( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the log sum exponent of the input tensor's elements along the + provided axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields minus infinity (if + supported by the datatype) or undefined otherwise. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceLogSumExp``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _ReduceLogSumExp( + _ReduceLogSumExp.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceLogSumExp.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def reduce_max( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the max of the input tensor's elements along the provided axes. + The resulting tensor has the same rank as the input if ``keepdims`` + equals 1. If ``keepdims`` equals 0, then the resulting tensor has the + reduced dimension pruned. Input tensors of rank zero are valid. + Reduction over an empty set of values yields minus infinity (if + supported by the datatype) or the minimum value of the data type + otherwise. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceMax``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _ReduceMax( + _ReduceMax.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceMax.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def reduce_mean( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the mean of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields undefined. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceMean``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _ReduceMean( + _ReduceMean.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceMean.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def reduce_min( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the min of the input tensor's elements along the provided axes. + The resulting tensor has the same rank as the input if ``keepdims`` + equals 1. If ``keepdims`` equals 0, then the resulting tensor has the + reduced dimension pruned. Input tensors of rank zero are valid. + Reduction over an empty set of values yields plus infinity (if supported + by the datatype) or the maximum value of the data type otherwise. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceMin``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _ReduceMin( + _ReduceMin.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceMin.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def reduce_prod( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the product of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields 1. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceProd``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _ReduceProd( + _ReduceProd.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceProd.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def reduce_sum( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: + r""" + Computes the sum of the input tensor's elements along the provided axes. + The resulting tensor has the same rank as the input if ``keepdims`` + equals 1. If ``keepdims`` equals 0, then the resulting tensor has the + reduced dimension pruned. Input tensors of rank zero are valid. + Reduction over an empty set of values yields 0. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceSum``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _ReduceSum( + _ReduceSum.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceSum.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_sum_square( + data: Var, + *, + axes: Optional[Iterable[int]] = None, + keepdims: int = 1, +) -> Var: + r""" + Computes the sum square of the input tensor's elements along the + provided axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields 0. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Attribute. + A list of integers, along which to reduce. The default is to reduce over + all the dimensions of the input tensor. Accepted range is [-r, r-1] + where r = rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::ReduceSumSquare``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + """ + return ( + _ReduceSumSquare( + _ReduceSumSquare.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _ReduceSumSquare.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .reduced + ) + + +def relu( + X: Var, +) -> Var: + r""" + Relu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = max(0, x), is + applied to the tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@14::Relu``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` + """ + return ( + _Relu( + _Relu.Attributes(), + _Relu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def reshape( + data: Var, + shape: Var, + *, + allowzero: int = 0, +) -> Var: + r""" + Reshape the input tensor similar to numpy.reshape. First input is the + data tensor, second input is a shape tensor which specifies the output + shape. It outputs the reshaped tensor. At most one dimension of the new + shape can be -1. In this case, the value is inferred from the size of + the tensor and the remaining dimensions. A dimension could also be 0, in + which case the actual dimension value is unchanged (i.e. taken from the + input tensor). If 'allowzero' is set, and the new shape includes 0, the + dimension will be set explicitly to zero (i.e. not taken from input + tensor). Shape (second input) could be an empty shape, which means + converting to a scalar. The input tensor's shape and the output tensor's + shape are required to have the same number of elements. + + If the attribute 'allowzero' is set, it is invalid for the specified + shape to contain both a zero value and -1, as the value of the dimension + corresponding to -1 cannot be determined uniquely. + + Parameters + ========== + data + Type T. + An input tensor. + shape + Type tensor(int64). + Specified shape for output. + allowzero + Attribute. + (Optional) By default, when any value in the 'shape' input is equal to + zero the corresponding dimension value is copied from the input tensor + dynamically. allowzero=1 indicates that if any value in the 'shape' + input is set to zero, the zero value is honored, similar to NumPy. + + Returns + ======= + reshaped : Var + Type T. + Reshaped data. + + Notes + ===== + Signature: ``ai.onnx@14::Reshape``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), + _Reshape.Inputs( + data=unwrap_vars(data), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + data=get_value(data), + shape=get_value(shape), + ) + .reshaped + ) + + +def resize( + X: Var, + roi: Optional[Var] = None, + scales: Optional[Var] = None, + sizes: Optional[Var] = None, + *, + coordinate_transformation_mode: str = "half_pixel", + cubic_coeff_a: float = -0.75, + exclude_outside: int = 0, + extrapolation_value: float = 0.0, + mode: str = "nearest", + nearest_mode: str = "round_prefer_floor", +) -> Var: + r""" + Resize the input tensor. In general, it calculates every value in the + output tensor as a weighted average of neighborhood (a.k.a. sampling + locations) in the input tensor. Each dimension value of the output + tensor is: output_dimension = floor(input_dimension \* (roi_end - + roi_start) \* scale) if input "sizes" is not specified. + + Parameters + ========== + X + Type T1. + N-D tensor + roi + Type T2. + 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is + the rank of X. The RoIs' coordinates are normalized in the coordinate + system of the input image. It only takes effect when + coordinate_transformation_mode is "tf_crop_and_resize" + scales + Type tensor(float). + The scale array along each dimension. It takes value greater than 0. If + it's less than 1, it's sampling down, otherwise, it's upsampling. The + number of elements of 'scales' should be the same as the rank of input + 'X'. One of 'scales' and 'sizes' MUST be specified and it is an error if + both are specified. If 'sizes' is needed, the user can use an empty + string as the name of 'scales' in this operator's input list. + sizes + Type tensor(int64). + The size of the output tensor. The number of elements of 'sizes' should + be the same as the rank of input 'X'. Only one of 'scales' and 'sizes' + can be specified. + coordinate_transformation_mode + Attribute. + This attribute describes how to transform the coordinate in the resized + tensor to the coordinate in the original tensor. + + The coordinate of each dimension is transformed individually. Let's + describe a case using axis x as an example. Denote x_resized as the + coordinate of axis x in the resized tensor, x_original as the coordinate + of axis x in the original tensor, length_original as the length of the + original tensor in axis x, length_resized as the length of the resized + tensor in axis x, roi_x = (start_x, end_x) of the axis x in input "roi", + scale = length_resized / length_original, + + if coordinate_transformation_mode is "half_pixel", x_original = + (x_resized + 0.5) / scale - 0.5, + + if coordinate_transformation_mode is "pytorch_half_pixel", x_original = + length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0, + + if coordinate_transformation_mode is "align_corners", x_original = + x_resized \* (length_original - 1) / (length_resized - 1), + + if coordinate_transformation_mode is "asymmetric", x_original = + x_resized / scale, + + if coordinate_transformation_mode is "tf_crop_and_resize", x_original = + length_resized > 1 ? start_x \* (length_original - 1) + x_resized \* + (end_x - start_x) \* (length_original - 1) / (length_resized - 1) : 0.5 + \* (start_x + end_x) \* (length_original - 1). + cubic_coeff_a + Attribute. + The coefficient 'a' used in cubic interpolation. Two common choice are + -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out + Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the + details. This attribute is valid only if "mode" is "cubic". + exclude_outside + Attribute. + If set to 1, the weight of sampling locations outside the tensor will be + set to 0 and the weight will be renormalized so that their sum is 1.0. + The default value is 0. + extrapolation_value + Attribute. + When coordinate_transformation_mode is "tf_crop_and_resize" and + x_original is outside the range [0, length_original - 1], this value is + used as the corresponding output value. Default is 0.0f. + mode + Attribute. + Three interpolation modes: nearest (default), linear and cubic. The + "linear" mode includes linear interpolation for 1D tensor and N-linear + interpolation for N-D tensor (for example, bilinear interpolation for 2D + tensor). The "cubic" mode includes cubic interpolation for 1D tensor and + N-cubic interpolation for N-D tensor (for example, bicubic interpolation + for 2D tensor). + nearest_mode + Attribute. + Four modes: round_prefer_floor (default, as known as round half down), + round_prefer_ceil (as known as round half up), floor, ceil. Only used by + nearest interpolation. It indicates how to get "nearest" pixel in input + tensor from x_original, so this attribute is valid only if "mode" is + "nearest". + + Returns + ======= + Y : Var + Type T1. + N-D tensor after resizing + + Notes + ===== + Signature: ``ai.onnx@13::Resize``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Resize( + _Resize.Attributes( + coordinate_transformation_mode=AttrString( + coordinate_transformation_mode, + name="coordinate_transformation_mode", + ), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32( + extrapolation_value, name="extrapolation_value" + ), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), + ), + _Resize.Inputs( + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), + ), + ) + .get_output_vars( + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), + ) + .Y + ) + + +def reverse_sequence( + input: Var, + sequence_lens: Var, + *, + batch_axis: int = 1, + time_axis: int = 0, +) -> Var: + r""" + Reverse batch of sequences having different lengths specified by + ``sequence_lens``. + + For each slice i iterating on batch axis, the operator reverses the + first sequence_lens[i] elements on time axis, and copies elements whose + index's beyond sequence_lens[i] to the output. So the output slice i + contains reversed sequences on the first sequence_lens[i] elements, then + have original values copied for the other elements. + + Example 1: input = [[0.0, 4.0, 8.0, 12.0], [1.0, 5.0, 9.0, 13.0], [2.0, + 6.0, 10.0, 14.0], [3.0, 7.0, 11.0, 15.0]] sequence_lens = [4, 3, 2, 1] + time_axis = 0 batch_axis = 1 + + output = [[3.0, 6.0, 9.0, 12.0], [2.0, 5.0, 8.0, 13.0], [1.0, 4.0, 10.0, + 14.0], [0.0, 7.0, 11.0, 15.0]] + + Example 2: input = [[0.0, 1.0, 2.0, 3.0 ], [4.0, 5.0, 6.0, 7.0 ], [8.0, + 9.0, 10.0, 11.0], [12.0, 13.0, 14.0, 15.0]] sequence_lens = [1, 2, 3, 4] + time_axis = 1 batch_axis = 0 + + output = [[0.0, 1.0, 2.0, 3.0 ], [5.0, 4.0, 6.0, 7.0 ], [10.0, 9.0, 8.0, + 11.0], [15.0, 14.0, 13.0, 12.0]] + + Parameters + ========== + input + Type T. + Tensor of rank r >= 2. + sequence_lens + Type tensor(int64). + Tensor specifying lengths of the sequences in a batch. It has shape + ``[batch_size]``. + batch_axis + Attribute. + (Optional) Specify which axis is batch axis. Must be one of 1 (default), + or 0. + time_axis + Attribute. + (Optional) Specify which axis is time axis. Must be one of 0 (default), + or 1. + + Returns + ======= + Y : Var + Type T. + Tensor with same shape of input. + + Notes + ===== + Signature: ``ai.onnx@10::ReverseSequence``. + + Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _ReverseSequence( + _ReverseSequence.Attributes( + batch_axis=AttrInt64(batch_axis, name="batch_axis"), + time_axis=AttrInt64(time_axis, name="time_axis"), + ), + _ReverseSequence.Inputs( + input=unwrap_vars(input), + sequence_lens=unwrap_vars(sequence_lens), + ), + ) + .get_output_vars( + input=get_value(input), + sequence_lens=get_value(sequence_lens), + ) + .Y + ) + + +def roi_align( + X: Var, + rois: Var, + batch_indices: Var, + *, + coordinate_transformation_mode: str = "half_pixel", + mode: str = "avg", + output_height: int = 1, + output_width: int = 1, + sampling_ratio: int = 0, + spatial_scale: float = 1.0, +) -> Var: + r""" + Region of Interest (RoI) align operation described in the `Mask R-CNN + paper `__. RoiAlign consumes an input + tensor X and region of interests (rois) to apply pooling across each + RoI; it produces a 4-D tensor of shape (num_rois, C, output_height, + output_width). + + RoiAlign is proposed to avoid the misalignment by removing quantizations + while converting from original image into feature map and from feature + map into RoI feature; in each ROI bin, the value of the sampled + locations are computed directly through bilinear interpolation. + + Parameters + ========== + X + Type T1. + Input data tensor from the previous operator; 4-D feature map of shape + (N, C, H, W), where N is the batch size, C is the number of channels, + and H and W are the height and the width of the data. + rois + Type T1. + RoIs (Regions of Interest) to pool over; rois is 2-D input of shape + (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates + are in the coordinate system of the input image. Each coordinate set has + a 1:1 correspondence with the 'batch_indices' input. + batch_indices + Type T2. + 1-D tensor of shape (num_rois,) with each element denoting the index of + the corresponding image in the batch. + coordinate_transformation_mode + Attribute. + Allowed values are 'half_pixel' and 'output_half_pixel'. Use the value + 'half_pixel' to pixel shift the input coordinates by -0.5 (the + recommended behavior). Use the value 'output_half_pixel' to omit the + pixel shift for the input (use this for a backward-compatible behavior). + mode + Attribute. + The pooling method. Two modes are supported: 'avg' and 'max'. Default is + 'avg'. + output_height + Attribute. + default 1; Pooled output Y's height. + output_width + Attribute. + default 1; Pooled output Y's width. + sampling_ratio + Attribute. + Number of sampling points in the interpolation grid used to compute the + output value of each pooled output bin. If > 0, then exactly + sampling_ratio x sampling_ratio grid points are used. If == 0, then an + adaptive number of grid points are used (computed as ceil(roi_width / + output_width), and likewise for height). Default is 0. + spatial_scale + Attribute. + Multiplicative spatial scale factor to translate ROI coordinates from + their input spatial scale to the scale used when pooling, i.e., spatial + scale of the input feature map X relative to the input image. E.g.; + default is 1.0f. + + Returns + ======= + Y : Var + Type T1. + RoI pooled output, 4-D tensor of shape (num_rois, C, output_height, + output_width). The r-th batch element Y[r-1] is a pooled feature map + corresponding to the r-th RoI X[r-1]. + + Notes + ===== + Signature: ``ai.onnx@16::RoiAlign``. + + Type constraints: + - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int64)` + """ + return ( + _RoiAlign( + _RoiAlign.Attributes( + coordinate_transformation_mode=AttrString( + coordinate_transformation_mode, + name="coordinate_transformation_mode", + ), + mode=AttrString(mode, name="mode"), + output_height=AttrInt64(output_height, name="output_height"), + output_width=AttrInt64(output_width, name="output_width"), + sampling_ratio=AttrInt64(sampling_ratio, name="sampling_ratio"), + spatial_scale=AttrFloat32(spatial_scale, name="spatial_scale"), + ), + _RoiAlign.Inputs( + X=unwrap_vars(X), + rois=unwrap_vars(rois), + batch_indices=unwrap_vars(batch_indices), + ), + ) + .get_output_vars( + X=get_value(X), + rois=get_value(rois), + batch_indices=get_value(batch_indices), + ) + .Y + ) + + +def round( + X: Var, +) -> Var: + r""" + Round takes one input Tensor and rounds the values, element-wise, + meaning it finds the nearest integer for each value. In case of halves, + the rule is to round them to the nearest even integer. If input x is + integral, +0, -0, NaN, or infinite, x itself is returned. The output + tensor has the same shape and type as the input. + + Examples: + + :: + + round([0.9]) = [1.0] + round([2.5]) = [2.0] + round([2.3]) = [2.0] + round([1.5]) = [2.0] + round([-4.5]) = [-4.0] + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@11::Round``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Round( + _Round.Attributes(), + _Round.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def stft( + signal: Var, + frame_step: Var, + window: Optional[Var] = None, + frame_length: Optional[Var] = None, + *, + onesided: int = 1, +) -> Var: + r""" + Computes the Short-time Fourier Transform of the signal. + + Parameters + ========== + signal + Type T1. + Input tensor representing a real or complex valued signal. For real + input, the following shape is expected: [batch_size][signal_length][1]. + For complex input, the following shape is expected: + [batch_size][signal_length][2], where [batch_size][signal_length][0] + represents the real component and [batch_size][signal_length][1] + represents the imaginary component of the signal. + frame_step + Type T2. + The number of samples to step between successive DFTs. + window + Type T1. + A tensor representing the window that will be slid over the signal.The + window must have rank 1 with shape: [window_shape]. It's an optional + value. + frame_length + Type T2. + A scalar representing the size of the DFT. It's an optional value. + onesided + Attribute. + If onesided is 1, only values for w in [0, 1, 2, ..., floor(n_fft/2) + + 1] are returned because the real-to-complex Fourier transform satisfies + the conjugate symmetry, i.e., X[m, w] = X[m,w]=X[m,n_fft-w]\*. Note if + the input or window tensors are complex, then onesided output is not + possible. Enabling onesided with real inputs performs a Real-valued fast + Fourier transform (RFFT).When invoked with real or complex valued input, + the default value is 1. Values can be 0 or 1. + + Returns + ======= + output : Var + Type T1. + The Short-time Fourier Transform of the signals.If onesided is 1, the + output has the shape: [batch_size][frames][dft_unique_bins][2], where + dft_unique_bins is frame_length // 2 + 1 (the unique components of the + DFT) If onesided is 0, the output has the shape: + [batch_size][frames][frame_length][2], where frame_length is the length + of the DFT. + + Notes + ===== + Signature: ``ai.onnx@17::STFT``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return ( + _STFT( + _STFT.Attributes( + onesided=AttrInt64(onesided, name="onesided"), + ), + _STFT.Inputs( + signal=unwrap_vars(signal), + frame_step=unwrap_vars(frame_step), + window=unwrap_vars(window), + frame_length=unwrap_vars(frame_length), + ), + ) + .get_output_vars( + signal=get_value(signal), + frame_step=get_value(frame_step), + window=get_value(window), + frame_length=get_value(frame_length), + ) + .output + ) + + +def scan( + initial_state_and_scan_inputs: Sequence[Var], + *, + body: Callable[..., Iterable[Var]], + num_scan_inputs: int, + scan_input_axes: Optional[Iterable[int]] = None, + scan_input_directions: Optional[Iterable[int]] = None, + scan_output_axes: Optional[Iterable[int]] = None, + scan_output_directions: Optional[Iterable[int]] = None, +) -> Sequence[Var]: + r""" + Scan can be used to iterate over one or more scan_input tensors, + constructing zero or more scan_output tensors. It combines ideas from + general recurrences, functional programming constructs such as scan, + fold, map, and zip, and is intended to enable generalizations of + RNN-like constructs for sequence-to-sequence processing. Other tensors + (referred to as state_variables here) can be used to carry a state when + iterating from one element to another (similar to hidden-state in RNNs, + also referred to as loop-carried dependences in the context of loops). + Many common usages involve a single scan_input tensor (where + functionality similar to scan, fold and map can be obtained). When more + than one scan_input is used, a behavior similar to zip is obtained. + + The attribute body must be a graph, specifying the computation to be + performed in every iteration. It takes as input the current values of + the state_variables and the current iterated element of the scan_inputs. + It must return the (updated) values of the state_variables and zero or + more scan_output_element tensors. The values of the scan_output_element + tensors are concatenated over all the iterations to produce the + scan_output values of the scan construct (similar to the concatenated + intermediate hidden-state values of RNN-like constructs). All the output + tensors (state_variables as well as scan_output_element tensors) are + required to have the same shape in each iteration of the loop (a + restriction imposed to enable efficient memory allocation). + + Note that the iterated element passed to the body subgraph does not have + a sequence axis. It will have a rank one less than the rank of the + corresponding scan_input. + + The scan operation returns the final values of the state_variables as + well as the scan_outputs. + + The optional attribute scan_input_directions specifies the direction + (forward or backward) for each scan input. If this attribute is omitted, + all sequences are scanned in the forward direction. A bidirectional scan + may be performed by specifying the same tensor input twice in the + scan_inputs, once with a forward direction, and once with a backward + direction. + + The scan_output of the operation is produced by concatenating the + scan_output_element values produced by the body in each iteration. The + optional attribute scan_output_directions specifies the direction in + which scan_output is constructed (by appending or prepending the + scan_output_element to scan_output in each iteration) for each + scan_output. If this attribute is omitted, the scan_output_element is + appended to the scan_output in each iteration. + + The optional attribute scan_input_axes specifies the axis to be scanned + for each scan_input. If omitted, every scan_input will be scanned in + axis 0. For example, if axis 0 is the batch axis and axis 1 is the time + axis (to be scanned), specify an axis value of 1. Note that scanning a + non-zero axis may be less efficient than scanning axis zero. + + The optional attribute scan_output_axes specifies the axis along which + the scan_outputs are accumulated for each scan_output. For example, if + axis 1 is the time axis (to be scanned) for both inputs and outputs, + specify a scan_input axis and scan_output axis value of 1. + + Note that because of the ONNX restriction that only the last parameter + of an operator can be variadic, the initial-states and scan-inputs are + listed together as one input parameter. Similarly, the final-states and + scan-outputs are listed together as one output parameter. The attribute + num_scan_inputs indicates the number M of scan-inputs. + + The behavior of + + :: + + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) + + is equivalent to the following pseudo-code: + + :: + + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + + *Sample usage: Encoding RNN using a Scan* + + The following example shows how a simple RNN over an input tensor %X, + with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi + and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. + Note that the loop-body is a nested graph, and it directly computes %Wi, + %Ri, %Wbi, and %Rbi (typically constants or initializers in the body + graph). If these values are computed in the outer graph, they need to be + passed in as extra state_variables. + + :: + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + + Parameters + ========== + initial_state_and_scan_inputs + Type V. + Initial values of the loop's N state variables followed by M scan_inputs + body + Attribute. + The graph run each iteration. It has N+M inputs: (loop state + variables..., scan_input_elts...). It has N+K outputs: (loop state + variables..., scan_output_elts...). Each scan_output is created by + concatenating the value of the specified scan_output_elt value at the + end of each iteration of the loop. It is an error if the dimensions of + these values change across loop iterations. + num_scan_inputs + Attribute. + An attribute specifying the number of scan_inputs M. + scan_input_axes + Attribute. + An optional list of M flags. The i-th element of the list specifies the + axis to be scanned (the sequence axis) for the i-th scan_input. If + omitted, 0 will be used as the scan axis for every scan_input. Negative + value for an axis means counting dimensions from the back. Accepted + range is [-r, r-1] where r = rank(input). + scan_input_directions + Attribute. + An optional list of M flags. The i-th element of the list specifies the + direction to be scanned for the i-th scan_input tensor: 0 indicates + forward direction and 1 indicates reverse direction. If omitted, all + scan_input tensors will be scanned in the forward direction. + scan_output_axes + Attribute. + An optional list of K flags. The i-th element of the list specifies the + axis for the i-th scan_output. The scan outputs are accumulated along + the specified axis. If omitted, 0 will be used as the scan axis for + every scan_output. Negative value for an axis means counting dimensions + from the back. Accepted range is [-r, r-1]. + scan_output_directions + Attribute. + An optional list of K flags, one for each scan_output. The i-th element + of the list specifies whether the i-th scan_output should be constructed + by appending or prepending a new value in each iteration: 0 indicates + appending and 1 indicates prepending. If omitted, all scan_output + tensors will be produced by appending a value in each iteration. + + Returns + ======= + final_state_and_scan_outputs : Sequence[Var] + Type V. + Final values of the loop's N state variables followed by K scan_outputs + + Notes + ===== + Signature: ``ai.onnx@16::Scan``. + + Type constraints: + - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + _body_subgraph: Graph = subgraph( + [ + Tensor( + var.unwrap_tensor().dtype, + (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape), + ) + for var in initial_state_and_scan_inputs[:num_scan_inputs] + ] + + [ + Tensor(var.unwrap_tensor().dtype) + for var in initial_state_and_scan_inputs[num_scan_inputs:] + ], + body, + ) + return ( + _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe( + scan_input_axes, name="scan_input_axes" + ), + scan_input_directions=AttrInt64s.maybe( + scan_input_directions, name="scan_input_directions" + ), + scan_output_axes=AttrInt64s.maybe( + scan_output_axes, name="scan_output_axes" + ), + scan_output_directions=AttrInt64s.maybe( + scan_output_directions, name="scan_output_directions" + ), + ), + _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars( + initial_state_and_scan_inputs + ), + ), + out_variadic=len(_body_subgraph.requested_results), + ) + .get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + ) + .final_state_and_scan_outputs + ) + + +def scatter_elements( + data: Var, + indices: Var, + updates: Var, + *, + axis: int = 0, + reduction: str = "none", +) -> Var: + r""" + ScatterElements takes three inputs ``data``, ``updates``, and + ``indices`` of the same rank r >= 1 and an optional attribute axis that + identifies an axis of ``data`` (by default, the outer-most axis, that is + axis 0). The output of the operation is produced by creating a copy of + the input ``data``, and then updating its value to values specified by + ``updates`` at specific index positions specified by ``indices``. Its + output shape is the same as the shape of ``data``. For each entry in + ``updates``, the target index in ``data`` is obtained by combining the + corresponding entry in ``indices`` with the index of the entry itself: + the index-value for dimension = axis is obtained from the value of the + corresponding entry in ``indices`` and the index-value for dimension != + axis is obtained from the index of the entry itself. ``reduction`` + allows specification of an optional reduction operation, which is + applied to all values in ``updates`` tensor into ``output`` at the + specified ``indices``. In cases where ``reduction`` is set to "none", + indices should not have duplicate entries: that is, if idx1 != idx2, + then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, + the update corresponding to the [i][j] entry is performed as below: + + :: + + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + + When ``reduction`` is set to "add", the update corresponding to the + [i][j] entry is performed as below: + + :: + + output[indices[i][j]][j] += updates[i][j] if axis = 0, + output[i][indices[i][j]] += updates[i][j] if axis = 1, + + When ``reduction`` is set to "mul", the update corresponding to the + [i][j] entry is performed as below: + + :: + + output[indices[i][j]][j] *= updates[i][j] if axis = 0, + output[i][indices[i][j]] *= updates[i][j] if axis = 1, + + This operator is the inverse of GatherElements. It is similar to Torch's + Scatter operation. Example 1: + + :: + + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + + Example 2: + + :: + + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + + Parameters + ========== + data + Type T. + Tensor of rank r >= 1. + indices + Type Tind. + Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index + values are expected to be within bounds [-s, s-1] along axis of size s. + It is an error if any of the index values are out of bounds. + updates + Type T. + Tensor of rank r >=1 (same rank and shape as indices) + axis + Attribute. + Which axis to scatter on. Negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(data). + reduction + Attribute. + Type of reduction to apply: none (default), add, mul. 'none': no + reduction applied. 'add': reduction using the addition operation. 'mul': + reduction using the multiplication operation. + + Returns + ======= + output : Var + Type T. + Tensor of rank r >= 1 (same rank as input). + + Notes + ===== + Signature: ``ai.onnx@16::ScatterElements``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return ( + _ScatterElements( + _ScatterElements.Attributes( + axis=AttrInt64(axis, name="axis"), + reduction=AttrString(reduction, name="reduction"), + ), + _ScatterElements.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), + ) + .output + ) + + +def scatter_nd( + data: Var, + indices: Var, + updates: Var, + *, + reduction: str = "none", +) -> Var: + r""" + ScatterND takes three inputs ``data`` tensor of rank r >= 1, ``indices`` + tensor of rank q >= 1, and ``updates`` tensor of rank q + r - + indices.shape[-1] - 1. The output of the operation is produced by + creating a copy of the input ``data``, and then updating its value to + values specified by ``updates`` at specific index positions specified by + ``indices``. Its output shape is the same as the shape of ``data``. + + ``indices`` is an integer tensor. Let k denote indices.shape[-1], the + last dimension in the shape of ``indices``. ``indices`` is treated as a + (q-1)-dimensional tensor of k-tuples, where each k-tuple is a + partial-index into ``data``. Hence, k can be a value at most the rank of + ``data``. When k equals rank(data), each update entry specifies an + update to a single element of the tensor. When k is less than rank(data) + each update entry specifies an update to a slice of the tensor. Index + values are allowed to be negative, as per the usual convention for + counting backwards from the end, but are expected in the valid range. + + ``updates`` is treated as a (q-1)-dimensional tensor of + replacement-slice-values. Thus, the first (q-1) dimensions of + updates.shape must match the first (q-1) dimensions of indices.shape. + The remaining dimensions of ``updates`` correspond to the dimensions of + the replacement-slice-values. Each replacement-slice-value is a (r-k) + dimensional tensor, corresponding to the trailing (r-k) dimensions of + ``data``. Thus, the shape of ``updates`` must equal indices.shape[0:q-1] + ++ data.shape[k:r-1], where ++ denotes the concatenation of shapes. + + The ``output`` is calculated via the following equation: output = + np.copy(data) update_indices = indices.shape[:-1] for idx in + np.ndindex(update_indices): output[indices[idx]] = updates[idx] The + order of iteration in the above loop is not specified. In particular, + indices should not have duplicate entries: that is, if idx1 != idx2, + then indices[idx1] != indices[idx2]. This ensures that the output value + does not depend on the iteration order. + + ``reduction`` allows specification of an optional reduction operation, + which is applied to all values in ``updates`` tensor into ``output`` at + the specified ``indices``. In cases where ``reduction`` is set to + "none", indices should not have duplicate entries: that is, if idx1 != + idx2, then indices[idx1] != indices[idx2]. This ensures that the output + value does not depend on the iteration order. When ``reduction`` is set + to "add", ``output`` is calculated as follows: output = np.copy(data) + update_indices = indices.shape[:-1] for idx in + np.ndindex(update_indices): output[indices[idx]] += updates[idx] When + ``reduction`` is set to "mul", ``output`` is calculated as follows: + output = np.copy(data) update_indices = indices.shape[:-1] for idx in + np.ndindex(update_indices): output[indices[idx]] \*= updates[idx] This + operator is the inverse of GatherND. Example 1: + + :: + + data = [1, 2, 3, 4, 5, 6, 7, 8] + indices = [[4], [3], [1], [7]] + updates = [9, 10, 11, 12] + output = [1, 11, 3, 10, 9, 6, 7, 12] + + Example 2: + + :: + + data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + indices = [[0], [2]] + updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] + output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + + Parameters + ========== + data + Type T. + Tensor of rank r >= 1. + indices + Type tensor(int64). + Tensor of rank q >= 1. + updates + Type T. + Tensor of rank q + r - indices_shape[-1] - 1. + reduction + Attribute. + Type of reduction to apply: none (default), add, mul. 'none': no + reduction applied. 'add': reduction using the addition operation. 'mul': + reduction using the multiplication operation. + + Returns + ======= + output : Var + Type T. + Tensor of rank r >= 1. + + Notes + ===== + Signature: ``ai.onnx@16::ScatterND``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _ScatterND( + _ScatterND.Attributes( + reduction=AttrString(reduction, name="reduction"), + ), + _ScatterND.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), + ) + .output + ) + + +def selu( + X: Var, + *, + alpha: float = 1.6732631921768188, + gamma: float = 1.0507010221481323, +) -> Var: + r""" + Selu takes one input data (Tensor) and produces one output data + (Tensor) where the scaled exponential linear unit function, + ``y = gamma * (alpha * e^x - alpha) for x <= 0``, + ``y = gamma * x for x > 0``, is applied to the tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + alpha + Attribute. + Coefficient of SELU default to 1.67326319217681884765625 (i.e., float32 + approximation of 1.6732632423543772848170429916717). + gamma + Attribute. + Coefficient of SELU default to 1.05070102214813232421875 (i.e., float32 + approximation of 1.0507009873554804934193349852946). + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@6::Selu``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Selu( + _Selu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + gamma=AttrFloat32(gamma, name="gamma"), + ), + _Selu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def sequence_at( + input_sequence: Var, + position: Var, +) -> Var: + r""" + Outputs a tensor copy from the tensor at 'position' in 'input_sequence'. + Accepted range for 'position' is in ``[-n, n - 1]``, where ``n`` is the + number of tensors in 'input_sequence'. Negative value means counting + positions from the back. + + Parameters + ========== + input_sequence + Type S. + Input sequence. + position + Type I. + Position of the tensor in the sequence. Negative value means counting + positions from the back. Accepted range in ``[-n, n - 1]``, where ``n`` + is the number of tensors in 'input_sequence'. It is an error if any of + the index values are out of bounds. It must be a scalar(tensor of empty + shape). + + Returns + ======= + tensor : Var + Type T. + Output tensor at the specified position in the input sequence. + + Notes + ===== + Signature: ``ai.onnx@11::SequenceAt``. + + Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - I: `tensor(int32)`, `tensor(int64)` + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _SequenceAt( + _SequenceAt.Attributes(), + _SequenceAt.Inputs( + input_sequence=unwrap_vars(input_sequence), + position=unwrap_vars(position), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + position=get_value(position), + ) + .tensor + ) + + +def sequence_construct( + inputs: Sequence[Var], +) -> Var: + r""" + Construct a tensor sequence containing 'inputs' tensors. All tensors in + 'inputs' must have the same data type. + + Parameters + ========== + inputs + Type T. + Tensors. + + Returns + ======= + output_sequence : Var + Type S. + Sequence enclosing the input tensors. + + Notes + ===== + Signature: ``ai.onnx@11::SequenceConstruct``. + + Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + """ + return ( + _SequenceConstruct( + _SequenceConstruct.Attributes(), + _SequenceConstruct.Inputs( + inputs=unwrap_vars(inputs), + ), + ) + .get_output_vars( + inputs=get_value(inputs), + ) + .output_sequence + ) + + +def sequence_empty( + *, + dtype: Optional[npt.DTypeLike] = None, +) -> Var: + r""" + Construct an empty tensor sequence, with given data type. + + Parameters + ========== + dtype + Attribute. + (Optional) The data type of the tensors in the output sequence. The + default type is 'float'. + + Returns + ======= + output : Var + Type S. + Empty sequence. + + Notes + ===== + Signature: ``ai.onnx@11::SequenceEmpty``. + + Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + """ + return ( + _SequenceEmpty( + _SequenceEmpty.Attributes( + dtype=AttrDtype.maybe(dtype, name="dtype"), + ), + _SequenceEmpty.Inputs(), + ) + .get_output_vars() + .output + ) + + +def sequence_erase( + input_sequence: Var, + position: Optional[Var] = None, +) -> Var: + r""" + Outputs a tensor sequence that removes the tensor at 'position' from + 'input_sequence'. Accepted range for 'position' is in ``[-n, n - 1]``, + where ``n`` is the number of tensors in 'input_sequence'. Negative value + means counting positions from the back. 'position' is optional, by + default it erases the last tensor from 'input_sequence'. + + Parameters + ========== + input_sequence + Type S. + Input sequence. + position + Type I. + Position of the tensor in the sequence. Negative value means counting + positions from the back. Accepted range in ``[-n, n - 1]``, where ``n`` + is the number of tensors in 'input_sequence'. It is an error if any of + the index values are out of bounds. It must be a scalar(tensor of empty + shape). + + Returns + ======= + output_sequence : Var + Type S. + Output sequence that has the tensor at the specified position removed. + + Notes + ===== + Signature: ``ai.onnx@11::SequenceErase``. + + Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - I: `tensor(int32)`, `tensor(int64)` + """ + return ( + _SequenceErase( + _SequenceErase.Attributes(), + _SequenceErase.Inputs( + input_sequence=unwrap_vars(input_sequence), + position=unwrap_vars(position), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + position=get_value(position), + ) + .output_sequence + ) + + +def sequence_insert( + input_sequence: Var, + tensor: Var, + position: Optional[Var] = None, +) -> Var: + r""" + Outputs a tensor sequence that inserts 'tensor' into 'input_sequence' at + 'position'. 'tensor' must have the same data type as 'input_sequence'. + Accepted range for 'position' is in ``[-n, n]``, where ``n`` is the + number of tensors in 'input_sequence'. Negative value means counting + positions from the back. 'position' is optional, by default it inserts + 'tensor' to the back of 'input_sequence'. + + Parameters + ========== + input_sequence + Type S. + Input sequence. + tensor + Type T. + Input tensor to be inserted into the input sequence. + position + Type I. + Position in the sequence where the new tensor is inserted. It is + optional and default is to insert to the back of the sequence. Negative + value means counting positions from the back. Accepted range in + ``[-n, n]``, where ``n`` is the number of tensors in 'input_sequence'. + It is an error if any of the index values are out of bounds. It must be + a scalar(tensor of empty shape). + + Returns + ======= + output_sequence : Var + Type S. + Output sequence that contains the inserted tensor at given position. + + Notes + ===== + Signature: ``ai.onnx@11::SequenceInsert``. + + Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - I: `tensor(int32)`, `tensor(int64)` + """ + return ( + _SequenceInsert( + _SequenceInsert.Attributes(), + _SequenceInsert.Inputs( + input_sequence=unwrap_vars(input_sequence), + tensor=unwrap_vars(tensor), + position=unwrap_vars(position), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + tensor=get_value(tensor), + position=get_value(position), + ) + .output_sequence + ) + + +def sequence_length( + input_sequence: Var, +) -> Var: + r""" + Produces a scalar(tensor of empty shape) containing the number of + tensors in 'input_sequence'. + + Parameters + ========== + input_sequence + Type S. + Input sequence. + + Returns + ======= + length : Var + Type I. + Length of input sequence. It must be a scalar(tensor of empty shape). + + Notes + ===== + Signature: ``ai.onnx@11::SequenceLength``. + + Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - I: `tensor(int64)` + """ + return ( + _SequenceLength( + _SequenceLength.Attributes(), + _SequenceLength.Inputs( + input_sequence=unwrap_vars(input_sequence), + ), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + ) + .length + ) + + +def sequence_map( + input_sequence: Var, + additional_inputs: Sequence[Var] = (), + *, + body: Callable[..., Iterable[Var]], +) -> Sequence[Var]: + r""" + Applies a sub-graph to each sample in the input sequence(s). + + Inputs can be either tensors or sequences, with the exception of the + first input which must be a sequence. The length of the first input + sequence will determine the number of samples in the outputs. Any other + sequence inputs should have the same number of samples. The number of + inputs and outputs, should match the one of the subgraph. + + For each i-th element in the output, a sample will be extracted from the + input sequence(s) at the i-th position and the sub-graph will be applied + to it. The outputs will contain the outputs of the sub-graph for each + sample, in the same order as in the input. + + This operator assumes that processing each sample is independent and + could executed in parallel or in any order. Users cannot expect any + specific ordering in which each subgraph is computed. + + Parameters + ========== + input_sequence + Type S. + Input sequence. + additional_inputs + Type V. + Additional inputs to the graph + body + Attribute. + The graph to be run for each sample in the sequence(s). It should have + as many inputs and outputs as inputs and outputs to the SequenceMap + function. + + Returns + ======= + out_sequence : Sequence[Var] + Type S. + Output sequence(s) + + Notes + ===== + Signature: ``ai.onnx@17::SequenceMap``. + + Type constraints: + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + _body_subgraph: Graph = subgraph( + [typing_cast(SpoxSequence, input_sequence.unwrap_type()).elem_type] + + [ + typing_cast(SpoxSequence, var.unwrap_type()).elem_type + for var in additional_inputs + ], + body, + ) + return ( + _SequenceMap( + _SequenceMap.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), + _SequenceMap.Inputs( + input_sequence=unwrap_vars(input_sequence), + additional_inputs=unwrap_vars(additional_inputs), + ), + out_variadic=len(_body_subgraph.requested_results), + ) + .get_output_vars( + input_sequence=get_value(input_sequence), + additional_inputs=get_value(additional_inputs), + ) + .out_sequence + ) + + +def shape( + data: Var, + *, + end: Optional[int] = None, + start: int = 0, +) -> Var: + r""" + Takes a tensor as input and outputs an 1D int64 tensor containing the + shape of the input tensor. Optional attributes start and end can be used + to compute a slice of the input tensor's shape. If start axis is + omitted, the slice starts from axis 0. The end axis, if specified, is + exclusive (and the returned value will not include the size of that + axis). If the end axis is omitted, the axes upto the last one will be + included. Negative axes indicate counting back from the last axis. Note + that axes will be clamped to the range [0, r-1], where r is the rank of + the input tensor if they are out-of-range (after adding r in the case of + negative axis). Thus, specifying any end value > r is equivalent to + specifying an end value of r, and specifying any start value < -r is + equivalent to specifying a start value of 0. + + Examples: + + :: + + Input tensor with shape: [2, 3, 4] + No attributes specified. + Output: [2, 3, 4] + + :: + + Input tensor with shape: [2, 3, 4] + start: -1 + Output: [4] + + :: + + Input tensor with shape: [2, 3, 4] + end: -1 + Output: [2, 3] + + :: + + Input tensor with shape: [2, 3, 4] + start: 1 + end: 2 + Output: [3] + + Parameters + ========== + data + Type T. + An input tensor. + end + Attribute. + (Optional) Ending axis for slicing the shape. Negative value means + counting dimensions from the back. If omitted, sizes of all axes upto + (including) the last one will be included. + start + Attribute. + (Optional) Starting axis for slicing the shape. Default value is + 0.Negative value means counting dimensions from the back. + + Returns + ======= + shape : Var + Type T1. + Shape of the input tensor + + Notes + ===== + Signature: ``ai.onnx@15::Shape``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` + """ + return ( + _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), + _Shape.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .shape + ) + + +def shrink( + input: Var, + *, + bias: float = 0.0, + lambd: float = 0.5, +) -> Var: + r""" + Shrink takes one input data (Tensor) and produces one Tensor output, + having same datatype and shape with input. It has two attributes, lambd + and bias. The formula of this operator is: If x < -lambd, y = x + bias; + If x > lambd, y = x - bias; Otherwise, y = 0. + + Parameters + ========== + input + Type T. + The input data as Tensor. + bias + Attribute. + The bias value added to output. Default is 0. + lambd + Attribute. + The lambd value for the Shrink formulation. Default is 0.5. + + Returns + ======= + output : Var + Type T. + The output. + + Notes + ===== + Signature: ``ai.onnx@9::Shrink``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Shrink( + _Shrink.Attributes( + bias=AttrFloat32(bias, name="bias"), + lambd=AttrFloat32(lambd, name="lambd"), + ), + _Shrink.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def sigmoid( + X: Var, +) -> Var: + r""" + Sigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is + applied to the tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::Sigmoid``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Sigmoid( + _Sigmoid.Attributes(), + _Sigmoid.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def sign( + input: Var, +) -> Var: + r""" + Calculate the sign of the given input tensor element-wise. If input > 0, + output 1. if input < 0, output -1. if input == 0, output 0. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The sign of the input tensor computed element-wise. It has the same + shape and type of the input. + + Notes + ===== + Signature: ``ai.onnx@13::Sign``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Sign( + _Sign.Attributes(), + _Sign.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def sin( + input: Var, +) -> Var: + r""" + Calculates the sine of the given input tensor, element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The sine of the input tensor computed element-wise + + Notes + ===== + Signature: ``ai.onnx@7::Sin``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Sin( + _Sin.Attributes(), + _Sin.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def sinh( + input: Var, +) -> Var: + r""" + Calculates the hyperbolic sine of the given input tensor element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The hyperbolic sine values of the input tensor computed element-wise + + Notes + ===== + Signature: ``ai.onnx@9::Sinh``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Sinh( + _Sinh.Attributes(), + _Sinh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def size( + data: Var, +) -> Var: + r""" + Takes a tensor as input and outputs a int64 scalar that equals to the + total number of elements of the input tensor. + + Parameters + ========== + data + Type T. + An input tensor. + + Returns + ======= + size : Var + Type T1. + Total number of elements of the input tensor + + Notes + ===== + Signature: ``ai.onnx@13::Size``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` + """ + return ( + _Size( + _Size.Attributes(), + _Size.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .size + ) + + +def slice( + data: Var, + starts: Var, + ends: Var, + axes: Optional[Var] = None, + steps: Optional[Var] = None, +) -> Var: + r""" + Produces a slice of the input tensor along multiple axes. Similar to + numpy: + https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding + + Slice uses the ``starts``, ``ends``, ``axes`` and ``steps`` inputs to + select a sub-tensor of its input ``data`` tensor. + + An effective ``starts[i]``, ``ends[i]``, and ``steps[i]`` must be + computed for each ``i`` in ``[0, ... r-1]`` where ``r = rank(input)`` as + follows: + + If ``axes`` are omitted, they are set to ``[0, ..., r-1]``. If ``steps`` + are omitted, they are set to ``[1, ..., 1]`` of length ``len(starts)`` + + The effective values are initialized as ``start[i] = 0``, + ``ends[i] = dims[i]`` where ``dims`` are the dimensions of ``input`` and + ``steps[i] = 1``. + + All negative elements of ``axes`` are made non-negative by adding ``r`` + to them, where ``r =rank(input)``. + + All negative values in ``starts[i]`` and ``ends[i]`` have + ``dims[axes[i]]`` added to them, where ``dims`` are the dimensions of + ``input``. Then ``start[axes[i]]`` is the adjusted ``starts[i]`` is + clamped into the range ``[0, dims[axes[i]]]`` for positive stepping and + ``[0, dims[axes[i]]-1]`` for negative stepping. + + The clamping for the adjusted ``ends[i]`` depends on the sign of + ``steps[i]`` and must accommodate copying 0 through ``dims[axes[i]]`` + elements, so for positive stepping ``ends[axes[i]]`` is clamped to + ``[0, dims[axes[i]]]``, while for negative stepping it is clamped to + ``[-1, dims[axes[i]]-1]``. + + Finally, ``steps[axes[i]] = steps[i]``. + + For slicing to the end of a dimension with unknown size, it is + recommended to pass in ``INT_MAX`` when slicing forward and 'INT_MIN' + when slicing backward. + + Example 1: + + :: + + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + axes = [0, 1] + starts = [1, 0] + ends = [2, 3] + steps = [1, 2] + result = [ + [5, 7], + ] + + Example 2: + + :: + + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + starts = [0, 1] + ends = [-1, 1000] + result = [ + [2, 3, 4], + ] + + Parameters + ========== + data + Type T. + Tensor of data to extract slices from. + starts + Type Tind. + 1-D tensor of starting indices of corresponding axis in ``axes`` + ends + Type Tind. + 1-D tensor of ending indices (exclusive) of corresponding axis in + ``axes`` + axes + Type Tind. + 1-D tensor of axes that ``starts`` and ``ends`` apply to. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(data). Behavior is undefined if an axis is repeated. + steps + Type Tind. + 1-D tensor of slice step of corresponding axis in ``axes``. Negative + value means slicing backward. 'steps' cannot be 0. Defaults to 1s. + + Returns + ======= + output : Var + Type T. + Sliced data tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Slice``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return ( + _Slice( + _Slice.Attributes(), + _Slice.Inputs( + data=unwrap_vars(data), + starts=unwrap_vars(starts), + ends=unwrap_vars(ends), + axes=unwrap_vars(axes), + steps=unwrap_vars(steps), + ), + ) + .get_output_vars( + data=get_value(data), + starts=get_value(starts), + ends=get_value(ends), + axes=get_value(axes), + steps=get_value(steps), + ) + .output + ) + + +def softmax( + input: Var, + *, + axis: int = -1, +) -> Var: + r""" + The operator computes the normalized exponential values for the given + input: + + Softmax(input, axis) = Exp(input) / ReduceSum(Exp(input), axis=axis, + keepdims=1) + + The "axis" attribute indicates the dimension along which Softmax will be + performed. The output tensor has the same shape and contains the Softmax + values of the corresponding input. + + Parameters + ========== + input + Type T. + The input tensor of rank >= axis. + axis + Attribute. + Describes the dimension Softmax will be performed on. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(input). + + Returns + ======= + output : Var + Type T. + The output values with the same shape as the input tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Softmax``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Softmax( + _Softmax.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Softmax.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def softmax_cross_entropy_loss( + scores: Var, + labels: Var, + weights: Optional[Var] = None, + *, + ignore_index: Optional[int] = None, + reduction: str = "mean", +) -> tuple[Var, Var]: + r""" + Loss function that measures the softmax cross entropy between 'scores' + and 'labels'. This operator first computes a loss tensor whose shape is + identical to the labels input. If the input is 2-D with shape (N, C), + the loss tensor may be a N-element vector L = (l_1, l_2, ..., l_N). If + the input is N-D tensor with shape (N, C, D1, D2, ..., Dk), the loss + tensor L may have (N, D1, D2, ..., Dk) as its shape and + L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. After L is + available, this operator can optionally do a reduction operator. + + - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, + D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, + D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. + + The loss for one sample, l_i, can calculated as follows: + + :: + + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes. + + or + + :: + + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided. + + loss is zero for the case when label-value equals ignore_index. + + :: + + l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index + + where: + + :: + + p = Softmax(scores) + y = Log(p) + c = labels[i][d1][d2]...[dk] + + Finally, L is optionally reduced: + + - If reduction = 'none', the output is L with shape (N, D1, D2, ..., + Dk). + - If reduction = 'sum', the output is scalar: Sum(L). + - If reduction = 'mean', the output is scalar: ReduceMean(L), or if + weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W + is of shape ``(N, D1, D2, ..., Dk)`` and + ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. + + Parameters + ========== + scores + Type T. + The predicted outputs with shape [batch_size, class_size], or + [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of + dimensions. + labels + Type Tind. + The ground truth output tensor, with shape [batch_size], or [batch_size, + D1, D2, ..., Dk], where K is the number of dimensions. Labels element + value shall be in range of [0, C). If ignore_index is specified, it may + have a value outside [0, C) and the label values should either be in the + range [0, C) or have the value ignore_index. + weights + Type T. + A manual rescaling weight given to each class. If given, it has to be a + 1D Tensor assigning weight to each of the classes. Otherwise, it is + treated as if having all ones. + ignore_index + Attribute. + Specifies a target value that is ignored and does not contribute to the + input gradient. It's an optional value. + reduction + Attribute. + Type of reduction to apply to loss: none, sum, mean(default). 'none': no + reduction will be applied, 'sum': the output will be summed. 'mean': the + sum of the output will be divided by the number of elements in the + output. + + Returns + ======= + output : Var + Type T. + Weighted loss float Tensor. If reduction is 'none', this has the shape + of [batch_size], or [batch_size, D1, D2, ..., Dk] in case of + K-dimensional loss. Otherwise, it is a scalar. + log_prob : Var + Type T. + Log probability tensor. If the output of softmax is prob, its value is + log(prob). + + Notes + ===== + Signature: ``ai.onnx@13::SoftmaxCrossEntropyLoss``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - Tind: `tensor(int32)`, `tensor(int64)` + """ + return ( + _SoftmaxCrossEntropyLoss( + _SoftmaxCrossEntropyLoss.Attributes( + ignore_index=AttrInt64.maybe(ignore_index, name="ignore_index"), + reduction=AttrString(reduction, name="reduction"), + ), + _SoftmaxCrossEntropyLoss.Inputs( + scores=unwrap_vars(scores), + labels=unwrap_vars(labels), + weights=unwrap_vars(weights), + ), + ) + .get_output_vars( + scores=get_value(scores), + labels=get_value(labels), + weights=get_value(weights), + ) + ._unpack_to_any() + ) + + +def softplus( + X: Var, +) -> Var: + r""" + Softplus takes one input data (Tensor) and produces one output data + (Tensor) where the softplus function, y = ln(exp(x) + 1), is applied + to the tensor elementwise. + + Parameters + ========== + X + Type T. + 1D input tensor + + Returns + ======= + Y : Var + Type T. + 1D input tensor + + Notes + ===== + Signature: ``ai.onnx@1::Softplus``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Softplus( + _Softplus.Attributes(), + _Softplus.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def softsign( + input: Var, +) -> Var: + r""" + Calculates the softsign (x/(1+|x\|)) of the given input tensor + element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The softsign (x/(1+|x\|)) values of the input tensor computed + element-wise + + Notes + ===== + Signature: ``ai.onnx@1::Softsign``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Softsign( + _Softsign.Attributes(), + _Softsign.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def space_to_depth( + input: Var, + *, + blocksize: int, +) -> Var: + r""" + SpaceToDepth rearranges blocks of spatial data into depth. More + specifically, this op outputs a copy of the input tensor where values + from the height and width dimensions are moved to the depth dimension. + + Parameters + ========== + input + Type T. + Input tensor of [N,C,H,W], where N is the batch axis, C is the channel + or depth, H is the height and W is the width. + blocksize + Attribute. + Blocks of [blocksize, blocksize] are moved. + + Returns + ======= + output : Var + Type T. + Output tensor of [N, C \* blocksize \* blocksize, H/blocksize, + W/blocksize]. + + Notes + ===== + Signature: ``ai.onnx@13::SpaceToDepth``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _SpaceToDepth( + _SpaceToDepth.Attributes( + blocksize=AttrInt64(blocksize, name="blocksize"), + ), + _SpaceToDepth.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def split( + input: Var, + split: Optional[Var] = None, + *, + outputs_count: int, + axis: int = 0, +) -> Sequence[Var]: + r""" + Split a tensor into a list of tensors, along the specified 'axis'. + Lengths of the parts can be specified using input 'split'. Otherwise, + the tensor is split to equal sized parts. + + Parameters + ========== + input + Type T. + The tensor to split + split + Type tensor(int64). + Optional length of each output. Values should be >= 0.Sum of the values + must be equal to the dim value at 'axis' specified. + axis + Attribute. + Which axis to split on. A negative value means counting dimensions from + the back. Accepted range is [-rank, rank-1] where r = rank(input). + outputs_count + Specifies the number of variadic outputs of this operator. + Non-standard parameter created by the opset generator, as inference (a solution) it was not implemented or is impossible. + + Returns + ======= + outputs : Sequence[Var] + Type T. + One or more outputs forming list of tensors after splitting + + Notes + ===== + Signature: ``ai.onnx@13::Split``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Split( + _Split.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Split.Inputs( + input=unwrap_vars(input), + split=unwrap_vars(split), + ), + out_variadic=outputs_count, + ) + .get_output_vars( + input=get_value(input), + split=get_value(split), + ) + .outputs + ) + + +def split_to_sequence( + input: Var, + split: Optional[Var] = None, + *, + axis: int = 0, + keepdims: int = 1, +) -> Var: + r""" + Split a tensor into a sequence of tensors, along the specified 'axis'. + Lengths of the parts can be specified using the optional argument + 'split'. If the argument + ``split' is not specified, a default scalar value of 1 is used as the value of``\ split'. + 'split' must contain only positive numbers. 'split' is either a scalar + (tensor of empty shape), or a 1-D tensor. If 'split' is a scalar, then + 'input' will be split into chunks all of size 'split' if possible. The + last chunk alone may be smaller than 'split' if the 'input' size along + the given axis 'axis' is not divisible by 'split'. If 'split' is a + 1-dimensional tensor, the input tensor is split into 'size(split)' + chunks, with lengths of the parts on 'axis' specified in 'split'. In + this scenario, the sum of entries in 'split' must be equal to the + dimension size of input tensor on 'axis'. + + Parameters + ========== + input + Type T. + The tensor to split + split + Type I. + Length of each output. It can be either a scalar(tensor of empty shape), + or a 1-D tensor. All values must be >= 0. + axis + Attribute. + Which axis to split on. A negative value means counting dimensions from + the back. Accepted range is [-rank, rank-1]. + keepdims + Attribute. + Keep the split dimension or not. Default 1, which means we keep split + dimension. If input 'split' is specified, this attribute is ignored. + + Returns + ======= + output_sequence : Var + Type S. + One or more outputs forming a sequence of tensors after splitting + + Notes + ===== + Signature: ``ai.onnx@11::SplitToSequence``. + + Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - I: `tensor(int32)`, `tensor(int64)` + - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` + """ + return ( + _SplitToSequence( + _SplitToSequence.Attributes( + axis=AttrInt64(axis, name="axis"), + keepdims=AttrInt64(keepdims, name="keepdims"), + ), + _SplitToSequence.Inputs( + input=unwrap_vars(input), + split=unwrap_vars(split), + ), + ) + .get_output_vars( + input=get_value(input), + split=get_value(split), + ) + .output_sequence + ) + + +def sqrt( + X: Var, +) -> Var: + r""" + Square root takes one input data (Tensor) and produces one output + data (Tensor) where the square root is, y = x^0.5, is applied to the + tensor elementwise. If x is negative, then it will return NaN. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@13::Sqrt``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Sqrt( + _Sqrt.Attributes(), + _Sqrt.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def squeeze( + data: Var, + axes: Optional[Var] = None, +) -> Var: + r""" + Remove single-dimensional entries from the shape of a tensor. Takes an + input ``axes`` with a list of axes to squeeze. If ``axes`` is not + provided, all the single dimensions will be removed from the shape. If + an axis is selected with shape entry not equal to one, an error is + raised. + + Parameters + ========== + data + Type T. + Tensors with at least max(dims) dimensions. + axes + Type tensor(int64). + List of integers indicating the dimensions to squeeze. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(data). + + Returns + ======= + squeezed : Var + Type T. + Reshaped tensor with same data as input. + + Notes + ===== + Signature: ``ai.onnx@13::Squeeze``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Squeeze( + _Squeeze.Attributes(), + _Squeeze.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .squeezed + ) + + +def string_normalizer( + X: Var, + *, + case_change_action: str = "NONE", + is_case_sensitive: int = 0, + locale: Optional[str] = None, + stopwords: Optional[Iterable[str]] = None, +) -> Var: + r""" + StringNormalization performs string operations for basic cleaning. This + operator has only one input (denoted by X) and only one output (denoted + by Y). This operator first examines the elements in the X, and removes + elements specified in "stopwords" attribute. After removing stop words, + the intermediate result can be further lowercased, uppercased, or just + returned depending the "case_change_action" attribute. This operator + only accepts [C]- and [1, C]-tensor. If all elements in X are dropped, + the output will be the empty value of string tensor with shape [1] if + input shape is [C] and shape [1, 1] if input shape is [1, C]. + + Parameters + ========== + X + Type tensor(string). + UTF-8 strings to normalize + case_change_action + Attribute. + string enum that cases output to be lowercased/uppercases/unchanged. + Valid values are "LOWER", "UPPER", "NONE". Default is "NONE" + is_case_sensitive + Attribute. + Boolean. Whether the identification of stop words in X is + case-sensitive. Default is false + locale + Attribute. + Environment dependent string that denotes the locale according to which + output strings needs to be upper/lowercased.Default en_US or platform + specific equivalent as decided by the implementation. + stopwords + Attribute. + List of stop words. If not set, no word would be removed from X. + + Returns + ======= + Y : Var + Type tensor(string). + UTF-8 Normalized strings + + Notes + ===== + Signature: ``ai.onnx@10::StringNormalizer``. + + """ + return ( + _StringNormalizer( + _StringNormalizer.Attributes( + case_change_action=AttrString( + case_change_action, name="case_change_action" + ), + is_case_sensitive=AttrInt64( + is_case_sensitive, name="is_case_sensitive" + ), + locale=AttrString.maybe(locale, name="locale"), + stopwords=AttrStrings.maybe(stopwords, name="stopwords"), + ), + _StringNormalizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def sub( + A: Var, + B: Var, +) -> Var: + r""" + Performs element-wise binary subtraction (with Numpy-style broadcasting + support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + (Opset 14 change): Extend supported types to include uint8, int8, + uint16, and int16. + + Parameters + ========== + A + Type T. + First operand. + B + Type T. + Second operand. + + Returns + ======= + C : Var + Type T. + Result, has same element type as two inputs + + Notes + ===== + Signature: ``ai.onnx@14::Sub``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Sub( + _Sub.Attributes(), + _Sub.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def sum( + data_0: Sequence[Var], +) -> Var: + r""" + Element-wise sum of each of the input tensors (with Numpy-style + broadcasting support). All inputs and outputs must have the same data + type. This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + data_0 + Type T. + List of tensors for sum. + + Returns + ======= + sum : Var + Type T. + Output tensor. + + Notes + ===== + Signature: ``ai.onnx@13::Sum``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Sum( + _Sum.Attributes(), + _Sum.Inputs( + data_0=unwrap_vars(data_0), + ), + ) + .get_output_vars( + data_0=get_value(data_0), + ) + .sum + ) + + +def tan( + input: Var, +) -> Var: + r""" + Calculates the tangent of the given input tensor, element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The tangent of the input tensor computed element-wise + + Notes + ===== + Signature: ``ai.onnx@7::Tan``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Tan( + _Tan.Attributes(), + _Tan.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def tanh( + input: Var, +) -> Var: + r""" + Calculates the hyperbolic tangent of the given input tensor + element-wise. + + Parameters + ========== + input + Type T. + Input tensor + + Returns + ======= + output : Var + Type T. + The hyperbolic tangent values of the input tensor computed element-wise + + Notes + ===== + Signature: ``ai.onnx@13::Tanh``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Tanh( + _Tanh.Attributes(), + _Tanh.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def tf_idf_vectorizer( + X: Var, + *, + max_gram_length: int, + max_skip_count: int, + min_gram_length: int, + mode: str, + ngram_counts: Iterable[int], + ngram_indexes: Iterable[int], + pool_int64s: Optional[Iterable[int]] = None, + pool_strings: Optional[Iterable[str]] = None, + weights: Optional[Iterable[float]] = None, +) -> Var: + r""" + This transform extracts n-grams from the input sequence and save them as + a vector. Input can be either a 1-D or 2-D tensor. For 1-D input, output + is the n-gram representation of that input. For 2-D input, the output is + also a 2-D tensor whose i-th row is the n-gram representation of the + i-th input row. More specifically, if input shape is [C], the + corresponding output shape would be [max(ngram_indexes) + 1]. If input + shape is [N, C], this operator produces a [N, max(ngram_indexes) + + 1]-tensor. + + In contrast to standard n-gram extraction, here, the indexes of + extracting an n-gram from the original sequence are not necessarily + consecutive numbers. The discontinuity between indexes are controlled by + the number of skips. If the number of skips is 2, we should skip two + tokens when scanning through the original sequence. Let's consider an + example. Assume that input sequence is [94, 17, 36, 12, 28] and the + number of skips is 2. The associated 2-grams are [94, 12] and [17, 28] + respectively indexed by [0, 3] and [1, 4]. If the number of skips + becomes 0, the 2-grams generated are [94, 17], [17, 36], [36, 12], [12, + 28] indexed by [0, 1], [1, 2], [2, 3], [3, 4], respectively. + + The output vector (denoted by Y) stores the count of each n-gram; + Y[ngram_indexes[i]] indicates the times that the i-th n-gram is found. + The attribute ngram_indexes is used to determine the mapping between + index i and the corresponding n-gram's output coordinate. If pool_int64s + is [94, 17, 17, 36], ngram_indexes is [1, 0], ngram_counts=[0, 0], then + the Y[0] (first element in Y) and Y[1] (second element in Y) are the + counts of [17, 36] and [94, 17], respectively. An n-gram which cannot be + found in pool_strings/pool_int64s should be ignored and has no effect on + the output. Note that we may consider all skips up to S when generating + the n-grams. + + The examples used above are true if mode is "TF". If mode is "IDF", all + the counts larger than 1 would be truncated to 1 and the i-th element in + weights would be used to scale (by multiplication) the count of the i-th + n-gram in pool. If mode is "TFIDF", this operator first computes the + counts of all n-grams and then scale them by the associated values in + the weights attribute. + + Only one of pool_strings and pool_int64s can be set. If pool_int64s is + set, the input should be an integer tensor. If pool_strings is set, the + input must be a string tensor. + + Parameters + ========== + X + Type T. + Input for n-gram extraction + max_gram_length + Attribute. + Maximum n-gram length. If this value is 3, 3-grams will be used to + generate the output. + max_skip_count + Attribute. + Maximum number of items (integers/strings) to be skipped when + constructing an n-gram from X. If max_skip_count=1, min_gram_length=2, + max_gram_length=3, this operator may generate 2-grams with skip_count=0 + and skip_count=1, and 3-grams with skip_count=0 and skip_count=1 + min_gram_length + Attribute. + Minimum n-gram length. If this value is 2 and max_gram_length is 3, + output may contain counts of 2-grams and 3-grams. + mode + Attribute. + The weighting criteria. It can be one of "TF" (term frequency), "IDF" + (inverse document frequency), and "TFIDF" (the combination of TF and + IDF) + ngram_counts + Attribute. + The starting indexes of 1-grams, 2-grams, and so on in pool. It is + useful when determining the boundary between two consecutive collections + of n-grams. For example, if ngram_counts is [0, 17, 36], the first index + (zero-based) of 1-gram/2-gram/3-gram in pool are 0/17/36. This format is + essentially identical to CSR (or CSC) sparse matrix format, and we + choose to use this due to its popularity. + ngram_indexes + Attribute. + list of int64s (type: AttributeProto::INTS). This list is parallel to + the specified 'pool\_\*' attribute. The i-th element in ngram_indexes + indicate the coordinate of the i-th n-gram in the output tensor. + pool_int64s + Attribute. + List of int64 n-grams learned from the training set. Either this or + pool_strings attributes must be present but not both. It's an 1-D tensor + starting with the collections of all 1-grams and ending with the + collections of n-grams. The i-th element in pool stores the n-gram that + should be mapped to coordinate ngram_indexes[i] in the output vector. + pool_strings + Attribute. + List of strings n-grams learned from the training set. Either this or + pool_int64s attributes must be present but not both. It's an 1-D tensor + starting with the collections of all 1-grams and ending with the + collections of n-grams. The i-th element in pool stores the n-gram that + should be mapped to coordinate ngram_indexes[i] in the output vector. + weights + Attribute. + list of floats. This attribute stores the weight of each n-gram in pool. + The i-th element in weights is the weight of the i-th n-gram in pool. + Its length equals to the size of ngram_indexes. By default, weights is + an all-one tensor.This attribute is used when mode is "IDF" or "TFIDF" + to scale the associated word counts. + + Returns + ======= + Y : Var + Type T1. + Ngram results + + Notes + ===== + Signature: ``ai.onnx@9::TfIdfVectorizer``. + + Type constraints: + - T: `tensor(int32)`, `tensor(int64)`, `tensor(string)` + - T1: `tensor(float)` + """ + return ( + _TfIdfVectorizer( + _TfIdfVectorizer.Attributes( + max_gram_length=AttrInt64(max_gram_length, name="max_gram_length"), + max_skip_count=AttrInt64(max_skip_count, name="max_skip_count"), + min_gram_length=AttrInt64(min_gram_length, name="min_gram_length"), + mode=AttrString(mode, name="mode"), + ngram_counts=AttrInt64s(ngram_counts, name="ngram_counts"), + ngram_indexes=AttrInt64s(ngram_indexes, name="ngram_indexes"), + pool_int64s=AttrInt64s.maybe(pool_int64s, name="pool_int64s"), + pool_strings=AttrStrings.maybe(pool_strings, name="pool_strings"), + weights=AttrFloat32s.maybe(weights, name="weights"), + ), + _TfIdfVectorizer.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def thresholded_relu( + X: Var, + *, + alpha: float = 1.0, +) -> Var: + r""" + ThresholdedRelu takes one input data (Tensor) and produces one output + data (Tensor) where the rectified linear function, y = x for x > + alpha, y = 0 otherwise, is applied to the tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + alpha + Attribute. + Threshold value + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@10::ThresholdedRelu``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _ThresholdedRelu( + _ThresholdedRelu.Attributes( + alpha=AttrFloat32(alpha, name="alpha"), + ), + _ThresholdedRelu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) -Outputs are either sorted in ascending order or optionally in the order -of the first occurrence of the values in the input. -https://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html +def tile( + input: Var, + repeats: Var, +) -> Var: + r""" + Constructs a tensor by tiling a given tensor. This is the same as + function ``tile`` in Numpy, but no broadcast. For example A = [[1, 2], + [3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]] + + Parameters + ========== + input + Type T. + Input tensor of any shape. + repeats + Type T1. + 1D int64 tensor of the same length as input's dimension number, includes + numbers of repeated copies along input's dimensions. + + Returns + ======= + output : Var + Type T. + Output tensor of the same dimensions and type as tensor input. + output_dim[i] = input_dim[i] \* repeats[i] + + Notes + ===== + Signature: ``ai.onnx@13::Tile``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` + """ + return ( + _Tile( + _Tile.Attributes(), + _Tile.Inputs( + input=unwrap_vars(input), + repeats=unwrap_vars(repeats), + ), + ) + .get_output_vars( + input=get_value(input), + repeats=get_value(repeats), + ) + .output + ) + + +def top_k( + X: Var, + K: Var, + *, + axis: int = -1, + largest: int = 1, + sorted: int = 1, +) -> tuple[Var, Var]: + r""" + Retrieve the top-K largest or smallest elements along a specified axis. + Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer + argument k, return two outputs: + + - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a\_{n-1}] which contains the values of the top k elements along + the specified axis + + - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a\_{n-1}] which contains the indices of the top k elements + (original indices from the input tensor). + + - If "largest" is 1 (the default value) then the k largest elements are + returned. + + - If "sorted" is 1 (the default value) then the resulting k elements + will be sorted. + + - If "sorted" is 0, order of returned 'Values' and 'Indices' are + undefined. + + Given two equivalent values, this operator uses the indices along the + axis as a tiebreaker. That is, the element with the lower index will + appear first. + + Parameters + ========== + X + Type T. + Tensor of shape [a_0, a_1, ..., a\_{n-1}] + K + Type tensor(int64). + A 1-D tensor containing a single positive value corresponding to the + number of top elements to retrieve + axis + Attribute. + Dimension on which to do the sort. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + largest + Attribute. + Whether to return the top-K largest or smallest elements. + sorted + Attribute. + Whether to return the elements in sorted order. + + Returns + ======= + Values : Var + Type T. + Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] containing top K values from the input tensor + Indices : Var + Type I. + Tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] containing the corresponding input tensor indices for the top + K values. + + Notes + ===== + Signature: ``ai.onnx@11::TopK``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - I: `tensor(int64)` + """ + return ( + _TopK( + _TopK.Attributes( + axis=AttrInt64(axis, name="axis"), + largest=AttrInt64(largest, name="largest"), + sorted=AttrInt64(sorted, name="sorted"), + ), + _TopK.Inputs( + X=unwrap_vars(X), + K=unwrap_vars(K), + ), + ) + .get_output_vars( + X=get_value(X), + K=get_value(K), + ) + ._unpack_to_any() + ) + + +def transpose( + data: Var, + *, + perm: Optional[Iterable[int]] = None, +) -> Var: + r""" + Transpose the input tensor similar to numpy.transpose. For example, when + perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output + shape will be (2, 1, 3). + + Parameters + ========== + data + Type T. + An input tensor. + perm + Attribute. + A list of integers. By default, reverse the dimensions, otherwise + permute the axes according to the values given. + + Returns + ======= + transposed : Var + Type T. + Transposed output. + + Notes + ===== + Signature: ``ai.onnx@13::Transpose``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Transpose( + _Transpose.Attributes( + perm=AttrInt64s.maybe(perm, name="perm"), + ), + _Transpose.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .transposed + ) + + +def trilu( + input: Var, + k: Optional[Var] = None, + *, + upper: int = 1, +) -> Var: + r""" + Given a 2-D matrix or batches of 2-D matrices, returns the upper or + lower triangular part of the tensor(s). The attribute "upper" determines + whether the upper or lower part is retained. If set to true, the upper + triangular matrix is retained. Lower triangular matrix is retained + otherwise. Default value for the "upper" attribute is true. Trilu takes + one input tensor of shape [\*, N, M], where \* is zero or more batch + dimensions. The upper triangular part consists of the elements on and + above the given diagonal (k). The lower triangular part consists of + elements on and below the diagonal. All other elements in the matrix are + set to zero. If k = 0, the triangular part on and above/below the main + diagonal is retained. If upper is set to true, a positive k retains the + upper triangular matrix excluding the main diagonal and (k-1) diagonals + above it. A negative k value retains the main diagonal and \|k\| + diagonals below it. If upper is set to false, a positive k retains the + lower triangular matrix including the main diagonal and k diagonals + above it. A negative k value excludes the main diagonal and (\|k\|-1) + diagonals below it. + + Parameters + ========== + input + Type T. + Input tensor of rank 2 or higher. + k + Type tensor(int64). + A 0-D tensor containing a single value corresponding to the number + diagonals above or below the main diagonal to exclude or include. + Default value is 0 if it's not specified. + upper + Attribute. + Boolean. Indicates whether upper or lower part of matrix is retained. + Default is true. + + Returns + ======= + output : Var + Type T. + Output tensor of the same type and shape as the input tensor. + + Notes + ===== + Signature: ``ai.onnx@14::Trilu``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Trilu( + _Trilu.Attributes( + upper=AttrInt64(upper, name="upper"), + ), + _Trilu.Inputs( + input=unwrap_vars(input), + k=unwrap_vars(k), + ), + ) + .get_output_vars( + input=get_value(input), + k=get_value(k), + ) + .output + ) + + +def unique( + X: Var, + *, + axis: Optional[int] = None, + sorted: int = 1, +) -> tuple[Var, Var, Var, Var]: + r""" + Find the unique elements of a tensor. When an optional attribute 'axis' + is provided, unique subtensors sliced along the 'axis' are returned. + Otherwise the input tensor is flattened and unique values of the + flattened tensor are returned. + + This operator returns the unique values or sliced unique subtensors of + the input tensor and three optional outputs. The first output tensor 'Y' + contains all unique values or subtensors of the input. The second + optional output tensor 'indices' contains indices of 'Y' elements' first + occurrence in 'X'. The third optional output tensor 'inverse_indices' + contains, for elements of 'X', its corresponding indices in 'Y'. The + fourth optional output tensor 'counts' contains the count of each + element of 'Y' in the input. + + Outputs are either sorted in ascending order or optionally in the order + of the first occurrence of the values in the input. + + https://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html + + Example 1: + + :: + + input_X = [2, 1, 1, 3, 4, 3] + attribute_sorted = 0 + attribute_axis = None + output_Y = [2, 1, 3, 4] + output_indices = [0, 1, 3, 4] + output_inverse_indices = [0, 1, 1, 2, 3, 2] + output_counts = [1, 2, 2, 1] + + Example 2: + + :: -Example 1: + input_X = [[1, 3], [2, 3]] + attribute_sorted = 1 + attribute_axis = None + output_Y = [1, 2, 3] + output_indices = [0, 2, 1] + output_inverse_indices = [0, 2, 1, 2] + output_counts = [1, 1, 2] -:: + Example 3: - input_X = [2, 1, 1, 3, 4, 3] - attribute_sorted = 0 - attribute_axis = None - output_Y = [2, 1, 3, 4] - output_indices = [0, 1, 3, 4] - output_inverse_indices = [0, 1, 1, 2, 3, 2] - output_counts = [1, 2, 2, 1] + :: -Example 2: + input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]] + attribute_sorted = 1 + attribute_axis = 0 + output_Y = [[1, 0, 0], [2, 3, 4]] + output_indices = [0, 2] + output_inverse_indices = [0, 0, 1] + output_counts = [2, 1] -:: - - input_X = [[1, 3], [2, 3]] - attribute_sorted = 1 - attribute_axis = None - output_Y = [1, 2, 3] - output_indices = [0, 2, 1] - output_inverse_indices = [0, 2, 1, 2] - output_counts = [1, 1, 2] - -Example 3: - -:: - - input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]] - attribute_sorted = 1 - attribute_axis = 0 - output_Y = [[1, 0, 0], [2, 3, 4]] - output_indices = [0, 2] - output_inverse_indices = [0, 0, 1] - output_counts = [2, 1] - -Example 4: - -:: - - input_x = [[[1., 1.], [0., 1.], [2., 1.], [0., 1.]], - [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]] - attribute_sorted = 1 - attribute_axis = 1 - -intermediate data are presented below for better understanding: there -are 4 subtensors sliced along axis 1 of input_x (shape = (2, 4, 2)): - -:: - - A: [[1, 1], [1, 1]], - [[0, 1], [0, 1]], - [[2, 1], [2, 1]], - [[0, 1], [0, 1]]. + Example 4: -there are 3 unique subtensors: + :: -:: + input_x = [[[1., 1.], [0., 1.], [2., 1.], [0., 1.]], + [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]] + attribute_sorted = 1 + attribute_axis = 1 - [[1, 1], [1, 1]], - [[0, 1], [0, 1]], - [[2, 1], [2, 1]]. + intermediate data are presented below for better understanding: there + are 4 subtensors sliced along axis 1 of input_x (shape = (2, 4, 2)): -sorted unique subtensors: + :: -:: + A: [[1, 1], [1, 1]], + [[0, 1], [0, 1]], + [[2, 1], [2, 1]], + [[0, 1], [0, 1]]. - B: [[0, 1], [0, 1]], - [[1, 1], [1, 1]], - [[2, 1], [2, 1]]. + there are 3 unique subtensors: -output_Y is constructed from B: + :: -:: + [[1, 1], [1, 1]], + [[0, 1], [0, 1]], + [[2, 1], [2, 1]]. - [[[0. 1.], [1. 1.], [2. 1.]], - [[0. 1.], [1. 1.], [2. 1.]]] + sorted unique subtensors: -output_indices is to map from B to A: - -:: - - [1, 0, 2] - -output_inverse_indices is to map from A to B: - -:: - - [1, 0, 2, 0] - -output_counts: - -:: + :: - [2, 1, 1] - -Parameters -========== -X - Type T. - A N-D input tensor that is to be processed. -axis - Attribute. - (Optional) The dimension to apply unique. If not specified, the unique - elements of the flattened input are returned. Negative value means - counting dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). -sorted - Attribute. - (Optional) Whether to sort the unique elements in ascending order before - returning as output. Must be one of 0, or 1 (default). + B: [[0, 1], [0, 1]], + [[1, 1], [1, 1]], + [[2, 1], [2, 1]]. -Returns -======= -Y : Var - Type T. - A tensor of the same type as 'X' containing all the unique values or - subtensors sliced along a provided 'axis' in 'X', either sorted or - maintained in the same order they occur in input 'X' -indices : Var - Type tensor(int64). - A 1-D INT64 tensor containing indices of 'Y' elements' first occurrence - in 'X'. When 'axis' is provided, it contains indices to subtensors in - input 'X' on the 'axis'. When 'axis' is not provided, it contains - indices to values in the flattened input tensor. -inverse_indices : Var - Type tensor(int64). - A 1-D INT64 tensor containing, for elements of 'X', its corresponding - indices in 'Y'. When 'axis' is provided, it contains indices to - subtensors in output 'Y' on the 'axis'. When 'axis' is not provided, it - contains indices to values in output 'Y'. -counts : Var - Type tensor(int64). - A 1-D INT64 tensor containing the count of each element of 'Y' in input - 'X' - -Notes -===== -Signature: ``ai.onnx@11::Unique``. - -Type constraints: - - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Unique( - _Unique.Attributes( - axis=AttrInt64.maybe(axis, name="axis"), - sorted=AttrInt64(sorted, name="sorted"), - ), _Unique.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), )._unpack_to_any() - - -def unsqueeze(data: Var, axes: Var, ) -> Var: - r""" -Insert single-dimensional entries to the shape of an input tensor -(``data``). Takes one required input ``axes`` - which contains a list of -dimension indices and this operator will insert a dimension of value -``1`` into the corresponding index of the output tensor (``expanded``). - -For example, given an input tensor (``data``) of shape [3, 4, 5], then -Unsqueeze(data, axes=[0, 4]) outputs a tensor (``expanded``) containing -same data as ``data`` but with shape [1, 3, 4, 5, 1]. - -The input ``axes`` should not contain any duplicate entries. It is an -error if it contains duplicates. The rank of the output tensor -(``output_rank``) is the rank of the input tensor (``data``) plus the -number of values in ``axes``. Each value in ``axes`` should be within -the (inclusive) range [-output_rank , output_rank - 1]. The order of -values in ``axes`` does not matter and can come in any order. - -Parameters -========== -data - Type T. - Original tensor -axes - Type tensor(int64). - List of integers indicating the dimensions to be inserted. Negative - value means counting dimensions from the back. Accepted range is [-r, - r-1] where r = rank(expanded). - -Returns -======= -expanded : Var - Type T. - Reshaped tensor with same data as input. - -Notes -===== -Signature: ``ai.onnx@13::Unsqueeze``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Unsqueeze( - _Unsqueeze.Attributes( - ), _Unsqueeze.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).expanded - - -def where(condition: Var, X: Var, Y: Var, ) -> Var: - r""" -Return elements, either from X or Y, depending on condition. Where -behaves like -`numpy.where `__ -with three parameters. - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -condition - Type B. - When True (nonzero), yield X, otherwise yield Y -X - Type T. - values selected at indices where condition is True -Y - Type T. - values selected at indices where condition is False - -Returns -======= -output : Var - Type T. - Tensor of shape equal to the broadcasted shape of condition, X, and Y. - -Notes -===== -Signature: ``ai.onnx@16::Where``. - -Type constraints: - - B: `tensor(bool)` - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - """ - return _Where( - _Where.Attributes( - ), _Where.Inputs( - condition=unwrap_vars(condition), X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( - condition=get_value(condition), X=get_value(X), Y=get_value(Y), ).output - - -def xor(A: Var, B: Var, ) -> Var: - r""" -Returns the tensor resulted from performing the ``xor`` logical -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. - -Returns -======= -C : Var - Type T1. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@7::Xor``. - -Type constraints: - - T: `tensor(bool)` - - T1: `tensor(bool)` - """ - return _Xor( - _Xor.Attributes( - ), _Xor.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C + output_Y is constructed from B: + + :: + + [[[0. 1.], [1. 1.], [2. 1.]], + [[0. 1.], [1. 1.], [2. 1.]]] + + output_indices is to map from B to A: + + :: + + [1, 0, 2] + + output_inverse_indices is to map from A to B: + + :: + + [1, 0, 2, 0] + + output_counts: + + :: + + [2, 1, 1] + + Parameters + ========== + X + Type T. + A N-D input tensor that is to be processed. + axis + Attribute. + (Optional) The dimension to apply unique. If not specified, the unique + elements of the flattened input are returned. Negative value means + counting dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + sorted + Attribute. + (Optional) Whether to sort the unique elements in ascending order before + returning as output. Must be one of 0, or 1 (default). + + Returns + ======= + Y : Var + Type T. + A tensor of the same type as 'X' containing all the unique values or + subtensors sliced along a provided 'axis' in 'X', either sorted or + maintained in the same order they occur in input 'X' + indices : Var + Type tensor(int64). + A 1-D INT64 tensor containing indices of 'Y' elements' first occurrence + in 'X'. When 'axis' is provided, it contains indices to subtensors in + input 'X' on the 'axis'. When 'axis' is not provided, it contains + indices to values in the flattened input tensor. + inverse_indices : Var + Type tensor(int64). + A 1-D INT64 tensor containing, for elements of 'X', its corresponding + indices in 'Y'. When 'axis' is provided, it contains indices to + subtensors in output 'Y' on the 'axis'. When 'axis' is not provided, it + contains indices to values in output 'Y'. + counts : Var + Type tensor(int64). + A 1-D INT64 tensor containing the count of each element of 'Y' in input + 'X' + + Notes + ===== + Signature: ``ai.onnx@11::Unique``. + + Type constraints: + - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Unique( + _Unique.Attributes( + axis=AttrInt64.maybe(axis, name="axis"), + sorted=AttrInt64(sorted, name="sorted"), + ), + _Unique.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) + + +def unsqueeze( + data: Var, + axes: Var, +) -> Var: + r""" + Insert single-dimensional entries to the shape of an input tensor + (``data``). Takes one required input ``axes`` - which contains a list of + dimension indices and this operator will insert a dimension of value + ``1`` into the corresponding index of the output tensor (``expanded``). + + For example, given an input tensor (``data``) of shape [3, 4, 5], then + Unsqueeze(data, axes=[0, 4]) outputs a tensor (``expanded``) containing + same data as ``data`` but with shape [1, 3, 4, 5, 1]. + + The input ``axes`` should not contain any duplicate entries. It is an + error if it contains duplicates. The rank of the output tensor + (``output_rank``) is the rank of the input tensor (``data``) plus the + number of values in ``axes``. Each value in ``axes`` should be within + the (inclusive) range [-output_rank , output_rank - 1]. The order of + values in ``axes`` does not matter and can come in any order. + + Parameters + ========== + data + Type T. + Original tensor + axes + Type tensor(int64). + List of integers indicating the dimensions to be inserted. Negative + value means counting dimensions from the back. Accepted range is [-r, + r-1] where r = rank(expanded). + + Returns + ======= + expanded : Var + Type T. + Reshaped tensor with same data as input. + + Notes + ===== + Signature: ``ai.onnx@13::Unsqueeze``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Unsqueeze( + _Unsqueeze.Attributes(), + _Unsqueeze.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .expanded + ) + + +def where( + condition: Var, + X: Var, + Y: Var, +) -> Var: + r""" + Return elements, either from X or Y, depending on condition. Where + behaves like + `numpy.where `__ + with three parameters. + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + condition + Type B. + When True (nonzero), yield X, otherwise yield Y + X + Type T. + values selected at indices where condition is True + Y + Type T. + values selected at indices where condition is False + + Returns + ======= + output : Var + Type T. + Tensor of shape equal to the broadcasted shape of condition, X, and Y. + + Notes + ===== + Signature: ``ai.onnx@16::Where``. + + Type constraints: + - B: `tensor(bool)` + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + return ( + _Where( + _Where.Attributes(), + _Where.Inputs( + condition=unwrap_vars(condition), + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + condition=get_value(condition), + X=get_value(X), + Y=get_value(Y), + ) + .output + ) + + +def xor( + A: Var, + B: Var, +) -> Var: + r""" + Returns the tensor resulted from performing the ``xor`` logical + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@7::Xor``. + + Type constraints: + - T: `tensor(bool)` + - T1: `tensor(bool)` + """ + return ( + _Xor( + _Xor.Attributes(), + _Xor.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -14373,4 +17081,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index 318c81f8..f8de6f33 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -1,200 +1,348 @@ +# Copyright (c) QuantCo 2023-2024 +# SPDX-License-Identifier: BSD-3-Clause + # ruff: noqa: E741 -- Allow ambiguous variable name -import typing -import warnings -from dataclasses import dataclass from collections.abc import Iterable, Sequence +from dataclasses import dataclass from typing import ( - Any, - Callable, Optional, - Union, ) -from typing import cast as typing_cast import numpy as np import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( - AttrDtype, AttrFloat32, - AttrFloat32s, - AttrGraph, AttrInt64, AttrInt64s, AttrString, - AttrStrings, - AttrTensor, - AttrType, ) -from spox._graph import Graph, subgraph -from spox._internal_op import intro +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType -from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence -from spox._value_prop import PropValueType - - -from spox.opset.ai.onnx.v17 import _Abs, abs -from spox.opset.ai.onnx.v17 import _Acos, acos -from spox.opset.ai.onnx.v17 import _Acosh, acosh -from spox.opset.ai.onnx.v17 import _Add, add -from spox.opset.ai.onnx.v17 import _And, and_ -from spox.opset.ai.onnx.v17 import _ArgMax, arg_max -from spox.opset.ai.onnx.v17 import _ArgMin, arg_min -from spox.opset.ai.onnx.v17 import _Asin, asin -from spox.opset.ai.onnx.v17 import _Asinh, asinh -from spox.opset.ai.onnx.v17 import _Atan, atan -from spox.opset.ai.onnx.v17 import _Atanh, atanh -from spox.opset.ai.onnx.v17 import _AveragePool, average_pool -from spox.opset.ai.onnx.v17 import _BatchNormalization, batch_normalization -from spox.opset.ai.onnx.v17 import _Bernoulli, bernoulli -from spox.opset.ai.onnx.v17 import _BitShift, bit_shift -from spox.opset.ai.onnx.v17 import _BlackmanWindow, blackman_window -from spox.opset.ai.onnx.v17 import _Cast, cast -from spox.opset.ai.onnx.v17 import _CastLike, cast_like -from spox.opset.ai.onnx.v17 import _Ceil, ceil -from spox.opset.ai.onnx.v17 import _Celu, celu -from spox.opset.ai.onnx.v17 import _Clip, clip -from spox.opset.ai.onnx.v17 import _Compress, compress -from spox.opset.ai.onnx.v17 import _Concat, concat -from spox.opset.ai.onnx.v17 import _ConcatFromSequence, concat_from_sequence -from spox.opset.ai.onnx.v17 import _Constant, constant -from spox.opset.ai.onnx.v17 import _ConstantOfShape, constant_of_shape -from spox.opset.ai.onnx.v17 import _Conv, conv -from spox.opset.ai.onnx.v17 import _ConvInteger, conv_integer -from spox.opset.ai.onnx.v17 import _ConvTranspose, conv_transpose -from spox.opset.ai.onnx.v17 import _Cos, cos -from spox.opset.ai.onnx.v17 import _Cosh, cosh -from spox.opset.ai.onnx.v17 import _CumSum, cumsum -from spox.opset.ai.onnx.v17 import _DFT, dft -from spox.opset.ai.onnx.v17 import _DepthToSpace, depth_to_space -from spox.opset.ai.onnx.v17 import _DequantizeLinear, dequantize_linear -from spox.opset.ai.onnx.v17 import _Det, det -from spox.opset.ai.onnx.v17 import _Div, div -from spox.opset.ai.onnx.v17 import _Dropout, dropout -from spox.opset.ai.onnx.v17 import _DynamicQuantizeLinear, dynamic_quantize_linear -from spox.opset.ai.onnx.v17 import _Einsum, einsum -from spox.opset.ai.onnx.v17 import _Elu, elu -from spox.opset.ai.onnx.v17 import _Equal, equal -from spox.opset.ai.onnx.v17 import _Erf, erf -from spox.opset.ai.onnx.v17 import _Exp, exp -from spox.opset.ai.onnx.v17 import _Expand, expand -from spox.opset.ai.onnx.v17 import _EyeLike, eye_like -from spox.opset.ai.onnx.v17 import _Flatten, flatten -from spox.opset.ai.onnx.v17 import _Floor, floor -from spox.opset.ai.onnx.v17 import _GRU, gru -from spox.opset.ai.onnx.v17 import _Gather, gather -from spox.opset.ai.onnx.v17 import _GatherElements, gather_elements -from spox.opset.ai.onnx.v17 import _GatherND, gather_nd -from spox.opset.ai.onnx.v17 import _Gemm, gemm -from spox.opset.ai.onnx.v17 import _GlobalAveragePool, global_average_pool -from spox.opset.ai.onnx.v17 import _GlobalLpPool, global_lp_pool -from spox.opset.ai.onnx.v17 import _GlobalMaxPool, global_max_pool -from spox.opset.ai.onnx.v17 import _Greater, greater -from spox.opset.ai.onnx.v17 import _GreaterOrEqual, greater_or_equal -from spox.opset.ai.onnx.v17 import _GridSample, grid_sample -from spox.opset.ai.onnx.v17 import _HammingWindow, hamming_window -from spox.opset.ai.onnx.v17 import _HannWindow, hann_window -from spox.opset.ai.onnx.v17 import _HardSigmoid, hard_sigmoid -from spox.opset.ai.onnx.v17 import _HardSwish, hard_swish -from spox.opset.ai.onnx.v17 import _Hardmax, hardmax -from spox.opset.ai.onnx.v17 import _Identity, identity -from spox.opset.ai.onnx.v17 import _If, if_ -from spox.opset.ai.onnx.v17 import _InstanceNormalization, instance_normalization -from spox.opset.ai.onnx.v17 import _IsInf, isinf -from spox.opset.ai.onnx.v17 import _IsNaN, isnan -from spox.opset.ai.onnx.v17 import _LRN, lrn -from spox.opset.ai.onnx.v17 import _LSTM, lstm -from spox.opset.ai.onnx.v17 import _LayerNormalization, layer_normalization -from spox.opset.ai.onnx.v17 import _LeakyRelu, leaky_relu -from spox.opset.ai.onnx.v17 import _Less, less -from spox.opset.ai.onnx.v17 import _LessOrEqual, less_or_equal -from spox.opset.ai.onnx.v17 import _Log, log -from spox.opset.ai.onnx.v17 import _LogSoftmax, log_softmax -from spox.opset.ai.onnx.v17 import _Loop, loop -from spox.opset.ai.onnx.v17 import _LpNormalization, lp_normalization -from spox.opset.ai.onnx.v17 import _MatMul, matmul -from spox.opset.ai.onnx.v17 import _MatMulInteger, matmul_integer -from spox.opset.ai.onnx.v17 import _Max, max -from spox.opset.ai.onnx.v17 import _MaxPool, max_pool -from spox.opset.ai.onnx.v17 import _MaxRoiPool, max_roi_pool -from spox.opset.ai.onnx.v17 import _MaxUnpool, max_unpool -from spox.opset.ai.onnx.v17 import _Mean, mean -from spox.opset.ai.onnx.v17 import _MeanVarianceNormalization, mean_variance_normalization -from spox.opset.ai.onnx.v17 import _MelWeightMatrix, mel_weight_matrix -from spox.opset.ai.onnx.v17 import _Min, min -from spox.opset.ai.onnx.v17 import _Mod, mod -from spox.opset.ai.onnx.v17 import _Mul, mul -from spox.opset.ai.onnx.v17 import _Multinomial, multinomial -from spox.opset.ai.onnx.v17 import _Neg, neg -from spox.opset.ai.onnx.v17 import _NegativeLogLikelihoodLoss, negative_log_likelihood_loss -from spox.opset.ai.onnx.v17 import _NonMaxSuppression, non_max_suppression -from spox.opset.ai.onnx.v17 import _NonZero, non_zero -from spox.opset.ai.onnx.v17 import _Not, not_ -from spox.opset.ai.onnx.v17 import _OneHot, one_hot -from spox.opset.ai.onnx.v17 import _Optional, optional -from spox.opset.ai.onnx.v17 import _Or, or_ -from spox.opset.ai.onnx.v17 import _PRelu, prelu -from spox.opset.ai.onnx.v17 import _Pow, pow -from spox.opset.ai.onnx.v17 import _QLinearConv, qlinear_conv -from spox.opset.ai.onnx.v17 import _QLinearMatMul, qlinear_matmul -from spox.opset.ai.onnx.v17 import _QuantizeLinear, quantize_linear -from spox.opset.ai.onnx.v17 import _RNN, rnn -from spox.opset.ai.onnx.v17 import _RandomNormal, random_normal -from spox.opset.ai.onnx.v17 import _RandomNormalLike, random_normal_like -from spox.opset.ai.onnx.v17 import _RandomUniform, random_uniform -from spox.opset.ai.onnx.v17 import _RandomUniformLike, random_uniform_like -from spox.opset.ai.onnx.v17 import _Range, range -from spox.opset.ai.onnx.v17 import _Reciprocal, reciprocal -from spox.opset.ai.onnx.v17 import _ReduceSum, reduce_sum -from spox.opset.ai.onnx.v17 import _Relu, relu -from spox.opset.ai.onnx.v17 import _Reshape, reshape -from spox.opset.ai.onnx.v17 import _ReverseSequence, reverse_sequence -from spox.opset.ai.onnx.v17 import _RoiAlign, roi_align -from spox.opset.ai.onnx.v17 import _Round, round -from spox.opset.ai.onnx.v17 import _STFT, stft -from spox.opset.ai.onnx.v17 import _Scan, scan -from spox.opset.ai.onnx.v17 import _Selu, selu -from spox.opset.ai.onnx.v17 import _SequenceAt, sequence_at -from spox.opset.ai.onnx.v17 import _SequenceConstruct, sequence_construct -from spox.opset.ai.onnx.v17 import _SequenceEmpty, sequence_empty -from spox.opset.ai.onnx.v17 import _SequenceErase, sequence_erase -from spox.opset.ai.onnx.v17 import _SequenceInsert, sequence_insert -from spox.opset.ai.onnx.v17 import _SequenceLength, sequence_length -from spox.opset.ai.onnx.v17 import _SequenceMap, sequence_map -from spox.opset.ai.onnx.v17 import _Shape, shape -from spox.opset.ai.onnx.v17 import _Shrink, shrink -from spox.opset.ai.onnx.v17 import _Sigmoid, sigmoid -from spox.opset.ai.onnx.v17 import _Sign, sign -from spox.opset.ai.onnx.v17 import _Sin, sin -from spox.opset.ai.onnx.v17 import _Sinh, sinh -from spox.opset.ai.onnx.v17 import _Size, size -from spox.opset.ai.onnx.v17 import _Slice, slice -from spox.opset.ai.onnx.v17 import _Softmax, softmax -from spox.opset.ai.onnx.v17 import _SoftmaxCrossEntropyLoss, softmax_cross_entropy_loss -from spox.opset.ai.onnx.v17 import _Softplus, softplus -from spox.opset.ai.onnx.v17 import _Softsign, softsign -from spox.opset.ai.onnx.v17 import _SpaceToDepth, space_to_depth -from spox.opset.ai.onnx.v17 import _SplitToSequence, split_to_sequence -from spox.opset.ai.onnx.v17 import _Sqrt, sqrt -from spox.opset.ai.onnx.v17 import _Squeeze, squeeze -from spox.opset.ai.onnx.v17 import _StringNormalizer, string_normalizer -from spox.opset.ai.onnx.v17 import _Sub, sub -from spox.opset.ai.onnx.v17 import _Sum, sum -from spox.opset.ai.onnx.v17 import _Tan, tan -from spox.opset.ai.onnx.v17 import _Tanh, tanh -from spox.opset.ai.onnx.v17 import _TfIdfVectorizer, tf_idf_vectorizer -from spox.opset.ai.onnx.v17 import _ThresholdedRelu, thresholded_relu -from spox.opset.ai.onnx.v17 import _Tile, tile -from spox.opset.ai.onnx.v17 import _TopK, top_k -from spox.opset.ai.onnx.v17 import _Transpose, transpose -from spox.opset.ai.onnx.v17 import _Trilu, trilu -from spox.opset.ai.onnx.v17 import _Unique, unique -from spox.opset.ai.onnx.v17 import _Unsqueeze, unsqueeze -from spox.opset.ai.onnx.v17 import _Where, where -from spox.opset.ai.onnx.v17 import _Xor, xor +from spox._standard import StandardNode +from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox.opset.ai.onnx.v17 import ( + _DFT, + _GRU, + _LRN, + _LSTM, + _RNN, + _STFT, + _Abs, + _Acos, + _Acosh, + _Add, + _And, + _ArgMax, + _ArgMin, + _Asin, + _Asinh, + _Atan, + _Atanh, + _AveragePool, + _BatchNormalization, + _Bernoulli, + _BitShift, + _BlackmanWindow, + _Cast, + _CastLike, + _Ceil, + _Celu, + _Clip, + _Compress, + _Concat, + _ConcatFromSequence, + _Constant, + _ConstantOfShape, + _Conv, + _ConvInteger, + _ConvTranspose, + _Cos, + _Cosh, + _CumSum, + _DepthToSpace, + _DequantizeLinear, + _Det, + _Div, + _Dropout, + _DynamicQuantizeLinear, + _Einsum, + _Elu, + _Equal, + _Erf, + _Exp, + _Expand, + _EyeLike, + _Flatten, + _Floor, + _Gather, + _GatherElements, + _GatherND, + _Gemm, + _GlobalAveragePool, + _GlobalLpPool, + _GlobalMaxPool, + _Greater, + _GreaterOrEqual, + _GridSample, + _HammingWindow, + _HannWindow, + _Hardmax, + _HardSigmoid, + _HardSwish, + _Identity, + _If, + _InstanceNormalization, + _IsInf, + _IsNaN, + _LayerNormalization, + _LeakyRelu, + _Less, + _LessOrEqual, + _Log, + _LogSoftmax, + _Loop, + _LpNormalization, + _MatMul, + _MatMulInteger, + _Max, + _MaxPool, + _MaxRoiPool, + _MaxUnpool, + _Mean, + _MeanVarianceNormalization, + _MelWeightMatrix, + _Min, + _Mod, + _Mul, + _Multinomial, + _Neg, + _NegativeLogLikelihoodLoss, + _NonMaxSuppression, + _NonZero, + _Not, + _OneHot, + _Optional, + _Or, + _Pow, + _PRelu, + _QLinearConv, + _QLinearMatMul, + _QuantizeLinear, + _RandomNormal, + _RandomNormalLike, + _RandomUniform, + _RandomUniformLike, + _Range, + _Reciprocal, + _ReduceSum, + _Relu, + _Reshape, + _ReverseSequence, + _RoiAlign, + _Round, + _Scan, + _Selu, + _SequenceAt, + _SequenceConstruct, + _SequenceEmpty, + _SequenceErase, + _SequenceInsert, + _SequenceLength, + _SequenceMap, + _Shape, + _Shrink, + _Sigmoid, + _Sign, + _Sin, + _Sinh, + _Size, + _Slice, + _Softmax, + _SoftmaxCrossEntropyLoss, + _Softplus, + _Softsign, + _SpaceToDepth, + _SplitToSequence, + _Sqrt, + _Squeeze, + _StringNormalizer, + _Sub, + _Sum, + _Tan, + _Tanh, + _TfIdfVectorizer, + _ThresholdedRelu, + _Tile, + _TopK, + _Transpose, + _Trilu, + _Unique, + _Unsqueeze, + _Where, + _Xor, + abs, + acos, + acosh, + add, + and_, + arg_max, + arg_min, + asin, + asinh, + atan, + atanh, + average_pool, + batch_normalization, + bernoulli, + bit_shift, + blackman_window, + cast, + cast_like, + ceil, + celu, + clip, + compress, + concat, + concat_from_sequence, + constant, + constant_of_shape, + conv, + conv_integer, + conv_transpose, + cos, + cosh, + cumsum, + depth_to_space, + dequantize_linear, + det, + dft, + div, + dropout, + dynamic_quantize_linear, + einsum, + elu, + equal, + erf, + exp, + expand, + eye_like, + flatten, + floor, + gather, + gather_elements, + gather_nd, + gemm, + global_average_pool, + global_lp_pool, + global_max_pool, + greater, + greater_or_equal, + grid_sample, + gru, + hamming_window, + hann_window, + hard_sigmoid, + hard_swish, + hardmax, + identity, + if_, + instance_normalization, + isinf, + isnan, + layer_normalization, + leaky_relu, + less, + less_or_equal, + log, + log_softmax, + loop, + lp_normalization, + lrn, + lstm, + matmul, + matmul_integer, + max, + max_pool, + max_roi_pool, + max_unpool, + mean, + mean_variance_normalization, + mel_weight_matrix, + min, + mod, + mul, + multinomial, + neg, + negative_log_likelihood_loss, + non_max_suppression, + non_zero, + not_, + one_hot, + optional, + or_, + pow, + prelu, + qlinear_conv, + qlinear_matmul, + quantize_linear, + random_normal, + random_normal_like, + random_uniform, + random_uniform_like, + range, + reciprocal, + reduce_sum, + relu, + reshape, + reverse_sequence, + rnn, + roi_align, + round, + scan, + selu, + sequence_at, + sequence_construct, + sequence_empty, + sequence_erase, + sequence_insert, + sequence_length, + sequence_map, + shape, + shrink, + sigmoid, + sign, + sin, + sinh, + size, + slice, + softmax, + softmax_cross_entropy_loss, + softplus, + softsign, + space_to_depth, + split_to_sequence, + sqrt, + squeeze, + stft, + string_normalizer, + sub, + sum, + tan, + tanh, + tf_idf_vectorizer, + thresholded_relu, + tile, + top_k, + transpose, + trilu, + unique, + unsqueeze, + where, + xor, +) + + class _BitwiseAnd(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -215,6 +363,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _BitwiseNot(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -234,6 +383,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _BitwiseOr(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -254,6 +404,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _BitwiseXor(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -274,6 +425,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _CenterCropPad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -294,6 +446,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Col2Im(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -317,6 +470,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GroupNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -339,6 +493,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _LpPool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -364,6 +519,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Mish(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -383,6 +539,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _OptionalGetElement(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -402,6 +559,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _OptionalHasElement(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -421,6 +579,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Pad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -443,6 +602,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceL1(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -464,6 +624,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceL2(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -485,6 +646,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceLogSum(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -506,6 +668,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceLogSumExp(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -527,6 +690,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceMax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -548,6 +712,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceMean(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -569,6 +734,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceMin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -590,6 +756,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceProd(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -611,6 +778,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceSumSquare(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -632,6 +800,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Resize(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -662,6 +831,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ScatterElements(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -684,6 +854,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ScatterND(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -705,6 +876,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Split(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -726,1684 +898,2102 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs -def bitwise_and(A: Var, B: Var, ) -> Var: + +def bitwise_and( + A: Var, + B: Var, +) -> Var: r""" -Returns the tensor resulting from performing the bitwise ``and`` -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the bitwise operator. -B - Type T. - Second input operand for the bitwise operator. - -Returns -======= -C : Var - Type T. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@18::BitwiseAnd``. - -Type constraints: - - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Returns the tensor resulting from performing the bitwise ``and`` + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the bitwise operator. + B + Type T. + Second input operand for the bitwise operator. + + Returns + ======= + C : Var + Type T. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@18::BitwiseAnd``. + + Type constraints: + - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitwiseAnd( - _BitwiseAnd.Attributes( - ), _BitwiseAnd.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def bitwise_not(X: Var, ) -> Var: + return ( + _BitwiseAnd( + _BitwiseAnd.Attributes(), + _BitwiseAnd.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def bitwise_not( + X: Var, +) -> Var: r""" -Returns the bitwise not of the input tensor element-wise. - -Parameters -========== -X - Type T. - Input tensor - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@18::BitwiseNot``. - -Type constraints: - - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Returns the bitwise not of the input tensor element-wise. + + Parameters + ========== + X + Type T. + Input tensor + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@18::BitwiseNot``. + + Type constraints: + - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitwiseNot( - _BitwiseNot.Attributes( - ), _BitwiseNot.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def bitwise_or(A: Var, B: Var, ) -> Var: + return ( + _BitwiseNot( + _BitwiseNot.Attributes(), + _BitwiseNot.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def bitwise_or( + A: Var, + B: Var, +) -> Var: r""" -Returns the tensor resulting from performing the bitwise ``or`` -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the bitwise operator. -B - Type T. - Second input operand for the bitwise operator. - -Returns -======= -C : Var - Type T. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@18::BitwiseOr``. - -Type constraints: - - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Returns the tensor resulting from performing the bitwise ``or`` + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the bitwise operator. + B + Type T. + Second input operand for the bitwise operator. + + Returns + ======= + C : Var + Type T. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@18::BitwiseOr``. + + Type constraints: + - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitwiseOr( - _BitwiseOr.Attributes( - ), _BitwiseOr.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def bitwise_xor(A: Var, B: Var, ) -> Var: + return ( + _BitwiseOr( + _BitwiseOr.Attributes(), + _BitwiseOr.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def bitwise_xor( + A: Var, + B: Var, +) -> Var: r""" -Returns the tensor resulting from performing the bitwise ``xor`` -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the bitwise operator. -B - Type T. - Second input operand for the bitwise operator. - -Returns -======= -C : Var - Type T. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@18::BitwiseXor``. - -Type constraints: - - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Returns the tensor resulting from performing the bitwise ``xor`` + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the bitwise operator. + B + Type T. + Second input operand for the bitwise operator. + + Returns + ======= + C : Var + Type T. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@18::BitwiseXor``. + + Type constraints: + - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _BitwiseXor( - _BitwiseXor.Attributes( - ), _BitwiseXor.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C - - -def center_crop_pad(input_data: Var, shape: Var, *, axes: Optional[Iterable[int]] = None, ) -> Var: + return ( + _BitwiseXor( + _BitwiseXor.Attributes(), + _BitwiseXor.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) + + +def center_crop_pad( + input_data: Var, + shape: Var, + *, + axes: Optional[Iterable[int]] = None, +) -> Var: r""" -Center crop or pad an input to given dimensions. - -The crop/pad dimensions can be specified for a subset of the ``axes``. -Non-specified dimensions will not be cropped or padded. - -If the input dimensions are bigger than the crop shape, a centered -cropping window is extracted from the input. If the input dimensions are -smaller than the crop shape, the input is padded on each side equally, -so that the input is centered in the output. - -Parameters -========== -input_data - Type T. - Input to extract the centered crop from. -shape - Type Tind. - 1-D tensor representing the cropping window dimensions. -axes - Attribute. - If provided, it specifies a subset of axes that 'shape' refer to. If not - provided, all axes are assumed [0, 1, ..., r-1], where r = rank(data). - Negative value means counting dimensions from the back. Accepted range - is [-r, r-1], where r = rank(data). Behavior is undefined if an axis is - repeated. - -Returns -======= -output_data : Var - Type T. - Output data. - -Notes -===== -Signature: ``ai.onnx@18::CenterCropPad``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` + Center crop or pad an input to given dimensions. + + The crop/pad dimensions can be specified for a subset of the ``axes``. + Non-specified dimensions will not be cropped or padded. + + If the input dimensions are bigger than the crop shape, a centered + cropping window is extracted from the input. If the input dimensions are + smaller than the crop shape, the input is padded on each side equally, + so that the input is centered in the output. + + Parameters + ========== + input_data + Type T. + Input to extract the centered crop from. + shape + Type Tind. + 1-D tensor representing the cropping window dimensions. + axes + Attribute. + If provided, it specifies a subset of axes that 'shape' refer to. If not + provided, all axes are assumed [0, 1, ..., r-1], where r = rank(data). + Negative value means counting dimensions from the back. Accepted range + is [-r, r-1], where r = rank(data). Behavior is undefined if an axis is + repeated. + + Returns + ======= + output_data : Var + Type T. + Output data. + + Notes + ===== + Signature: ``ai.onnx@18::CenterCropPad``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return _CenterCropPad( - _CenterCropPad.Attributes( - axes=AttrInt64s.maybe(axes, name="axes"), - ), _CenterCropPad.Inputs( - input_data=unwrap_vars(input_data), shape=unwrap_vars(shape), ), ).get_output_vars( - input_data=get_value(input_data), shape=get_value(shape), ).output_data - - -def col2_im(input: Var, image_shape: Var, block_shape: Var, *, dilations: Optional[Iterable[int]] = None, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + return ( + _CenterCropPad( + _CenterCropPad.Attributes( + axes=AttrInt64s.maybe(axes, name="axes"), + ), + _CenterCropPad.Inputs( + input_data=unwrap_vars(input_data), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + input_data=get_value(input_data), + shape=get_value(shape), + ) + .output_data + ) + + +def col2_im( + input: Var, + image_shape: Var, + block_shape: Var, + *, + dilations: Optional[Iterable[int]] = None, + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: r""" -The operator rearranges column blocks back into a multidimensional image - -Col2Im behaves similarly to PyTorch's fold -https://pytorch.org/docs/stable/generated/torch.nn.Fold.html, but it -only supports *batched* multi-dimensional image tensors. Another -implementation in Python with N-dimension support can be found at -https://github.com/f-dangel/unfoldNd/. - -NOTE: Although specifying image_shape looks redundant because it could -be calculated from convolution formulas, it is required as input for -more advanced scenarios as explained at PyTorch's implementation -(https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Col2Im.cpp#L10) - -Parameters -========== -input - Type T. - Input data tensor to be rearranged from column blocks back into an - image. This is a 3-dimensional tensor containing [N, C \* - n-ary-product(block_shape), L], where N is batch dimension, C is image - channel dimension and L is number of blocks.The blocks are enumerated in - increasing lexicographic-order of their indices.For example, with an - image-size 10\ *20 and block-size 9*\ 18, there would be 2*3 blocks, - enumerated in the order block(0, 0), block(0, 1), block(0, 2), block(1, - 0), block(1, 1), block(1, 2). -image_shape - Type tensor(int64). - The shape of the spatial dimensions of the image after rearranging the - column blocks.This is a 1-dimensional tensor with size of at least 2, - containing the value [H_img, W_img] for a 2-D image or [dim_i1, dim_i2, - ..., dim_iN] for a N-D image. -block_shape - Type tensor(int64). - The shape of the block to apply on the input.This is a 1-dimensional - tensor of size of at least 2, containing the value [H_block, W_block] - for a 2-D image or [dim_b1, dim_b2, ..., dim_bN] for a N-D block.This is - the block-shape before dilation is applied to it. -dilations - Attribute. - 1-dimensional tensor with dilation value along each spatial axis of the - image. If not present, the dilation defaults to 1 along each spatial - axis of the image. -pads - Attribute. - 1-dimensional tensor with padding value for the beginning and ending - along each spatial axis, it can take any value greater than or equal to - 0. The value represent the number of pixels added to the beginning and - end part of the corresponding axis. ``pads`` format should be as follow - [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin is the number - of pixels added at the beginning of axis ``i`` and xi_end is the number - of pixels added at the end of axis ``i``. If not present, the padding - defaults to 0 along start and end of each spatial axis. -strides - Attribute. - 1-dimensional tensor with stride value along each spatial axis. If not - present, the stride defaults to 1 along each spatial axis. - -Returns -======= -output : Var - Type T. - Output tensor produced by rearranging blocks into an image. - -Notes -===== -Signature: ``ai.onnx@18::Col2Im``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + The operator rearranges column blocks back into a multidimensional image + + Col2Im behaves similarly to PyTorch's fold + https://pytorch.org/docs/stable/generated/torch.nn.Fold.html, but it + only supports *batched* multi-dimensional image tensors. Another + implementation in Python with N-dimension support can be found at + https://github.com/f-dangel/unfoldNd/. + + NOTE: Although specifying image_shape looks redundant because it could + be calculated from convolution formulas, it is required as input for + more advanced scenarios as explained at PyTorch's implementation + (https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Col2Im.cpp#L10) + + Parameters + ========== + input + Type T. + Input data tensor to be rearranged from column blocks back into an + image. This is a 3-dimensional tensor containing [N, C \* + n-ary-product(block_shape), L], where N is batch dimension, C is image + channel dimension and L is number of blocks.The blocks are enumerated in + increasing lexicographic-order of their indices.For example, with an + image-size 10\ *20 and block-size 9*\ 18, there would be 2*3 blocks, + enumerated in the order block(0, 0), block(0, 1), block(0, 2), block(1, + 0), block(1, 1), block(1, 2). + image_shape + Type tensor(int64). + The shape of the spatial dimensions of the image after rearranging the + column blocks.This is a 1-dimensional tensor with size of at least 2, + containing the value [H_img, W_img] for a 2-D image or [dim_i1, dim_i2, + ..., dim_iN] for a N-D image. + block_shape + Type tensor(int64). + The shape of the block to apply on the input.This is a 1-dimensional + tensor of size of at least 2, containing the value [H_block, W_block] + for a 2-D image or [dim_b1, dim_b2, ..., dim_bN] for a N-D block.This is + the block-shape before dilation is applied to it. + dilations + Attribute. + 1-dimensional tensor with dilation value along each spatial axis of the + image. If not present, the dilation defaults to 1 along each spatial + axis of the image. + pads + Attribute. + 1-dimensional tensor with padding value for the beginning and ending + along each spatial axis, it can take any value greater than or equal to + 0. The value represent the number of pixels added to the beginning and + end part of the corresponding axis. ``pads`` format should be as follow + [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin is the number + of pixels added at the beginning of axis ``i`` and xi_end is the number + of pixels added at the end of axis ``i``. If not present, the padding + defaults to 0 along start and end of each spatial axis. + strides + Attribute. + 1-dimensional tensor with stride value along each spatial axis. If not + present, the stride defaults to 1 along each spatial axis. + + Returns + ======= + output : Var + Type T. + Output tensor produced by rearranging blocks into an image. + + Notes + ===== + Signature: ``ai.onnx@18::Col2Im``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Col2Im( - _Col2Im.Attributes( - dilations=AttrInt64s.maybe(dilations, name="dilations"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _Col2Im.Inputs( - input=unwrap_vars(input), image_shape=unwrap_vars(image_shape), block_shape=unwrap_vars(block_shape), ), ).get_output_vars( - input=get_value(input), image_shape=get_value(image_shape), block_shape=get_value(block_shape), ).output - - -def group_normalization(X: Var, scale: Var, bias: Var, *, epsilon: float = 9.999999747378752e-06, num_groups: int, ) -> Var: + return ( + _Col2Im( + _Col2Im.Attributes( + dilations=AttrInt64s.maybe(dilations, name="dilations"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _Col2Im.Inputs( + input=unwrap_vars(input), + image_shape=unwrap_vars(image_shape), + block_shape=unwrap_vars(block_shape), + ), + ) + .get_output_vars( + input=get_value(input), + image_shape=get_value(image_shape), + block_shape=get_value(block_shape), + ) + .output + ) + + +def group_normalization( + X: Var, + scale: Var, + bias: Var, + *, + epsilon: float = 9.999999747378752e-06, + num_groups: int, +) -> Var: r""" -A GroupNormalization function. Carries out group normalization as -described in the paper https://arxiv.org/abs/1803.08494 - -This operator transforms input according to - -:: - - y = scale * (x - mean) / sqrt(variance + epsilon) + bias, - -where the mean and variance are computed per instance per group of -channels, and ``scale`` and ``bias`` should be specified for each group -of channels. The number of groups ``num_groups`` should be divisible by -the number of channels so that there are an equal number of channels per -group. - -When the number of groups is the same as the number of channels, this -operator is equivalent to InstanceNormalization. When there is only one -group, this operator is equivalent to LayerNormalization. - -Parameters -========== -X - Type T. - Input data tensor. Dimensions for image cases are ``(N x C x H x W)``, - where ``N`` is the batch size, ``C`` is the number of channels, and - ``H`` and ``W`` are the height and width of the data. Statistics are - computed for every group of channels over ``C``, ``H``, and ``W``. For - non-image cases, the dimensions are in the form of - ``(N x C x D1 x D2 ... Dn)``. -scale - Type T. - Scale tensor of shape ``(num_groups)``. -bias - Type T. - Bias tensor of shape ``(num_groups)``. -epsilon - Attribute. - The epsilon value to use to avoid division by zero. -num_groups - Attribute. - The number of groups of channels. It should be a divisor of the number - of channels ``C``. - -Returns -======= -Y : Var - Type T. - The output tensor of the same shape as ``X``. - -Notes -===== -Signature: ``ai.onnx@18::GroupNormalization``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + A GroupNormalization function. Carries out group normalization as + described in the paper https://arxiv.org/abs/1803.08494 + + This operator transforms input according to + + :: + + y = scale * (x - mean) / sqrt(variance + epsilon) + bias, + + where the mean and variance are computed per instance per group of + channels, and ``scale`` and ``bias`` should be specified for each group + of channels. The number of groups ``num_groups`` should be divisible by + the number of channels so that there are an equal number of channels per + group. + + When the number of groups is the same as the number of channels, this + operator is equivalent to InstanceNormalization. When there is only one + group, this operator is equivalent to LayerNormalization. + + Parameters + ========== + X + Type T. + Input data tensor. Dimensions for image cases are ``(N x C x H x W)``, + where ``N`` is the batch size, ``C`` is the number of channels, and + ``H`` and ``W`` are the height and width of the data. Statistics are + computed for every group of channels over ``C``, ``H``, and ``W``. For + non-image cases, the dimensions are in the form of + ``(N x C x D1 x D2 ... Dn)``. + scale + Type T. + Scale tensor of shape ``(num_groups)``. + bias + Type T. + Bias tensor of shape ``(num_groups)``. + epsilon + Attribute. + The epsilon value to use to avoid division by zero. + num_groups + Attribute. + The number of groups of channels. It should be a divisor of the number + of channels ``C``. + + Returns + ======= + Y : Var + Type T. + The output tensor of the same shape as ``X``. + + Notes + ===== + Signature: ``ai.onnx@18::GroupNormalization``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GroupNormalization( - _GroupNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - num_groups=AttrInt64(num_groups, name="num_groups"), - ), _GroupNormalization.Inputs( - X=unwrap_vars(X), scale=unwrap_vars(scale), bias=unwrap_vars(bias), ), ).get_output_vars( - X=get_value(X), scale=get_value(scale), bias=get_value(bias), ).Y - - -def lp_pool(X: Var, *, auto_pad: str = "NOTSET", ceil_mode: int = 0, dilations: Optional[Iterable[int]] = None, kernel_shape: Iterable[int], p: int = 2, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + return ( + _GroupNormalization( + _GroupNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + num_groups=AttrInt64(num_groups, name="num_groups"), + ), + _GroupNormalization.Inputs( + X=unwrap_vars(X), + scale=unwrap_vars(scale), + bias=unwrap_vars(bias), + ), + ) + .get_output_vars( + X=get_value(X), + scale=get_value(scale), + bias=get_value(bias), + ) + .Y + ) + + +def lp_pool( + X: Var, + *, + auto_pad: str = "NOTSET", + ceil_mode: int = 0, + dilations: Optional[Iterable[int]] = None, + kernel_shape: Iterable[int], + p: int = 2, + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: r""" -LpPool consumes an input tensor X and applies Lp pooling across the -tensor according to kernel sizes, stride sizes, and pad lengths. Lp -pooling consisting of computing the Lp norm on all values of a subset of -the input tensor according to the kernel size and downsampling the data -into the output tensor Y for further processing. The output spatial -shape will be following: - -:: - - output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) - -or - -:: - - output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) - -if ceil_mode is enabled ``pad_shape[i]`` is the sum of pads along axis -``i``. - -``auto_pad`` is a DEPRECATED attribute. If you are using them currently, -the output spatial shape will be following: - -:: - - VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) - -And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: - -:: - - pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i] - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. -ceil_mode - Attribute. - Whether to use ceil or floor (default) to compute the output shape. -dilations - Attribute. - dilation value along each spatial axis of the filter. If not present, - the dilation defaults is 1 along each spatial axis. -kernel_shape - Attribute. - The size of the kernel along each axis. -p - Attribute. - p value of the Lp norm used to pool over the input data. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - -Returns -======= -Y : Var - Type T. - Output data tensor from Lp pooling across the input tensor. Dimensions - will vary based on various kernel, stride, and pad sizes. - -Notes -===== -Signature: ``ai.onnx@18::LpPool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + LpPool consumes an input tensor X and applies Lp pooling across the + tensor according to kernel sizes, stride sizes, and pad lengths. Lp + pooling consisting of computing the Lp norm on all values of a subset of + the input tensor according to the kernel size and downsampling the data + into the output tensor Y for further processing. The output spatial + shape will be following: + + :: + + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) + + or + + :: + + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1) + + if ceil_mode is enabled ``pad_shape[i]`` is the sum of pads along axis + ``i``. + + ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, + the output spatial shape will be following: + + :: + + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + + And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: + + :: + + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i] + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. + ceil_mode + Attribute. + Whether to use ceil or floor (default) to compute the output shape. + dilations + Attribute. + dilation value along each spatial axis of the filter. If not present, + the dilation defaults is 1 along each spatial axis. + kernel_shape + Attribute. + The size of the kernel along each axis. + p + Attribute. + p value of the Lp norm used to pool over the input data. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + + Returns + ======= + Y : Var + Type T. + Output data tensor from Lp pooling across the input tensor. Dimensions + will vary based on various kernel, stride, and pad sizes. + + Notes + ===== + Signature: ``ai.onnx@18::LpPool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _LpPool( - _LpPool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - p=AttrInt64(p, name="p"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _LpPool.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def mish(X: Var, ) -> Var: + return ( + _LpPool( + _LpPool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + p=AttrInt64(p, name="p"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _LpPool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def mish( + X: Var, +) -> Var: r""" -Mish: A Self Regularized Non-Monotonic Neural Activation Function. + Mish: A Self Regularized Non-Monotonic Neural Activation Function. -Perform the linear unit element-wise on the input tensor X using -formula: + Perform the linear unit element-wise on the input tensor X using + formula: -:: + :: - mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x})) + mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x})) -Parameters -========== -X - Type T. - Input tensor + Parameters + ========== + X + Type T. + Input tensor -Returns -======= -Y : Var - Type T. - Output tensor + Returns + ======= + Y : Var + Type T. + Output tensor -Notes -===== -Signature: ``ai.onnx@18::Mish``. + Notes + ===== + Signature: ``ai.onnx@18::Mish``. -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Mish( - _Mish.Attributes( - ), _Mish.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def optional_get_element(input: Var, ) -> Var: + return ( + _Mish( + _Mish.Attributes(), + _Mish.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def optional_get_element( + input: Var, +) -> Var: r""" -If the input is a tensor or sequence type, it returns the input. If the -input is an optional type, it outputs the element in the input. It is an -error if the input is an empty optional-type (i.e. does not have an -element) and the behavior is undefined in this case. - -Parameters -========== -input - Type O. - The optional input. - -Returns -======= -output : Var - Type V. - Output element in the optional input. - -Notes -===== -Signature: ``ai.onnx@18::OptionalGetElement``. - -Type constraints: - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + If the input is a tensor or sequence type, it returns the input. If the + input is an optional type, it outputs the element in the input. It is an + error if the input is an empty optional-type (i.e. does not have an + element) and the behavior is undefined in this case. + + Parameters + ========== + input + Type O. + The optional input. + + Returns + ======= + output : Var + Type V. + Output element in the optional input. + + Notes + ===== + Signature: ``ai.onnx@18::OptionalGetElement``. + + Type constraints: + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _OptionalGetElement( - _OptionalGetElement.Attributes( - ), _OptionalGetElement.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def optional_has_element(input: Optional[Var] = None, ) -> Var: + return ( + _OptionalGetElement( + _OptionalGetElement.Attributes(), + _OptionalGetElement.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def optional_has_element( + input: Optional[Var] = None, +) -> Var: r""" -Returns true if (1) the input is an optional-type and contains an -element, or, (2) the input is a tensor or sequence type. If the input is -not provided or is an empty optional-type, this op returns false. - -Parameters -========== -input - Type O. - The optional input. - -Returns -======= -output : Var - Type B. - A scalar boolean tensor. If true, it indicates that optional-type input - contains an element. Otherwise, it is empty. - -Notes -===== -Signature: ``ai.onnx@18::OptionalHasElement``. - -Type constraints: - - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - B: `tensor(bool)` + Returns true if (1) the input is an optional-type and contains an + element, or, (2) the input is a tensor or sequence type. If the input is + not provided or is an empty optional-type, this op returns false. + + Parameters + ========== + input + Type O. + The optional input. + + Returns + ======= + output : Var + Type B. + A scalar boolean tensor. If true, it indicates that optional-type input + contains an element. Otherwise, it is empty. + + Notes + ===== + Signature: ``ai.onnx@18::OptionalHasElement``. + + Type constraints: + - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - B: `tensor(bool)` """ - return _OptionalHasElement( - _OptionalHasElement.Attributes( - ), _OptionalHasElement.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output - - -def pad(data: Var, pads: Var, constant_value: Optional[Var] = None, axes: Optional[Var] = None, *, mode: str = "constant", ) -> Var: + return ( + _OptionalHasElement( + _OptionalHasElement.Attributes(), + _OptionalHasElement.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def pad( + data: Var, + pads: Var, + constant_value: Optional[Var] = None, + axes: Optional[Var] = None, + *, + mode: str = "constant", +) -> Var: r""" -Given a tensor containing the data to be padded (``data``), a tensor -containing the number of start and end pad values for axis (``pads``), -(optionally) a ``mode``, and (optionally) ``constant_value``, a padded -tensor (``output``) is generated. - -The three supported ``modes`` are (similar to corresponding modes -supported by ``numpy.pad``): - -1) ``constant``\ (default) - pads with a given constant value as - specified by ``constant_value`` (which defaults to 0, empty string, - or False) - -2) ``reflect`` - pads with the reflection of the vector mirrored on the - first and last values of the vector along each axis - -3) ``edge`` - pads with the edge values of array - -Example 1 (``constant`` mode): - -Insert 0 pads to the beginning of the second dimension. - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'constant' - - constant_value = 0.0 - - output = [ - [0.0, 0.0, 1.0, 1.2], - [0.0, 0.0, 2.3, 3.4], - [0.0, 0.0, 4.5, 5.7], - ] - -Example 2 (``reflect`` mode): - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'reflect' - - output = [ - [1.0, 1.2, 1.0, 1.2], - [2.3, 3.4, 2.3, 3.4], - [4.5, 5.7, 4.5, 5.7], - ] - -Example 3 (``edge`` mode): - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'edge' - - output = [ - [1.0, 1.0, 1.0, 1.2], - [2.3, 2.3, 2.3, 3.4], - [4.5, 4.5, 4.5, 5.7], - ] - -Parameters -========== -data - Type T. - Input tensor. -pads - Type tensor(int64). - Tensor of integers indicating the number of padding elements to add or - remove (if negative) at the beginning and end of each axis. For 2D input - tensor, it is the number of pixels. ``pads`` should be a 1D tensor of - shape [2 \* num_axes] where ``num_axes`` refers to the number of - elements in the ``axes`` input or the input rank if ``axes`` are not - provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, - ..., x1_end, x2_end,...], where xi_begin is the number of pad values - added at the beginning of axis ``axes[i]`` and xi_end, the number of pad - values added at the end of axis ``axes[i]``. -constant_value - Type T. - (Optional) A scalar value to be used if the mode chosen is ``constant`` - (by default it is 0, empty string or False). -axes - Type Tind. - 1-D tensor of axes that ``pads`` apply to. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(data). Behavior is undefined if an axis is repeated. If not - provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). -mode - Attribute. - Supported modes: ``constant``\ (default), ``reflect``, ``edge`` - -Returns -======= -output : Var - Type T. - Tensor after padding. - -Notes -===== -Signature: ``ai.onnx@18::Pad``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` + Given a tensor containing the data to be padded (``data``), a tensor + containing the number of start and end pad values for axis (``pads``), + (optionally) a ``mode``, and (optionally) ``constant_value``, a padded + tensor (``output``) is generated. + + The three supported ``modes`` are (similar to corresponding modes + supported by ``numpy.pad``): + + 1) ``constant``\ (default) - pads with a given constant value as + specified by ``constant_value`` (which defaults to 0, empty string, + or False) + + 2) ``reflect`` - pads with the reflection of the vector mirrored on the + first and last values of the vector along each axis + + 3) ``edge`` - pads with the edge values of array + + Example 1 (``constant`` mode): + + Insert 0 pads to the beginning of the second dimension. + + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + + Example 2 (``reflect`` mode): + + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] + + Example 3 (``edge`` mode): + + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] + + Parameters + ========== + data + Type T. + Input tensor. + pads + Type tensor(int64). + Tensor of integers indicating the number of padding elements to add or + remove (if negative) at the beginning and end of each axis. For 2D input + tensor, it is the number of pixels. ``pads`` should be a 1D tensor of + shape [2 \* num_axes] where ``num_axes`` refers to the number of + elements in the ``axes`` input or the input rank if ``axes`` are not + provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, + ..., x1_end, x2_end,...], where xi_begin is the number of pad values + added at the beginning of axis ``axes[i]`` and xi_end, the number of pad + values added at the end of axis ``axes[i]``. + constant_value + Type T. + (Optional) A scalar value to be used if the mode chosen is ``constant`` + (by default it is 0, empty string or False). + axes + Type Tind. + 1-D tensor of axes that ``pads`` apply to. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(data). Behavior is undefined if an axis is repeated. If not + provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). + mode + Attribute. + Supported modes: ``constant``\ (default), ``reflect``, ``edge`` + + Returns + ======= + output : Var + Type T. + Tensor after padding. + + Notes + ===== + Signature: ``ai.onnx@18::Pad``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), _Pad.Inputs( - data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), pads=get_value(pads), constant_value=get_value(constant_value), axes=get_value(axes), ).output - - -def reduce_l1(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), + _Pad.Inputs( + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), + ) + .output + ) + + +def reduce_l1( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the L1 norm of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields 0. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceL1``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + Computes the L1 norm of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields 0. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceL1``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceL1( - _ReduceL1.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceL1.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_l2(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ReduceL1( + _ReduceL1.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceL1.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_l2( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the L2 norm of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields 0. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceL2``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + Computes the L2 norm of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields 0. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceL2``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceL2( - _ReduceL2.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceL2.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_log_sum(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ReduceL2( + _ReduceL2.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceL2.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_log_sum( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the log sum of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields minus infinity (if -supported by the datatype) or undefined otherwise. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceLogSum``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + Computes the log sum of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields minus infinity (if + supported by the datatype) or undefined otherwise. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceLogSum``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceLogSum( - _ReduceLogSum.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceLogSum.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_log_sum_exp(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ReduceLogSum( + _ReduceLogSum.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceLogSum.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_log_sum_exp( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the log sum exponent of the input tensor's elements along the -provided axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields minus infinity (if -supported by the datatype) or undefined otherwise. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceLogSumExp``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + Computes the log sum exponent of the input tensor's elements along the + provided axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields minus infinity (if + supported by the datatype) or undefined otherwise. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceLogSumExp``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceLogSumExp( - _ReduceLogSumExp.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceLogSumExp.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_max(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ReduceLogSumExp( + _ReduceLogSumExp.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceLogSumExp.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_max( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the max of the input tensor's elements along the provided axes. -The resulting tensor has the same rank as the input if ``keepdims`` -equals 1. If ``keepdims`` equals 0, then the resulting tensor has the -reduced dimension pruned. Input tensors of rank zero are valid. -Reduction over an empty set of values yields minus infinity (if -supported by the datatype) or the minimum value of the data type -otherwise. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceMax``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Computes the max of the input tensor's elements along the provided axes. + The resulting tensor has the same rank as the input if ``keepdims`` + equals 1. If ``keepdims`` equals 0, then the resulting tensor has the + reduced dimension pruned. Input tensors of rank zero are valid. + Reduction over an empty set of values yields minus infinity (if + supported by the datatype) or the minimum value of the data type + otherwise. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceMax``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReduceMax( - _ReduceMax.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceMax.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_mean(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ReduceMax( + _ReduceMax.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceMax.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_mean( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the mean of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields undefined. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceMean``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + Computes the mean of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields undefined. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceMean``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceMean( - _ReduceMean.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceMean.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_min(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ReduceMean( + _ReduceMean.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceMean.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_min( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the min of the input tensor's elements along the provided axes. -The resulting tensor has the same rank as the input if ``keepdims`` -equals 1. If ``keepdims`` equals 0, then the resulting tensor has the -reduced dimension pruned. Input tensors of rank zero are valid. -Reduction over an empty set of values yields plus infinity (if supported -by the datatype) or the maximum value of the data type otherwise. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceMin``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Computes the min of the input tensor's elements along the provided axes. + The resulting tensor has the same rank as the input if ``keepdims`` + equals 1. If ``keepdims`` equals 0, then the resulting tensor has the + reduced dimension pruned. Input tensors of rank zero are valid. + Reduction over an empty set of values yields plus infinity (if supported + by the datatype) or the maximum value of the data type otherwise. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceMin``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ReduceMin( - _ReduceMin.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceMin.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_prod(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ReduceMin( + _ReduceMin.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceMin.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_prod( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the product of the input tensor's elements along the provided -axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields 1. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceProd``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + Computes the product of the input tensor's elements along the provided + axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields 1. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceProd``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceProd( - _ReduceProd.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceProd.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_sum_square(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ReduceProd( + _ReduceProd.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceProd.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_sum_square( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -Computes the sum square of the input tensor's elements along the -provided axes. The resulting tensor has the same rank as the input if -``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting -tensor has the reduced dimension pruned. Input tensors of rank zero are -valid. Reduction over an empty set of values yields 0. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@18::ReduceSumSquare``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` + Computes the sum square of the input tensor's elements along the + provided axes. The resulting tensor has the same rank as the input if + ``keepdims`` equals 1. If ``keepdims`` equals 0, then the resulting + tensor has the reduced dimension pruned. Input tensors of rank zero are + valid. Reduction over an empty set of values yields 0. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@18::ReduceSumSquare``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - return _ReduceSumSquare( - _ReduceSumSquare.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceSumSquare.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def resize(X: Var, roi: Optional[Var] = None, scales: Optional[Var] = None, sizes: Optional[Var] = None, *, antialias: int = 0, axes: Optional[Iterable[int]] = None, coordinate_transformation_mode: str = "half_pixel", cubic_coeff_a: float = -0.75, exclude_outside: int = 0, extrapolation_value: float = 0.0, keep_aspect_ratio_policy: str = "stretch", mode: str = "nearest", nearest_mode: str = "round_prefer_floor", ) -> Var: + return ( + _ReduceSumSquare( + _ReduceSumSquare.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceSumSquare.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def resize( + X: Var, + roi: Optional[Var] = None, + scales: Optional[Var] = None, + sizes: Optional[Var] = None, + *, + antialias: int = 0, + axes: Optional[Iterable[int]] = None, + coordinate_transformation_mode: str = "half_pixel", + cubic_coeff_a: float = -0.75, + exclude_outside: int = 0, + extrapolation_value: float = 0.0, + keep_aspect_ratio_policy: str = "stretch", + mode: str = "nearest", + nearest_mode: str = "round_prefer_floor", +) -> Var: r""" -Resize the input tensor. In general, it calculates every value in the -output tensor as a weighted average of neighborhood (a.k.a. sampling -locations) in the input tensor. Each dimension value of the output -tensor is: -``output_dimension = floor(input_dimension * (roi_end - roi_start) * scale)`` -if input "sizes" is not specified. - -Parameters -========== -X - Type T1. - N-D tensor -roi - Type T2. - 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is - the rank of X or the length of axes, if provided. The RoIs' coordinates - are normalized in the coordinate system of the input image. It only - takes effect when coordinate_transformation_mode is "tf_crop_and_resize" -scales - Type tensor(float). - The scale array along each dimension. It takes value greater than 0. If - it's less than 1, it's sampling down, otherwise, it's upsampling. The - number of elements of 'scales' should be the same as the rank of input - 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' - MUST be specified and it is an error if both are specified. If 'sizes' - is needed, the user can use an empty string as the name of 'scales' in - this operator's input list. -sizes - Type tensor(int64). - Target size of the output tensor. Its interpretation depends on the - 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' - should be the same as the rank of input 'X', or the length of 'axes', if - provided. Only one of 'scales' and 'sizes' can be specified. -antialias - Attribute. - If set to 1, "linear" and "cubic" interpolation modes will use an - antialiasing filter when downscaling. Antialiasing is achieved by - stretching the resampling filter by a factor max(1, 1 / scale), which - means that when downsampling, more input pixels contribute to an output - pixel. -axes - Attribute. - If provided, it specifies a subset of axes that 'roi', 'scales' and - 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., - r-1], where r = rank(data). Non-specified dimensions are interpreted as - non-resizable. Negative value means counting dimensions from the back. - Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined - if an axis is repeated. -coordinate_transformation_mode - Attribute. - This attribute describes how to transform the coordinate in the resized - tensor to the coordinate in the original tensor. - - The coordinate of each dimension is transformed individually. Let's - describe a case using axis x as an example. Denote x_resized as the - coordinate of axis x in the resized tensor, x_original as the coordinate - of axis x in the original tensor, ``length_original`` as the length of - the original tensor in axis x, length_resized as the length of the - resized tensor in axis x, roi_x = (start_x, end_x) of the axis x in - input "roi", ``scale = length_resized / length_original``, - - if coordinate_transformation_mode is ``"half_pixel"``, - ``x_original = (x_resized + 0.5) / scale - 0.5`` - - if coordinate_transformation_mode is ``"pytorch_half_pixel"``, - ``x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0`` - - if coordinate_transformation_mode is ``"align_corners"``, - ``x_original = x_resized * (length_original - 1) / (length_resized - 1)`` - - if coordinate_transformation_mode is ``"asymmetric"``, - ``x_original = x_resized / scale`` - - if coordinate_transformation_mode is ``"tf_crop_and_resize"``, - ``x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1)`` - . -cubic_coeff_a - Attribute. - The coefficient 'a' used in cubic interpolation. Two common choice are - -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out - Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the - details. This attribute is valid only if mode is "cubic". -exclude_outside - Attribute. - If set to 1, the weight of sampling locations outside the tensor will be - set to 0 and the weight will be renormalized so that their sum is 1.0. - The default value is 0. -extrapolation_value - Attribute. - When coordinate_transformation_mode is "tf_crop_and_resize" and - x_original is outside the range [0, length_original - 1], this value is - used as the corresponding output value. Default is 0.0f. -keep_aspect_ratio_policy - Attribute. - This attribute describes how to interpret the ``sizes`` input with - regard to keeping the original aspect ratio of the input, and it is not - applicable when the ``scales`` input is used. - - Given a set of ``sizes``, associated with a subset of ``axes`` - (explicitly provided or default), and assuming ``d = axes[i]``, with - ``i`` being the index of the provided ``sizes``. - - If ``keep_aspect_ratio_policy`` is ``"stretch"``, the original aspect - ratio is disregarded, and the input is resized to the specified size: - ``out_size[d] = sizes[i]`` - - If ``keep_aspect_ratio_policy`` is ``"not_larger"``, the sizes are - adjusted so that no extent of the output is larger than the specified - size, while keeping the original aspect ratio: - ``scale = Min(sizes[i] / in_size[d])`` - ``out_size[d] = round_int(scale * in_size[i])`` - - If ``keep_aspect_ratio_policy`` is ``"not_smaller"``, the sizes are - adjusted so that no extent of the output is smaller than the specified - size, while keeping the original aspect ratio: - ``scale = Max(sizes[i] / in_size[d])`` - ``out_size[d] = round_int(scale * in_size[i])`` - - For non-resizable axes (those not specified in ``axes``), the output - size will be equal to the input size. - - Note: ``round_int`` stands for computing the nearest integer value, - rounding halfway cases up. -mode - Attribute. - Three interpolation modes: "nearest" (default), "linear" and "cubic". - The "linear" mode includes linear interpolation for 1D tensor and - N-linear interpolation for N-D tensor (for example, bilinear - interpolation for 2D tensor). The "cubic" mode includes cubic - interpolation for 1D tensor and N-cubic interpolation for N-D tensor - (for example, bicubic interpolation for 2D tensor). -nearest_mode - Attribute. - Four modes: "round_prefer_floor" (default, as known as round half down), - "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only - used by nearest interpolation. It indicates how to get "nearest" pixel - in input tensor from x_original, so this attribute is valid only if - "mode" is "nearest". - -Returns -======= -Y : Var - Type T1. - N-D tensor after resizing - -Notes -===== -Signature: ``ai.onnx@18::Resize``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + Resize the input tensor. In general, it calculates every value in the + output tensor as a weighted average of neighborhood (a.k.a. sampling + locations) in the input tensor. Each dimension value of the output + tensor is: + ``output_dimension = floor(input_dimension * (roi_end - roi_start) * scale)`` + if input "sizes" is not specified. + + Parameters + ========== + X + Type T1. + N-D tensor + roi + Type T2. + 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is + the rank of X or the length of axes, if provided. The RoIs' coordinates + are normalized in the coordinate system of the input image. It only + takes effect when coordinate_transformation_mode is "tf_crop_and_resize" + scales + Type tensor(float). + The scale array along each dimension. It takes value greater than 0. If + it's less than 1, it's sampling down, otherwise, it's upsampling. The + number of elements of 'scales' should be the same as the rank of input + 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' + MUST be specified and it is an error if both are specified. If 'sizes' + is needed, the user can use an empty string as the name of 'scales' in + this operator's input list. + sizes + Type tensor(int64). + Target size of the output tensor. Its interpretation depends on the + 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' + should be the same as the rank of input 'X', or the length of 'axes', if + provided. Only one of 'scales' and 'sizes' can be specified. + antialias + Attribute. + If set to 1, "linear" and "cubic" interpolation modes will use an + antialiasing filter when downscaling. Antialiasing is achieved by + stretching the resampling filter by a factor max(1, 1 / scale), which + means that when downsampling, more input pixels contribute to an output + pixel. + axes + Attribute. + If provided, it specifies a subset of axes that 'roi', 'scales' and + 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., + r-1], where r = rank(data). Non-specified dimensions are interpreted as + non-resizable. Negative value means counting dimensions from the back. + Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined + if an axis is repeated. + coordinate_transformation_mode + Attribute. + This attribute describes how to transform the coordinate in the resized + tensor to the coordinate in the original tensor. + + The coordinate of each dimension is transformed individually. Let's + describe a case using axis x as an example. Denote x_resized as the + coordinate of axis x in the resized tensor, x_original as the coordinate + of axis x in the original tensor, ``length_original`` as the length of + the original tensor in axis x, length_resized as the length of the + resized tensor in axis x, roi_x = (start_x, end_x) of the axis x in + input "roi", ``scale = length_resized / length_original``, + + if coordinate_transformation_mode is ``"half_pixel"``, + ``x_original = (x_resized + 0.5) / scale - 0.5`` + + if coordinate_transformation_mode is ``"pytorch_half_pixel"``, + ``x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0`` + + if coordinate_transformation_mode is ``"align_corners"``, + ``x_original = x_resized * (length_original - 1) / (length_resized - 1)`` + + if coordinate_transformation_mode is ``"asymmetric"``, + ``x_original = x_resized / scale`` + + if coordinate_transformation_mode is ``"tf_crop_and_resize"``, + ``x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1)`` + . + cubic_coeff_a + Attribute. + The coefficient 'a' used in cubic interpolation. Two common choice are + -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out + Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the + details. This attribute is valid only if mode is "cubic". + exclude_outside + Attribute. + If set to 1, the weight of sampling locations outside the tensor will be + set to 0 and the weight will be renormalized so that their sum is 1.0. + The default value is 0. + extrapolation_value + Attribute. + When coordinate_transformation_mode is "tf_crop_and_resize" and + x_original is outside the range [0, length_original - 1], this value is + used as the corresponding output value. Default is 0.0f. + keep_aspect_ratio_policy + Attribute. + This attribute describes how to interpret the ``sizes`` input with + regard to keeping the original aspect ratio of the input, and it is not + applicable when the ``scales`` input is used. + + Given a set of ``sizes``, associated with a subset of ``axes`` + (explicitly provided or default), and assuming ``d = axes[i]``, with + ``i`` being the index of the provided ``sizes``. + + If ``keep_aspect_ratio_policy`` is ``"stretch"``, the original aspect + ratio is disregarded, and the input is resized to the specified size: + ``out_size[d] = sizes[i]`` + + If ``keep_aspect_ratio_policy`` is ``"not_larger"``, the sizes are + adjusted so that no extent of the output is larger than the specified + size, while keeping the original aspect ratio: + ``scale = Min(sizes[i] / in_size[d])`` + ``out_size[d] = round_int(scale * in_size[i])`` + + If ``keep_aspect_ratio_policy`` is ``"not_smaller"``, the sizes are + adjusted so that no extent of the output is smaller than the specified + size, while keeping the original aspect ratio: + ``scale = Max(sizes[i] / in_size[d])`` + ``out_size[d] = round_int(scale * in_size[i])`` + + For non-resizable axes (those not specified in ``axes``), the output + size will be equal to the input size. + + Note: ``round_int`` stands for computing the nearest integer value, + rounding halfway cases up. + mode + Attribute. + Three interpolation modes: "nearest" (default), "linear" and "cubic". + The "linear" mode includes linear interpolation for 1D tensor and + N-linear interpolation for N-D tensor (for example, bilinear + interpolation for 2D tensor). The "cubic" mode includes cubic + interpolation for 1D tensor and N-cubic interpolation for N-D tensor + (for example, bicubic interpolation for 2D tensor). + nearest_mode + Attribute. + Four modes: "round_prefer_floor" (default, as known as round half down), + "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only + used by nearest interpolation. It indicates how to get "nearest" pixel + in input tensor from x_original, so this attribute is valid only if + "mode" is "nearest". + + Returns + ======= + Y : Var + Type T1. + N-D tensor after resizing + + Notes + ===== + Signature: ``ai.onnx@18::Resize``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _Resize( - _Resize.Attributes( - antialias=AttrInt64(antialias, name="antialias"), - axes=AttrInt64s.maybe(axes, name="axes"), - coordinate_transformation_mode=AttrString(coordinate_transformation_mode, name="coordinate_transformation_mode"), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32(extrapolation_value, name="extrapolation_value"), - keep_aspect_ratio_policy=AttrString(keep_aspect_ratio_policy, name="keep_aspect_ratio_policy"), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), _Resize.Inputs( - X=unwrap_vars(X), roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), ).get_output_vars( - X=get_value(X), roi=get_value(roi), scales=get_value(scales), sizes=get_value(sizes), ).Y - - -def scatter_elements(data: Var, indices: Var, updates: Var, *, axis: int = 0, reduction: str = "none", ) -> Var: + return ( + _Resize( + _Resize.Attributes( + antialias=AttrInt64(antialias, name="antialias"), + axes=AttrInt64s.maybe(axes, name="axes"), + coordinate_transformation_mode=AttrString( + coordinate_transformation_mode, + name="coordinate_transformation_mode", + ), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32( + extrapolation_value, name="extrapolation_value" + ), + keep_aspect_ratio_policy=AttrString( + keep_aspect_ratio_policy, name="keep_aspect_ratio_policy" + ), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), + ), + _Resize.Inputs( + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), + ), + ) + .get_output_vars( + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), + ) + .Y + ) + + +def scatter_elements( + data: Var, + indices: Var, + updates: Var, + *, + axis: int = 0, + reduction: str = "none", +) -> Var: r""" -ScatterElements takes three inputs ``data``, ``updates``, and -``indices`` of the same rank r >= 1 and an optional attribute axis that -identifies an axis of ``data`` (by default, the outer-most axis, that is -axis 0). The output of the operation is produced by creating a copy of -the input ``data``, and then updating its value to values specified by -``updates`` at specific index positions specified by ``indices``. Its -output shape is the same as the shape of ``data``. - -For each entry in ``updates``, the target index in ``data`` is obtained -by combining the corresponding entry in ``indices`` with the index of -the entry itself: the index-value for dimension = axis is obtained from -the value of the corresponding entry in ``indices`` and the index-value -for dimension != axis is obtained from the index of the entry itself. - -``reduction`` allows specification of an optional reduction operation, -which is applied to all values in ``updates`` tensor into ``output`` at -the specified ``indices``. In cases where ``reduction`` is set to -"none", indices should not have duplicate entries: that is, if idx1 != -idx2, then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor -case, the update corresponding to the [i][j] entry is performed as -below: - -:: - - output[indices[i][j]][j] = updates[i][j] if axis = 0, - output[i][indices[i][j]] = updates[i][j] if axis = 1, - -When ``reduction`` is set to some reduction function ``f``, the update -corresponding to the [i][j] entry is performed as below: - -:: - - output[indices[i][j]][j] = f(output[indices[i][j]][j], updates[i][j]) if axis = 0, - output[i][indices[i][j]] = f(output[i][indices[i][j]], updates[i][j]) if axis = 1, - -where the ``f`` is ``+``, ``*``, ``max`` or ``min`` as specified. - -This operator is the inverse of GatherElements. It is similar to Torch's -Scatter operation. - -(Opset 18 change): Adds max/min to the set of allowed reduction ops. - -Example 1: - -:: - - data = [ - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0], - ] - indices = [ - [1, 0, 2], - [0, 2, 1], - ] - updates = [ - [1.0, 1.1, 1.2], - [2.0, 2.1, 2.2], - ] - output = [ - [2.0, 1.1, 0.0] - [1.0, 0.0, 2.2] - [0.0, 2.1, 1.2] - ] - -Example 2: - -:: - - data = [[1.0, 2.0, 3.0, 4.0, 5.0]] - indices = [[1, 3]] - updates = [[1.1, 2.1]] - axis = 1 - output = [[1.0, 1.1, 3.0, 2.1, 5.0]] - -Parameters -========== -data - Type T. - Tensor of rank r >= 1. -indices - Type Tind. - Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index - values are expected to be within bounds [-s, s-1] along axis of size s. - It is an error if any of the index values are out of bounds. -updates - Type T. - Tensor of rank r >=1 (same rank and shape as indices) -axis - Attribute. - Which axis to scatter on. Negative value means counting dimensions from - the back. Accepted range is [-r, r-1] where r = rank(data). -reduction - Attribute. - Type of reduction to apply: none (default), add, mul, max, min. 'none': - no reduction applied. 'add': reduction using the addition operation. - 'mul': reduction using the multiplication operation.'max': reduction - using the maximum operation.'min': reduction using the minimum - operation. - -Returns -======= -output : Var - Type T. - Tensor of rank r >= 1 (same rank as input). - -Notes -===== -Signature: ``ai.onnx@18::ScatterElements``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` + ScatterElements takes three inputs ``data``, ``updates``, and + ``indices`` of the same rank r >= 1 and an optional attribute axis that + identifies an axis of ``data`` (by default, the outer-most axis, that is + axis 0). The output of the operation is produced by creating a copy of + the input ``data``, and then updating its value to values specified by + ``updates`` at specific index positions specified by ``indices``. Its + output shape is the same as the shape of ``data``. + + For each entry in ``updates``, the target index in ``data`` is obtained + by combining the corresponding entry in ``indices`` with the index of + the entry itself: the index-value for dimension = axis is obtained from + the value of the corresponding entry in ``indices`` and the index-value + for dimension != axis is obtained from the index of the entry itself. + + ``reduction`` allows specification of an optional reduction operation, + which is applied to all values in ``updates`` tensor into ``output`` at + the specified ``indices``. In cases where ``reduction`` is set to + "none", indices should not have duplicate entries: that is, if idx1 != + idx2, then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor + case, the update corresponding to the [i][j] entry is performed as + below: + + :: + + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + + When ``reduction`` is set to some reduction function ``f``, the update + corresponding to the [i][j] entry is performed as below: + + :: + + output[indices[i][j]][j] = f(output[indices[i][j]][j], updates[i][j]) if axis = 0, + output[i][indices[i][j]] = f(output[i][indices[i][j]], updates[i][j]) if axis = 1, + + where the ``f`` is ``+``, ``*``, ``max`` or ``min`` as specified. + + This operator is the inverse of GatherElements. It is similar to Torch's + Scatter operation. + + (Opset 18 change): Adds max/min to the set of allowed reduction ops. + + Example 1: + + :: + + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + + Example 2: + + :: + + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + + Parameters + ========== + data + Type T. + Tensor of rank r >= 1. + indices + Type Tind. + Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index + values are expected to be within bounds [-s, s-1] along axis of size s. + It is an error if any of the index values are out of bounds. + updates + Type T. + Tensor of rank r >=1 (same rank and shape as indices) + axis + Attribute. + Which axis to scatter on. Negative value means counting dimensions from + the back. Accepted range is [-r, r-1] where r = rank(data). + reduction + Attribute. + Type of reduction to apply: none (default), add, mul, max, min. 'none': + no reduction applied. 'add': reduction using the addition operation. + 'mul': reduction using the multiplication operation.'max': reduction + using the maximum operation.'min': reduction using the minimum + operation. + + Returns + ======= + output : Var + Type T. + Tensor of rank r >= 1 (same rank as input). + + Notes + ===== + Signature: ``ai.onnx@18::ScatterElements``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return _ScatterElements( - _ScatterElements.Attributes( - axis=AttrInt64(axis, name="axis"), - reduction=AttrString(reduction, name="reduction"), - ), _ScatterElements.Inputs( - data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), ).get_output_vars( - data=get_value(data), indices=get_value(indices), updates=get_value(updates), ).output - - -def scatter_nd(data: Var, indices: Var, updates: Var, *, reduction: str = "none", ) -> Var: + return ( + _ScatterElements( + _ScatterElements.Attributes( + axis=AttrInt64(axis, name="axis"), + reduction=AttrString(reduction, name="reduction"), + ), + _ScatterElements.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), + ) + .output + ) + + +def scatter_nd( + data: Var, + indices: Var, + updates: Var, + *, + reduction: str = "none", +) -> Var: r""" -ScatterND takes three inputs ``data`` tensor of rank r >= 1, ``indices`` -tensor of rank q >= 1, and ``updates`` tensor of rank q + r - -indices.shape[-1] - 1. The output of the operation is produced by -creating a copy of the input ``data``, and then updating its value to -values specified by ``updates`` at specific index positions specified by -``indices``. Its output shape is the same as the shape of ``data``. - -``indices`` is an integer tensor. Let k denote indices.shape[-1], the -last dimension in the shape of ``indices``. ``indices`` is treated as a -(q-1)-dimensional tensor of k-tuples, where each k-tuple is a -partial-index into ``data``. Hence, k can be a value at most the rank of -``data``. When k equals rank(data), each update entry specifies an -update to a single element of the tensor. When k is less than rank(data) -each update entry specifies an update to a slice of the tensor. Index -values are allowed to be negative, as per the usual convention for -counting backwards from the end, but are expected in the valid range. - -``updates`` is treated as a (q-1)-dimensional tensor of -replacement-slice-values. Thus, the first (q-1) dimensions of -updates.shape must match the first (q-1) dimensions of indices.shape. -The remaining dimensions of ``updates`` correspond to the dimensions of -the replacement-slice-values. Each replacement-slice-value is a (r-k) -dimensional tensor, corresponding to the trailing (r-k) dimensions of -``data``. Thus, the shape of ``updates`` must equal indices.shape[0:q-1] -++ data.shape[k:r-1], where ++ denotes the concatenation of shapes. - -The ``output`` is calculated via the following equation: - -:: - - output = np.copy(data) - update_indices = indices.shape[:-1] - for idx in np.ndindex(update_indices): - output[indices[idx]] = updates[idx] - -The order of iteration in the above loop is not specified. In -particular, indices should not have duplicate entries: that is, if idx1 -!= idx2, then indices[idx1] != indices[idx2]. This ensures that the -output value does not depend on the iteration order. - -``reduction`` allows specification of an optional reduction operation, -which is applied to all values in ``updates`` tensor into ``output`` at -the specified ``indices``. In cases where ``reduction`` is set to -"none", indices should not have duplicate entries: that is, if idx1 != -idx2, then indices[idx1] != indices[idx2]. This ensures that the output -value does not depend on the iteration order. When ``reduction`` is set -to some reduction function ``f``, ``output`` is calculated as follows: - -:: - - output = np.copy(data) - update_indices = indices.shape[:-1] - for idx in np.ndindex(update_indices): - output[indices[idx]] = f(output[indices[idx]], updates[idx]) - -where the ``f`` is ``+``, ``*``, ``max`` or ``min`` as specified. - -This operator is the inverse of GatherND. - -(Opset 18 change): Adds max/min to the set of allowed reduction ops. - -Example 1: - -:: - - data = [1, 2, 3, 4, 5, 6, 7, 8] - indices = [[4], [3], [1], [7]] - updates = [9, 10, 11, 12] - output = [1, 11, 3, 10, 9, 6, 7, 12] - -Example 2: - -:: - - data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] - indices = [[0], [2]] - updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], - [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] - output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], - [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], - [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], - [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] - -Parameters -========== -data - Type T. - Tensor of rank r >= 1. -indices - Type tensor(int64). - Tensor of rank q >= 1. -updates - Type T. - Tensor of rank q + r - indices_shape[-1] - 1. -reduction - Attribute. - Type of reduction to apply: none (default), add, mul, max, min. 'none': - no reduction applied. 'add': reduction using the addition operation. - 'mul': reduction using the addition operation. 'max': reduction using - the maximum operation.'min': reduction using the minimum operation. - -Returns -======= -output : Var - Type T. - Tensor of rank r >= 1. - -Notes -===== -Signature: ``ai.onnx@18::ScatterND``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + ScatterND takes three inputs ``data`` tensor of rank r >= 1, ``indices`` + tensor of rank q >= 1, and ``updates`` tensor of rank q + r - + indices.shape[-1] - 1. The output of the operation is produced by + creating a copy of the input ``data``, and then updating its value to + values specified by ``updates`` at specific index positions specified by + ``indices``. Its output shape is the same as the shape of ``data``. + + ``indices`` is an integer tensor. Let k denote indices.shape[-1], the + last dimension in the shape of ``indices``. ``indices`` is treated as a + (q-1)-dimensional tensor of k-tuples, where each k-tuple is a + partial-index into ``data``. Hence, k can be a value at most the rank of + ``data``. When k equals rank(data), each update entry specifies an + update to a single element of the tensor. When k is less than rank(data) + each update entry specifies an update to a slice of the tensor. Index + values are allowed to be negative, as per the usual convention for + counting backwards from the end, but are expected in the valid range. + + ``updates`` is treated as a (q-1)-dimensional tensor of + replacement-slice-values. Thus, the first (q-1) dimensions of + updates.shape must match the first (q-1) dimensions of indices.shape. + The remaining dimensions of ``updates`` correspond to the dimensions of + the replacement-slice-values. Each replacement-slice-value is a (r-k) + dimensional tensor, corresponding to the trailing (r-k) dimensions of + ``data``. Thus, the shape of ``updates`` must equal indices.shape[0:q-1] + ++ data.shape[k:r-1], where ++ denotes the concatenation of shapes. + + The ``output`` is calculated via the following equation: + + :: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] = updates[idx] + + The order of iteration in the above loop is not specified. In + particular, indices should not have duplicate entries: that is, if idx1 + != idx2, then indices[idx1] != indices[idx2]. This ensures that the + output value does not depend on the iteration order. + + ``reduction`` allows specification of an optional reduction operation, + which is applied to all values in ``updates`` tensor into ``output`` at + the specified ``indices``. In cases where ``reduction`` is set to + "none", indices should not have duplicate entries: that is, if idx1 != + idx2, then indices[idx1] != indices[idx2]. This ensures that the output + value does not depend on the iteration order. When ``reduction`` is set + to some reduction function ``f``, ``output`` is calculated as follows: + + :: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] = f(output[indices[idx]], updates[idx]) + + where the ``f`` is ``+``, ``*``, ``max`` or ``min`` as specified. + + This operator is the inverse of GatherND. + + (Opset 18 change): Adds max/min to the set of allowed reduction ops. + + Example 1: + + :: + + data = [1, 2, 3, 4, 5, 6, 7, 8] + indices = [[4], [3], [1], [7]] + updates = [9, 10, 11, 12] + output = [1, 11, 3, 10, 9, 6, 7, 12] + + Example 2: + + :: + + data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + indices = [[0], [2]] + updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] + output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + + Parameters + ========== + data + Type T. + Tensor of rank r >= 1. + indices + Type tensor(int64). + Tensor of rank q >= 1. + updates + Type T. + Tensor of rank q + r - indices_shape[-1] - 1. + reduction + Attribute. + Type of reduction to apply: none (default), add, mul, max, min. 'none': + no reduction applied. 'add': reduction using the addition operation. + 'mul': reduction using the addition operation. 'max': reduction using + the maximum operation.'min': reduction using the minimum operation. + + Returns + ======= + output : Var + Type T. + Tensor of rank r >= 1. + + Notes + ===== + Signature: ``ai.onnx@18::ScatterND``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ScatterND( - _ScatterND.Attributes( - reduction=AttrString(reduction, name="reduction"), - ), _ScatterND.Inputs( - data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), ).get_output_vars( - data=get_value(data), indices=get_value(indices), updates=get_value(updates), ).output - - -def split(input: Var, split: Optional[Var] = None, *, axis: int = 0, num_outputs: Optional[int] = None, ) -> Sequence[Var]: + return ( + _ScatterND( + _ScatterND.Attributes( + reduction=AttrString(reduction, name="reduction"), + ), + _ScatterND.Inputs( + data=unwrap_vars(data), + indices=unwrap_vars(indices), + updates=unwrap_vars(updates), + ), + ) + .get_output_vars( + data=get_value(data), + indices=get_value(indices), + updates=get_value(updates), + ) + .output + ) + + +def split( + input: Var, + split: Optional[Var] = None, + *, + axis: int = 0, + num_outputs: Optional[int] = None, +) -> Sequence[Var]: r""" -Split a tensor into a list of tensors, along the specified 'axis'. -Either input 'split' or the attribute 'num_outputs' should be specified, -but not both. If the attribute 'num_outputs' is specified, then the -tensor is split into equal sized parts. If the tensor is not evenly -splittable into ``num_outputs``, the last chunk will be smaller. If the -input 'split' is specified, it indicates the sizes of each output in the -split. - -Parameters -========== -input - Type T. - The tensor to split -split - Type tensor(int64). - Optional length of each output. Values should be >= 0.Sum of the values - must be equal to the dim value at 'axis' specified. -axis - Attribute. - Which axis to split on. A negative value means counting dimensions from - the back. Accepted range is [-rank, rank-1] where r = rank(input). -num_outputs - Attribute. - Number of outputs to split parts of the tensor into. If the tensor is - not evenly splittable the last chunk will be smaller. - -Returns -======= -outputs : Sequence[Var] - Type T. - One or more outputs forming list of tensors after splitting - -Notes -===== -Signature: ``ai.onnx@18::Split``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Split a tensor into a list of tensors, along the specified 'axis'. + Either input 'split' or the attribute 'num_outputs' should be specified, + but not both. If the attribute 'num_outputs' is specified, then the + tensor is split into equal sized parts. If the tensor is not evenly + splittable into ``num_outputs``, the last chunk will be smaller. If the + input 'split' is specified, it indicates the sizes of each output in the + split. + + Parameters + ========== + input + Type T. + The tensor to split + split + Type tensor(int64). + Optional length of each output. Values should be >= 0.Sum of the values + must be equal to the dim value at 'axis' specified. + axis + Attribute. + Which axis to split on. A negative value means counting dimensions from + the back. Accepted range is [-rank, rank-1] where r = rank(input). + num_outputs + Attribute. + Number of outputs to split parts of the tensor into. If the tensor is + not evenly splittable the last chunk will be smaller. + + Returns + ======= + outputs : Sequence[Var] + Type T. + One or more outputs forming list of tensors after splitting + + Notes + ===== + Signature: ``ai.onnx@18::Split``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Split( - _Split.Attributes( - axis=AttrInt64(axis, name="axis"), - num_outputs=AttrInt64.maybe(num_outputs, name="num_outputs"), - ), _Split.Inputs( - input=unwrap_vars(input), split=unwrap_vars(split), ), out_variadic=num_outputs, ).get_output_vars( - input=get_value(input), split=get_value(split), ).outputs + return ( + _Split( + _Split.Attributes( + axis=AttrInt64(axis, name="axis"), + num_outputs=AttrInt64.maybe(num_outputs, name="num_outputs"), + ), + _Split.Inputs( + input=unwrap_vars(input), + split=unwrap_vars(split), + ), + out_variadic=num_outputs, + ) + .get_output_vars( + input=get_value(input), + split=get_value(split), + ) + .outputs + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -2791,4 +3381,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index c8119fd7..8fc23f65 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -1,21 +1,18 @@ +# Copyright (c) QuantCo 2023-2024 +# SPDX-License-Identifier: BSD-3-Clause + # ruff: noqa: E741 -- Allow ambiguous variable name -import typing -import warnings -from dataclasses import dataclass from collections.abc import Iterable, Sequence +from dataclasses import dataclass from typing import ( - Any, Callable, Optional, - Union, ) from typing import cast as typing_cast import numpy as np import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, AttrFloat32, @@ -26,184 +23,354 @@ AttrString, AttrStrings, AttrTensor, - AttrType, ) +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._graph import Graph, subgraph -from spox._internal_op import intro from spox._node import OpType -from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._standard import StandardNode +from spox._type_system import Tensor, Type from spox._value_prop import PropValueType +from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox.opset.ai.onnx.v18 import ( + _DFT, + _GRU, + _LRN, + _LSTM, + _RNN, + _STFT, + _Abs, + _Acos, + _Acosh, + _Add, + _And, + _ArgMax, + _ArgMin, + _Asin, + _Asinh, + _Atan, + _Atanh, + _BatchNormalization, + _Bernoulli, + _BitShift, + _BitwiseAnd, + _BitwiseNot, + _BitwiseOr, + _BitwiseXor, + _BlackmanWindow, + _Ceil, + _Celu, + _CenterCropPad, + _Clip, + _Col2Im, + _Compress, + _Concat, + _ConcatFromSequence, + _ConstantOfShape, + _Conv, + _ConvInteger, + _ConvTranspose, + _Cos, + _Cosh, + _CumSum, + _DepthToSpace, + _Det, + _Div, + _Dropout, + _DynamicQuantizeLinear, + _Einsum, + _Elu, + _Erf, + _Exp, + _Expand, + _EyeLike, + _Flatten, + _Floor, + _Gather, + _GatherElements, + _GatherND, + _Gemm, + _GlobalAveragePool, + _GlobalLpPool, + _GlobalMaxPool, + _Greater, + _GreaterOrEqual, + _GridSample, + _GroupNormalization, + _HammingWindow, + _HannWindow, + _Hardmax, + _HardSigmoid, + _HardSwish, + _InstanceNormalization, + _IsInf, + _IsNaN, + _LayerNormalization, + _LeakyRelu, + _Less, + _LessOrEqual, + _Log, + _LogSoftmax, + _LpNormalization, + _LpPool, + _MatMul, + _MatMulInteger, + _Max, + _MaxPool, + _MaxRoiPool, + _MaxUnpool, + _Mean, + _MeanVarianceNormalization, + _MelWeightMatrix, + _Min, + _Mish, + _Mod, + _Mul, + _Multinomial, + _Neg, + _NegativeLogLikelihoodLoss, + _NonMaxSuppression, + _NonZero, + _Not, + _OneHot, + _Optional, + _OptionalGetElement, + _OptionalHasElement, + _Or, + _Pow, + _PRelu, + _QLinearConv, + _QLinearMatMul, + _RandomNormal, + _RandomNormalLike, + _RandomUniform, + _RandomUniformLike, + _Range, + _Reciprocal, + _ReduceL1, + _ReduceL2, + _ReduceLogSum, + _ReduceLogSumExp, + _ReduceMax, + _ReduceMean, + _ReduceMin, + _ReduceProd, + _ReduceSum, + _ReduceSumSquare, + _Relu, + _ReverseSequence, + _RoiAlign, + _Round, + _ScatterElements, + _ScatterND, + _Selu, + _SequenceAt, + _SequenceConstruct, + _SequenceEmpty, + _SequenceErase, + _SequenceInsert, + _SequenceLength, + _SequenceMap, + _Shrink, + _Sigmoid, + _Sign, + _Sin, + _Sinh, + _Slice, + _Softmax, + _SoftmaxCrossEntropyLoss, + _Softplus, + _Softsign, + _SpaceToDepth, + _Split, + _SplitToSequence, + _Sqrt, + _Squeeze, + _StringNormalizer, + _Sub, + _Sum, + _Tan, + _Tanh, + _TfIdfVectorizer, + _ThresholdedRelu, + _Tile, + _TopK, + _Transpose, + _Trilu, + _Unique, + _Unsqueeze, + _Where, + _Xor, + abs, + acos, + acosh, + add, + and_, + arg_max, + arg_min, + asin, + asinh, + atan, + atanh, + batch_normalization, + bernoulli, + bit_shift, + bitwise_and, + bitwise_not, + bitwise_or, + bitwise_xor, + blackman_window, + ceil, + celu, + center_crop_pad, + clip, + col2_im, + compress, + concat, + concat_from_sequence, + constant_of_shape, + conv, + conv_integer, + conv_transpose, + cos, + cosh, + cumsum, + depth_to_space, + det, + dft, + div, + dropout, + dynamic_quantize_linear, + einsum, + elu, + erf, + exp, + expand, + eye_like, + flatten, + floor, + gather, + gather_elements, + gather_nd, + gemm, + global_average_pool, + global_lp_pool, + global_max_pool, + greater, + greater_or_equal, + grid_sample, + group_normalization, + gru, + hamming_window, + hann_window, + hard_sigmoid, + hard_swish, + hardmax, + instance_normalization, + isinf, + isnan, + layer_normalization, + leaky_relu, + less, + less_or_equal, + log, + log_softmax, + lp_normalization, + lp_pool, + lrn, + lstm, + matmul, + matmul_integer, + max, + max_pool, + max_roi_pool, + max_unpool, + mean, + mean_variance_normalization, + mel_weight_matrix, + min, + mish, + mod, + mul, + multinomial, + neg, + negative_log_likelihood_loss, + non_max_suppression, + non_zero, + not_, + one_hot, + optional, + optional_get_element, + optional_has_element, + or_, + pow, + prelu, + qlinear_conv, + qlinear_matmul, + random_normal, + random_normal_like, + random_uniform, + random_uniform_like, + range, + reciprocal, + reduce_l1, + reduce_l2, + reduce_log_sum, + reduce_log_sum_exp, + reduce_max, + reduce_mean, + reduce_min, + reduce_prod, + reduce_sum, + reduce_sum_square, + relu, + reverse_sequence, + rnn, + roi_align, + round, + scatter_elements, + scatter_nd, + selu, + sequence_at, + sequence_construct, + sequence_empty, + sequence_erase, + sequence_insert, + sequence_length, + sequence_map, + shrink, + sigmoid, + sign, + sin, + sinh, + slice, + softmax, + softmax_cross_entropy_loss, + softplus, + softsign, + space_to_depth, + split, + split_to_sequence, + sqrt, + squeeze, + stft, + string_normalizer, + sub, + sum, + tan, + tanh, + tf_idf_vectorizer, + thresholded_relu, + tile, + top_k, + transpose, + trilu, + unique, + unsqueeze, + where, + xor, +) -from spox.opset.ai.onnx.v18 import _Abs, abs -from spox.opset.ai.onnx.v18 import _Acos, acos -from spox.opset.ai.onnx.v18 import _Acosh, acosh -from spox.opset.ai.onnx.v18 import _Add, add -from spox.opset.ai.onnx.v18 import _And, and_ -from spox.opset.ai.onnx.v18 import _ArgMax, arg_max -from spox.opset.ai.onnx.v18 import _ArgMin, arg_min -from spox.opset.ai.onnx.v18 import _Asin, asin -from spox.opset.ai.onnx.v18 import _Asinh, asinh -from spox.opset.ai.onnx.v18 import _Atan, atan -from spox.opset.ai.onnx.v18 import _Atanh, atanh -from spox.opset.ai.onnx.v18 import _BatchNormalization, batch_normalization -from spox.opset.ai.onnx.v18 import _Bernoulli, bernoulli -from spox.opset.ai.onnx.v18 import _BitShift, bit_shift -from spox.opset.ai.onnx.v18 import _BitwiseAnd, bitwise_and -from spox.opset.ai.onnx.v18 import _BitwiseNot, bitwise_not -from spox.opset.ai.onnx.v18 import _BitwiseOr, bitwise_or -from spox.opset.ai.onnx.v18 import _BitwiseXor, bitwise_xor -from spox.opset.ai.onnx.v18 import _BlackmanWindow, blackman_window -from spox.opset.ai.onnx.v18 import _Ceil, ceil -from spox.opset.ai.onnx.v18 import _Celu, celu -from spox.opset.ai.onnx.v18 import _CenterCropPad, center_crop_pad -from spox.opset.ai.onnx.v18 import _Clip, clip -from spox.opset.ai.onnx.v18 import _Col2Im, col2_im -from spox.opset.ai.onnx.v18 import _Compress, compress -from spox.opset.ai.onnx.v18 import _Concat, concat -from spox.opset.ai.onnx.v18 import _ConcatFromSequence, concat_from_sequence -from spox.opset.ai.onnx.v18 import _ConstantOfShape, constant_of_shape -from spox.opset.ai.onnx.v18 import _Conv, conv -from spox.opset.ai.onnx.v18 import _ConvInteger, conv_integer -from spox.opset.ai.onnx.v18 import _ConvTranspose, conv_transpose -from spox.opset.ai.onnx.v18 import _Cos, cos -from spox.opset.ai.onnx.v18 import _Cosh, cosh -from spox.opset.ai.onnx.v18 import _CumSum, cumsum -from spox.opset.ai.onnx.v18 import _DFT, dft -from spox.opset.ai.onnx.v18 import _DepthToSpace, depth_to_space -from spox.opset.ai.onnx.v18 import _Det, det -from spox.opset.ai.onnx.v18 import _Div, div -from spox.opset.ai.onnx.v18 import _Dropout, dropout -from spox.opset.ai.onnx.v18 import _DynamicQuantizeLinear, dynamic_quantize_linear -from spox.opset.ai.onnx.v18 import _Einsum, einsum -from spox.opset.ai.onnx.v18 import _Elu, elu -from spox.opset.ai.onnx.v18 import _Erf, erf -from spox.opset.ai.onnx.v18 import _Exp, exp -from spox.opset.ai.onnx.v18 import _Expand, expand -from spox.opset.ai.onnx.v18 import _EyeLike, eye_like -from spox.opset.ai.onnx.v18 import _Flatten, flatten -from spox.opset.ai.onnx.v18 import _Floor, floor -from spox.opset.ai.onnx.v18 import _GRU, gru -from spox.opset.ai.onnx.v18 import _Gather, gather -from spox.opset.ai.onnx.v18 import _GatherElements, gather_elements -from spox.opset.ai.onnx.v18 import _GatherND, gather_nd -from spox.opset.ai.onnx.v18 import _Gemm, gemm -from spox.opset.ai.onnx.v18 import _GlobalAveragePool, global_average_pool -from spox.opset.ai.onnx.v18 import _GlobalLpPool, global_lp_pool -from spox.opset.ai.onnx.v18 import _GlobalMaxPool, global_max_pool -from spox.opset.ai.onnx.v18 import _Greater, greater -from spox.opset.ai.onnx.v18 import _GreaterOrEqual, greater_or_equal -from spox.opset.ai.onnx.v18 import _GridSample, grid_sample -from spox.opset.ai.onnx.v18 import _GroupNormalization, group_normalization -from spox.opset.ai.onnx.v18 import _HammingWindow, hamming_window -from spox.opset.ai.onnx.v18 import _HannWindow, hann_window -from spox.opset.ai.onnx.v18 import _HardSigmoid, hard_sigmoid -from spox.opset.ai.onnx.v18 import _HardSwish, hard_swish -from spox.opset.ai.onnx.v18 import _Hardmax, hardmax -from spox.opset.ai.onnx.v18 import _InstanceNormalization, instance_normalization -from spox.opset.ai.onnx.v18 import _IsInf, isinf -from spox.opset.ai.onnx.v18 import _IsNaN, isnan -from spox.opset.ai.onnx.v18 import _LRN, lrn -from spox.opset.ai.onnx.v18 import _LSTM, lstm -from spox.opset.ai.onnx.v18 import _LayerNormalization, layer_normalization -from spox.opset.ai.onnx.v18 import _LeakyRelu, leaky_relu -from spox.opset.ai.onnx.v18 import _Less, less -from spox.opset.ai.onnx.v18 import _LessOrEqual, less_or_equal -from spox.opset.ai.onnx.v18 import _Log, log -from spox.opset.ai.onnx.v18 import _LogSoftmax, log_softmax -from spox.opset.ai.onnx.v18 import _LpNormalization, lp_normalization -from spox.opset.ai.onnx.v18 import _LpPool, lp_pool -from spox.opset.ai.onnx.v18 import _MatMul, matmul -from spox.opset.ai.onnx.v18 import _MatMulInteger, matmul_integer -from spox.opset.ai.onnx.v18 import _Max, max -from spox.opset.ai.onnx.v18 import _MaxPool, max_pool -from spox.opset.ai.onnx.v18 import _MaxRoiPool, max_roi_pool -from spox.opset.ai.onnx.v18 import _MaxUnpool, max_unpool -from spox.opset.ai.onnx.v18 import _Mean, mean -from spox.opset.ai.onnx.v18 import _MeanVarianceNormalization, mean_variance_normalization -from spox.opset.ai.onnx.v18 import _MelWeightMatrix, mel_weight_matrix -from spox.opset.ai.onnx.v18 import _Min, min -from spox.opset.ai.onnx.v18 import _Mish, mish -from spox.opset.ai.onnx.v18 import _Mod, mod -from spox.opset.ai.onnx.v18 import _Mul, mul -from spox.opset.ai.onnx.v18 import _Multinomial, multinomial -from spox.opset.ai.onnx.v18 import _Neg, neg -from spox.opset.ai.onnx.v18 import _NegativeLogLikelihoodLoss, negative_log_likelihood_loss -from spox.opset.ai.onnx.v18 import _NonMaxSuppression, non_max_suppression -from spox.opset.ai.onnx.v18 import _NonZero, non_zero -from spox.opset.ai.onnx.v18 import _Not, not_ -from spox.opset.ai.onnx.v18 import _OneHot, one_hot -from spox.opset.ai.onnx.v18 import _Optional, optional -from spox.opset.ai.onnx.v18 import _OptionalGetElement, optional_get_element -from spox.opset.ai.onnx.v18 import _OptionalHasElement, optional_has_element -from spox.opset.ai.onnx.v18 import _Or, or_ -from spox.opset.ai.onnx.v18 import _PRelu, prelu -from spox.opset.ai.onnx.v18 import _Pow, pow -from spox.opset.ai.onnx.v18 import _QLinearConv, qlinear_conv -from spox.opset.ai.onnx.v18 import _QLinearMatMul, qlinear_matmul -from spox.opset.ai.onnx.v18 import _RNN, rnn -from spox.opset.ai.onnx.v18 import _RandomNormal, random_normal -from spox.opset.ai.onnx.v18 import _RandomNormalLike, random_normal_like -from spox.opset.ai.onnx.v18 import _RandomUniform, random_uniform -from spox.opset.ai.onnx.v18 import _RandomUniformLike, random_uniform_like -from spox.opset.ai.onnx.v18 import _Range, range -from spox.opset.ai.onnx.v18 import _Reciprocal, reciprocal -from spox.opset.ai.onnx.v18 import _ReduceL1, reduce_l1 -from spox.opset.ai.onnx.v18 import _ReduceL2, reduce_l2 -from spox.opset.ai.onnx.v18 import _ReduceLogSum, reduce_log_sum -from spox.opset.ai.onnx.v18 import _ReduceLogSumExp, reduce_log_sum_exp -from spox.opset.ai.onnx.v18 import _ReduceMax, reduce_max -from spox.opset.ai.onnx.v18 import _ReduceMean, reduce_mean -from spox.opset.ai.onnx.v18 import _ReduceMin, reduce_min -from spox.opset.ai.onnx.v18 import _ReduceProd, reduce_prod -from spox.opset.ai.onnx.v18 import _ReduceSum, reduce_sum -from spox.opset.ai.onnx.v18 import _ReduceSumSquare, reduce_sum_square -from spox.opset.ai.onnx.v18 import _Relu, relu -from spox.opset.ai.onnx.v18 import _ReverseSequence, reverse_sequence -from spox.opset.ai.onnx.v18 import _RoiAlign, roi_align -from spox.opset.ai.onnx.v18 import _Round, round -from spox.opset.ai.onnx.v18 import _STFT, stft -from spox.opset.ai.onnx.v18 import _ScatterElements, scatter_elements -from spox.opset.ai.onnx.v18 import _ScatterND, scatter_nd -from spox.opset.ai.onnx.v18 import _Selu, selu -from spox.opset.ai.onnx.v18 import _SequenceAt, sequence_at -from spox.opset.ai.onnx.v18 import _SequenceConstruct, sequence_construct -from spox.opset.ai.onnx.v18 import _SequenceEmpty, sequence_empty -from spox.opset.ai.onnx.v18 import _SequenceErase, sequence_erase -from spox.opset.ai.onnx.v18 import _SequenceInsert, sequence_insert -from spox.opset.ai.onnx.v18 import _SequenceLength, sequence_length -from spox.opset.ai.onnx.v18 import _SequenceMap, sequence_map -from spox.opset.ai.onnx.v18 import _Shrink, shrink -from spox.opset.ai.onnx.v18 import _Sigmoid, sigmoid -from spox.opset.ai.onnx.v18 import _Sign, sign -from spox.opset.ai.onnx.v18 import _Sin, sin -from spox.opset.ai.onnx.v18 import _Sinh, sinh -from spox.opset.ai.onnx.v18 import _Slice, slice -from spox.opset.ai.onnx.v18 import _Softmax, softmax -from spox.opset.ai.onnx.v18 import _SoftmaxCrossEntropyLoss, softmax_cross_entropy_loss -from spox.opset.ai.onnx.v18 import _Softplus, softplus -from spox.opset.ai.onnx.v18 import _Softsign, softsign -from spox.opset.ai.onnx.v18 import _SpaceToDepth, space_to_depth -from spox.opset.ai.onnx.v18 import _Split, split -from spox.opset.ai.onnx.v18 import _SplitToSequence, split_to_sequence -from spox.opset.ai.onnx.v18 import _Sqrt, sqrt -from spox.opset.ai.onnx.v18 import _Squeeze, squeeze -from spox.opset.ai.onnx.v18 import _StringNormalizer, string_normalizer -from spox.opset.ai.onnx.v18 import _Sub, sub -from spox.opset.ai.onnx.v18 import _Sum, sum -from spox.opset.ai.onnx.v18 import _Tan, tan -from spox.opset.ai.onnx.v18 import _Tanh, tanh -from spox.opset.ai.onnx.v18 import _TfIdfVectorizer, tf_idf_vectorizer -from spox.opset.ai.onnx.v18 import _ThresholdedRelu, thresholded_relu -from spox.opset.ai.onnx.v18 import _Tile, tile -from spox.opset.ai.onnx.v18 import _TopK, top_k -from spox.opset.ai.onnx.v18 import _Transpose, transpose -from spox.opset.ai.onnx.v18 import _Trilu, trilu -from spox.opset.ai.onnx.v18 import _Unique, unique -from spox.opset.ai.onnx.v18 import _Unsqueeze, unsqueeze -from spox.opset.ai.onnx.v18 import _Where, where -from spox.opset.ai.onnx.v18 import _Xor, xor class _AveragePool(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -229,6 +396,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Cast(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -249,6 +417,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _CastLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -269,6 +438,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Constant(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -287,7 +457,9 @@ class Outputs(BaseOutputs): output: VarInfo def propagate_values(self, initializers) -> dict[str, PropValueType]: - ((key, raw),) = ((k, v.value) for k, v in self.attrs.get_fields().items() if v is not None) + ((key, raw),) = ( + (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None + ) if key == "value": value = raw elif key == "value_float": @@ -305,14 +477,18 @@ def propagate_values(self, initializers) -> dict[str, PropValueType]: elif key == "sparse_value": return {} else: - raise RuntimeError(f"Could not extract the set Constant value attribute, got: {key}") + raise RuntimeError( + f"Could not extract the set Constant value attribute, got: {key}" + ) return {"output": value} + op_type = OpType("Constant", "", 19) attrs: Attributes inputs: BaseInputs outputs: Outputs + class _DeformConv(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -341,6 +517,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _DequantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -362,6 +539,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Equal(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -382,6 +560,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Identity(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -401,6 +580,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _If(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -421,6 +601,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Loop(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -442,6 +623,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Pad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -464,6 +646,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _QuantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -486,6 +669,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Reshape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -506,6 +690,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Resize(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -536,6 +721,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Scan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -560,6 +746,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Shape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -580,6 +767,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Size(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -599,1655 +787,1964 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs -def average_pool(X: Var, *, auto_pad: str = "NOTSET", ceil_mode: int = 0, count_include_pad: int = 0, dilations: Optional[Iterable[int]] = None, kernel_shape: Iterable[int], pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + +def average_pool( + X: Var, + *, + auto_pad: str = "NOTSET", + ceil_mode: int = 0, + count_include_pad: int = 0, + dilations: Optional[Iterable[int]] = None, + kernel_shape: Iterable[int], + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: r""" -AveragePool consumes an input tensor X and applies average pooling -across the tensor according to kernel sizes, stride sizes, and pad -lengths. average pooling consisting of computing the average on all -values of a subset of the input tensor according to the kernel size and -downsampling the data into the output tensor Y for further processing. -The output spatial shape is calculated differently depending on whether -explicit padding is used, where pads is employed, or auto padding is -used, where auto_pad is utilized. With explicit padding -(https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): - -:: - - output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) - -or - -:: - - output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) - -if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis -``i``. Sliding windows that would start in the right padded region are -ignored. - -``auto_pad`` is a DEPRECATED attribute. If you are using them currently, -the output spatial shape will be following when ceil_mode is enabled: - -:: - - VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) - -or when ceil_mode is disabled -(https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): - -:: - - VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 - SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 - -And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: - -:: - - pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] - -The output of each pooling window is divided by the number of elements -(exclude pad when attribute count_include_pad is zero). - -Parameters -========== -X - Type T. - Input data tensor from the previous operator; dimensions for image case - are (N x C x H x W), where N is the batch size, C is the number of - channels, and H and W are the height and the width of the data. For non - image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), - where N is the batch size. Optionally, if dimension denotation is in - effect, the operation expects the input data tensor to arrive with the - dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, - DATA_FEATURE ...]. -auto_pad - Attribute. - auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where - default value is NOTSET, which means explicit padding is used. - SAME_UPPER or SAME_LOWER mean pad the input so that - ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis - ``i``. The padding is split between the two sides equally or almost - equally (depending on whether it is even or odd). In case the padding is - an odd number, the extra padding is added at the end for SAME_UPPER and - at the beginning for SAME_LOWER. -ceil_mode - Attribute. - Whether to use ceil or floor (default) to compute the output shape. -count_include_pad - Attribute. - Whether include pad pixels when calculating values for the edges. - Default is 0, doesn't count include pad. -dilations - Attribute. - Dilation value along each spatial axis of filter. If not present, the - dilation defaults to 1 along each spatial axis. -kernel_shape - Attribute. - The size of the kernel along each axis. -pads - Attribute. - Padding for the beginning and ending along each spatial axis, it can - take any value greater than or equal to 0. The value represent the - number of pixels added to the beginning and end part of the - corresponding axis. ``pads`` format should be as follow [x1_begin, - x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels - added at the beginning of axis ``i`` and xi_end, the number of pixels - added at the end of axis ``i``. This attribute cannot be used - simultaneously with auto_pad attribute. If not present, the padding - defaults to 0 along start and end of each spatial axis. -strides - Attribute. - Stride along each spatial axis. If not present, the stride defaults to 1 - along each spatial axis. - -Returns -======= -Y : Var - Type T. - Output data tensor from average or max pooling across the input tensor. - Dimensions will vary based on various kernel, stride, and pad sizes. - Floor value of the dimension is used - -Notes -===== -Signature: ``ai.onnx@19::AveragePool``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + AveragePool consumes an input tensor X and applies average pooling + across the tensor according to kernel sizes, stride sizes, and pad + lengths. average pooling consisting of computing the average on all + values of a subset of the input tensor according to the kernel size and + downsampling the data into the output tensor Y for further processing. + The output spatial shape is calculated differently depending on whether + explicit padding is used, where pads is employed, or auto padding is + used, where auto_pad is utilized. With explicit padding + (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d): + + :: + + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + + or + + :: + + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) + + if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis + ``i``. Sliding windows that would start in the right padded region are + ignored. + + ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, + the output spatial shape will be following when ceil_mode is enabled: + + :: + + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + + or when ceil_mode is disabled + (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D): + + :: + + VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i]) + 1 + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1 + + And pad shape will be following if ``SAME_UPPER`` or ``SAME_LOWER``: + + :: + + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + + The output of each pooling window is divided by the number of elements + (exclude pad when attribute count_include_pad is zero). + + Parameters + ========== + X + Type T. + Input data tensor from the previous operator; dimensions for image case + are (N x C x H x W), where N is the batch size, C is the number of + channels, and H and W are the height and the width of the data. For non + image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), + where N is the batch size. Optionally, if dimension denotation is in + effect, the operation expects the input data tensor to arrive with the + dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, + DATA_FEATURE ...]. + auto_pad + Attribute. + auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where + default value is NOTSET, which means explicit padding is used. + SAME_UPPER or SAME_LOWER mean pad the input so that + ``output_shape[i] = ceil(input_shape[i] / strides[i])`` for each axis + ``i``. The padding is split between the two sides equally or almost + equally (depending on whether it is even or odd). In case the padding is + an odd number, the extra padding is added at the end for SAME_UPPER and + at the beginning for SAME_LOWER. + ceil_mode + Attribute. + Whether to use ceil or floor (default) to compute the output shape. + count_include_pad + Attribute. + Whether include pad pixels when calculating values for the edges. + Default is 0, doesn't count include pad. + dilations + Attribute. + Dilation value along each spatial axis of filter. If not present, the + dilation defaults to 1 along each spatial axis. + kernel_shape + Attribute. + The size of the kernel along each axis. + pads + Attribute. + Padding for the beginning and ending along each spatial axis, it can + take any value greater than or equal to 0. The value represent the + number of pixels added to the beginning and end part of the + corresponding axis. ``pads`` format should be as follow [x1_begin, + x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels + added at the beginning of axis ``i`` and xi_end, the number of pixels + added at the end of axis ``i``. This attribute cannot be used + simultaneously with auto_pad attribute. If not present, the padding + defaults to 0 along start and end of each spatial axis. + strides + Attribute. + Stride along each spatial axis. If not present, the stride defaults to 1 + along each spatial axis. + + Returns + ======= + Y : Var + Type T. + Output data tensor from average or max pooling across the input tensor. + Dimensions will vary based on various kernel, stride, and pad sizes. + Floor value of the dimension is used + + Notes + ===== + Signature: ``ai.onnx@19::AveragePool``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _AveragePool( - _AveragePool.Attributes( - auto_pad=AttrString(auto_pad, name="auto_pad"), - ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), - count_include_pad=AttrInt64(count_include_pad, name="count_include_pad"), - dilations=AttrInt64s.maybe(dilations, name="dilations"), - kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _AveragePool.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def cast(input: Var, *, saturate: int = 1, to: npt.DTypeLike, ) -> Var: + return ( + _AveragePool( + _AveragePool.Attributes( + auto_pad=AttrString(auto_pad, name="auto_pad"), + ceil_mode=AttrInt64(ceil_mode, name="ceil_mode"), + count_include_pad=AttrInt64( + count_include_pad, name="count_include_pad" + ), + dilations=AttrInt64s.maybe(dilations, name="dilations"), + kernel_shape=AttrInt64s(kernel_shape, name="kernel_shape"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _AveragePool.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def cast( + input: Var, + *, + saturate: int = 1, + to: npt.DTypeLike, +) -> Var: r""" -The operator casts the elements of a given input tensor to a data type -specified by the 'to' argument and returns an output tensor of the same -size in the converted type. The 'to' argument must be one of the data -types specified in the 'DataType' enum field in the TensorProto message. - -Casting from string tensor in plain (e.g., "3.14" and "1000") and -scientific numeric representations (e.g., "1e-5" and "1E8") to float -types is supported. For example, converting string "100.5" to an integer -may yield result 100. There are some string literals reserved for -special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are -positive infinity, negative infinity, and not-a-number, respectively. -Any string which can exactly match "+INF" in a case-insensitive way -would be mapped to positive infinite. Similarly, this case-insensitive -rule is applied to "INF" and "NaN". When casting from numeric tensors to -string tensors, plain floating-point representation (such as -"314.15926") would be used. Converting non-numerical-literal string such -as "Hello World!" is an undefined behavior. Cases of converting string -representing floating-point arithmetic value, such as "2.718", to INT is -an undefined behavior. - -Conversion from a numerical type to any numerical type is always -allowed. User must be aware of precision loss and value change caused by -range difference between two types. For example, a 64-bit float -3.1415926459 may be round to a 32-bit float 3.141592. Similarly, -converting an integer 36 to Boolean may produce 1 because we truncate -bits which can't be stored in the targeted type. - -In more detail, the conversion among numerical types should follow these -rules if the destination type is not a float 8 type. - -- Casting from floating point to: - - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. - -- Casting from fixed point to: - - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. - -- Casting from bool to: - - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. - -Float 8 type were introduced to speed up the training of deep models. By -default the conversion of a float *x* obeys to the following rules. -``[x]`` means the value rounded to the target mantissa width. - -============== =========== ======== ======== ======== -x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ -============== =========== ======== ======== ======== -0 0 0 0 0 --0 -0 0 -0 0 -NaN NaN NaN NaN NaN -+/- Inf +/- FLT_MAX NaN FLT_MAX NaN -[x] > FLT_MAX FLT_MAX FLT_MAX FLT_MAX FLT_MAX -[x] < -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -else RNE RNE RNE RNE -============== =========== ======== ======== ======== - -The behavior changes if the parameter 'saturate' is set to False. The -rules then become: - -============== ====== ======== ======= ======== -x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ -============== ====== ======== ======= ======== -0 0 0 0 0 --0 -0 0 -0 0 -NaN NaN NaN NaN NaN -+/- Inf NaN NaN +/- Inf NaN -[x] > FLT_MAX NaN NaN Inf NaN -[x] < -FLT_MAX NaN NaN -Inf NaN -else RNE RNE RNE RNE -============== ====== ======== ======= ======== - -Parameters -========== -input - Type T1. - Input tensor to be cast. -saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. All cases are fully described in two tables - inserted in the operator description. -to - Attribute. - The data type to which the elements of the input tensor are cast. - Strictly must be one of the types from DataType enum in TensorProto - -Returns -======= -output : Var - Type T2. - Output tensor with the same shape as input with type specified by the - 'to' argument - -Notes -===== -Signature: ``ai.onnx@19::Cast``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + The operator casts the elements of a given input tensor to a data type + specified by the 'to' argument and returns an output tensor of the same + size in the converted type. The 'to' argument must be one of the data + types specified in the 'DataType' enum field in the TensorProto message. + + Casting from string tensor in plain (e.g., "3.14" and "1000") and + scientific numeric representations (e.g., "1e-5" and "1E8") to float + types is supported. For example, converting string "100.5" to an integer + may yield result 100. There are some string literals reserved for + special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are + positive infinity, negative infinity, and not-a-number, respectively. + Any string which can exactly match "+INF" in a case-insensitive way + would be mapped to positive infinite. Similarly, this case-insensitive + rule is applied to "INF" and "NaN". When casting from numeric tensors to + string tensors, plain floating-point representation (such as + "314.15926") would be used. Converting non-numerical-literal string such + as "Hello World!" is an undefined behavior. Cases of converting string + representing floating-point arithmetic value, such as "2.718", to INT is + an undefined behavior. + + Conversion from a numerical type to any numerical type is always + allowed. User must be aware of precision loss and value change caused by + range difference between two types. For example, a 64-bit float + 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, + converting an integer 36 to Boolean may produce 1 because we truncate + bits which can't be stored in the targeted type. + + In more detail, the conversion among numerical types should follow these + rules if the destination type is not a float 8 type. + + - Casting from floating point to: + + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. + + - Casting from fixed point to: + + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. + + - Casting from bool to: + + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. + + Float 8 type were introduced to speed up the training of deep models. By + default the conversion of a float *x* obeys to the following rules. + ``[x]`` means the value rounded to the target mantissa width. + + ============== =========== ======== ======== ======== + x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ + ============== =========== ======== ======== ======== + 0 0 0 0 0 + -0 -0 0 -0 0 + NaN NaN NaN NaN NaN + +/- Inf +/- FLT_MAX NaN FLT_MAX NaN + [x] > FLT_MAX FLT_MAX FLT_MAX FLT_MAX FLT_MAX + [x] < -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX + else RNE RNE RNE RNE + ============== =========== ======== ======== ======== + + The behavior changes if the parameter 'saturate' is set to False. The + rules then become: + + ============== ====== ======== ======= ======== + x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ + ============== ====== ======== ======= ======== + 0 0 0 0 0 + -0 -0 0 -0 0 + NaN NaN NaN NaN NaN + +/- Inf NaN NaN +/- Inf NaN + [x] > FLT_MAX NaN NaN Inf NaN + [x] < -FLT_MAX NaN NaN -Inf NaN + else RNE RNE RNE RNE + ============== ====== ======== ======= ======== + + Parameters + ========== + input + Type T1. + Input tensor to be cast. + saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. All cases are fully described in two tables + inserted in the operator description. + to + Attribute. + The data type to which the elements of the input tensor are cast. + Strictly must be one of the types from DataType enum in TensorProto + + Returns + ======= + output : Var + Type T2. + Output tensor with the same shape as input with type specified by the + 'to' argument + + Notes + ===== + Signature: ``ai.onnx@19::Cast``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Cast( - _Cast.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - to=AttrDtype(to, name="to"), - ), _Cast.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Cast( + _Cast.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + to=AttrDtype(to, name="to"), + ), + _Cast.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def cast_like(input: Var, target_type: Var, *, saturate: int = 1, ) -> Var: +def cast_like( + input: Var, + target_type: Var, + *, + saturate: int = 1, +) -> Var: r""" -The operator casts the elements of a given input tensor (the first -input) to the same data type as the elements of the second input tensor. -See documentation of the Cast operator for further details. - -Parameters -========== -input - Type T1. - Input tensor to be cast. -target_type - Type T2. - The (first) input tensor will be cast to produce a tensor of the same - type as this (second input) tensor. -saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. Please refer to operator Cast description for - further details. - -Returns -======= -output : Var - Type T2. - Output tensor produced by casting the first input tensor to have the - same type as the second input tensor. - -Notes -===== -Signature: ``ai.onnx@19::CastLike``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + The operator casts the elements of a given input tensor (the first + input) to the same data type as the elements of the second input tensor. + See documentation of the Cast operator for further details. + + Parameters + ========== + input + Type T1. + Input tensor to be cast. + target_type + Type T2. + The (first) input tensor will be cast to produce a tensor of the same + type as this (second input) tensor. + saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. Please refer to operator Cast description for + further details. + + Returns + ======= + output : Var + Type T2. + Output tensor produced by casting the first input tensor to have the + same type as the second input tensor. + + Notes + ===== + Signature: ``ai.onnx@19::CastLike``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _CastLike( - _CastLike.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - ), _CastLike.Inputs( - input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), ).get_output_vars( - input=get_value(input), target_type=get_value(target_type), ).output + return ( + _CastLike( + _CastLike.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + ), + _CastLike.Inputs( + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), + ), + ) + .get_output_vars( + input=get_value(input), + target_type=get_value(target_type), + ) + .output + ) -def constant(*, value: Optional[np.ndarray] = None, value_float: Optional[float] = None, value_floats: Optional[Iterable[float]] = None, value_int: Optional[int] = None, value_ints: Optional[Iterable[int]] = None, value_string: Optional[str] = None, value_strings: Optional[Iterable[str]] = None, ) -> Var: +def constant( + *, + value: Optional[np.ndarray] = None, + value_float: Optional[float] = None, + value_floats: Optional[Iterable[float]] = None, + value_int: Optional[int] = None, + value_ints: Optional[Iterable[int]] = None, + value_string: Optional[str] = None, + value_strings: Optional[Iterable[str]] = None, +) -> Var: r""" -This operator produces a constant tensor. Exactly one of the provided -attributes, either value, sparse_value, or value\_\* must be specified. - -Parameters -========== -sparse_value - Attribute. - The value for the elements of the output tensor in sparse format. -value - Attribute. - The value for the elements of the output tensor. -value_float - Attribute. - The value for the sole element for the scalar, float32, output tensor. -value_floats - Attribute. - The values for the elements for the 1D, float32, output tensor. -value_int - Attribute. - The value for the sole element for the scalar, int64, output tensor. -value_ints - Attribute. - The values for the elements for the 1D, int64, output tensor. -value_string - Attribute. - The value for the sole element for the scalar, UTF-8 string, output - tensor. -value_strings - Attribute. - The values for the elements for the 1D, UTF-8 string, output tensor. - -Returns -======= -output : Var - Type T. - Output tensor containing the same value of the provided tensor. - -Notes -===== -Signature: ``ai.onnx@19::Constant``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + This operator produces a constant tensor. Exactly one of the provided + attributes, either value, sparse_value, or value\_\* must be specified. + + Parameters + ========== + sparse_value + Attribute. + The value for the elements of the output tensor in sparse format. + value + Attribute. + The value for the elements of the output tensor. + value_float + Attribute. + The value for the sole element for the scalar, float32, output tensor. + value_floats + Attribute. + The values for the elements for the 1D, float32, output tensor. + value_int + Attribute. + The value for the sole element for the scalar, int64, output tensor. + value_ints + Attribute. + The values for the elements for the 1D, int64, output tensor. + value_string + Attribute. + The value for the sole element for the scalar, UTF-8 string, output + tensor. + value_strings + Attribute. + The values for the elements for the 1D, UTF-8 string, output tensor. + + Returns + ======= + output : Var + Type T. + Output tensor containing the same value of the provided tensor. + + Notes + ===== + Signature: ``ai.onnx@19::Constant``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), _Constant.Inputs( - ), ).get_output_vars( - ).output - - -def deform_conv(X: Var, W: Var, offset: Var, B: Optional[Var] = None, mask: Optional[Var] = None, *, dilations: Optional[Iterable[int]] = None, group: int = 1, kernel_shape: Optional[Iterable[int]] = None, offset_group: int = 1, pads: Optional[Iterable[int]] = None, strides: Optional[Iterable[int]] = None, ) -> Var: + return ( + _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), + _Constant.Inputs(), + ) + .get_output_vars() + .output + ) + + +def deform_conv( + X: Var, + W: Var, + offset: Var, + B: Optional[Var] = None, + mask: Optional[Var] = None, + *, + dilations: Optional[Iterable[int]] = None, + group: int = 1, + kernel_shape: Optional[Iterable[int]] = None, + offset_group: int = 1, + pads: Optional[Iterable[int]] = None, + strides: Optional[Iterable[int]] = None, +) -> Var: r""" -Performs deformable convolution as described in -https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168. -This operator specification supports the general N-D case. Note that -most common use cases have 2D or 3D data. - -Parameters -========== -X - Type T. - Input data tensor. For 2D image data, it has shape (N, C, H, W) where N - is the batch size, C is the number of input channels, and H and W are - the height and width. In general, the shape is (N, C, D1, D2, ... , Dn) - for n-dimensional data, where D1 to Dn are the spatial dimension sizes. - Most common use cases have n = 2 or 3. -W - Type T. - Weight tensor that will be used in the convolutions. It has shape (oC, - C/group, kH, kW), where oC is the number of output channels and kH and - kW are the kernel height and width. For more than 2 dimensions, it has - shape (oC, C/group, k1, k2, ... , kn). -offset - Type T. - Offset tensor denoting the offset for the sampling locations in the - convolution kernel. It has shape (N, offset_group \* kH \* kW \* 2, oH, - oW) for 2D data or (N, offset_group \* k1 \* k2 \* ... \* kn \* n, o1, - o2, ... , on) for nD data. Use linear interpolationfor fractional offset - values. Sampling locations outside of the padded input tensor gives - zero. -B - Type T. - Optional 1D bias of length oC to be added to the convolution. Default is - a tensor of zeros. -mask - Type T. - The mask tensor to be applied to each position in the convolution - kernel. It has shape (N, offset_group \* kH \* kW, oH, oW) for 2D data - or (N, offset_group \* k1 \* k2 \* ... \* kn \* n, o1, o2, ... , on) for - nD data. Default is a tensor of ones. -dilations - Attribute. - Dilation value along each spatial axis of the kernel. Default is 1 along - each axis. -group - Attribute. - Number of groups the input and output channels, C and oC, are divided - into. C and oC must both be divisible by group. Default is 1. -kernel_shape - Attribute. - Shape of the convolution kernel. If not present, it is inferred from the - shape of input W. -offset_group - Attribute. - Number of groups of offset. C must be divisible by offset_group. Default - is 1. -pads - Attribute. - Padding for the beginning and end along each spatial axis. The values - represent the number of pixels added to the beginning and end of the - corresponding axis and can take any nonnegative value. The format should - be as follows: [x1_begin, x2_begin, ..., x1_end, x2_end, ...], where - xi_begin is the number of pixels added at the beginning of axis ``i`` - and xi_end is the number of pixels added at the end of axis ``i``. - Default is 0 along each axis. -strides - Attribute. - Stride along each spatial axis. Default is 1 along each axis. - -Returns -======= -Y : Var - Type T. - Output data tensor that contains the result of convolution. It has shape - (N, oC, oH, oW) for 2D data or (N, oC, o1, o2, ..., on) for nD data - -Notes -===== -Signature: ``ai.onnx@19::DeformConv``. - -Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + Performs deformable convolution as described in + https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168. + This operator specification supports the general N-D case. Note that + most common use cases have 2D or 3D data. + + Parameters + ========== + X + Type T. + Input data tensor. For 2D image data, it has shape (N, C, H, W) where N + is the batch size, C is the number of input channels, and H and W are + the height and width. In general, the shape is (N, C, D1, D2, ... , Dn) + for n-dimensional data, where D1 to Dn are the spatial dimension sizes. + Most common use cases have n = 2 or 3. + W + Type T. + Weight tensor that will be used in the convolutions. It has shape (oC, + C/group, kH, kW), where oC is the number of output channels and kH and + kW are the kernel height and width. For more than 2 dimensions, it has + shape (oC, C/group, k1, k2, ... , kn). + offset + Type T. + Offset tensor denoting the offset for the sampling locations in the + convolution kernel. It has shape (N, offset_group \* kH \* kW \* 2, oH, + oW) for 2D data or (N, offset_group \* k1 \* k2 \* ... \* kn \* n, o1, + o2, ... , on) for nD data. Use linear interpolationfor fractional offset + values. Sampling locations outside of the padded input tensor gives + zero. + B + Type T. + Optional 1D bias of length oC to be added to the convolution. Default is + a tensor of zeros. + mask + Type T. + The mask tensor to be applied to each position in the convolution + kernel. It has shape (N, offset_group \* kH \* kW, oH, oW) for 2D data + or (N, offset_group \* k1 \* k2 \* ... \* kn \* n, o1, o2, ... , on) for + nD data. Default is a tensor of ones. + dilations + Attribute. + Dilation value along each spatial axis of the kernel. Default is 1 along + each axis. + group + Attribute. + Number of groups the input and output channels, C and oC, are divided + into. C and oC must both be divisible by group. Default is 1. + kernel_shape + Attribute. + Shape of the convolution kernel. If not present, it is inferred from the + shape of input W. + offset_group + Attribute. + Number of groups of offset. C must be divisible by offset_group. Default + is 1. + pads + Attribute. + Padding for the beginning and end along each spatial axis. The values + represent the number of pixels added to the beginning and end of the + corresponding axis and can take any nonnegative value. The format should + be as follows: [x1_begin, x2_begin, ..., x1_end, x2_end, ...], where + xi_begin is the number of pixels added at the beginning of axis ``i`` + and xi_end is the number of pixels added at the end of axis ``i``. + Default is 0 along each axis. + strides + Attribute. + Stride along each spatial axis. Default is 1 along each axis. + + Returns + ======= + Y : Var + Type T. + Output data tensor that contains the result of convolution. It has shape + (N, oC, oH, oW) for 2D data or (N, oC, o1, o2, ..., on) for nD data + + Notes + ===== + Signature: ``ai.onnx@19::DeformConv``. + + Type constraints: + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _DeformConv( - _DeformConv.Attributes( - dilations=AttrInt64s.maybe(dilations, name="dilations"), - group=AttrInt64(group, name="group"), - kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), - offset_group=AttrInt64(offset_group, name="offset_group"), - pads=AttrInt64s.maybe(pads, name="pads"), - strides=AttrInt64s.maybe(strides, name="strides"), - ), _DeformConv.Inputs( - X=unwrap_vars(X), W=unwrap_vars(W), offset=unwrap_vars(offset), B=unwrap_vars(B), mask=unwrap_vars(mask), ), ).get_output_vars( - X=get_value(X), W=get_value(W), offset=get_value(offset), B=get_value(B), mask=get_value(mask), ).Y - - -def dequantize_linear(x: Var, x_scale: Var, x_zero_point: Optional[Var] = None, *, axis: int = 1, ) -> Var: + return ( + _DeformConv( + _DeformConv.Attributes( + dilations=AttrInt64s.maybe(dilations, name="dilations"), + group=AttrInt64(group, name="group"), + kernel_shape=AttrInt64s.maybe(kernel_shape, name="kernel_shape"), + offset_group=AttrInt64(offset_group, name="offset_group"), + pads=AttrInt64s.maybe(pads, name="pads"), + strides=AttrInt64s.maybe(strides, name="strides"), + ), + _DeformConv.Inputs( + X=unwrap_vars(X), + W=unwrap_vars(W), + offset=unwrap_vars(offset), + B=unwrap_vars(B), + mask=unwrap_vars(mask), + ), + ) + .get_output_vars( + X=get_value(X), + W=get_value(W), + offset=get_value(offset), + B=get_value(B), + mask=get_value(mask), + ) + .Y + ) + + +def dequantize_linear( + x: Var, + x_scale: Var, + x_zero_point: Optional[Var] = None, + *, + axis: int = 1, +) -> Var: r""" -The linear dequantization operator. It consumes a quantized tensor, a -scale, and a zero point to compute the full precision tensor. The -dequantization formula is ``y = (x - x_zero_point) * x_scale``. -``x_scale`` and ``x_zero_point`` must have same shape, and can be either -a scalar for per-tensor / per layer quantization, or a 1-D tensor for -per-axis quantization. ``x_zero_point`` and ``x`` must have same type. -``x`` and ``y`` must have same shape. In the case of dequantizing int32, -there's no zero point (zero point is supposed to be 0). ``zero-point`` -is usually not used in the case of float8e4m3fn, float8e4m3fnuz, -float8e5m2, float8e5m2fnuz quantization, but the dequantization formula -remains the same for consistency and 'x_scale' still determines the -output type. - -Parameters -========== -x - Type T1. - N-D quantized input tensor to be de-quantized. -x_scale - Type T2. - Scale for input 'x'. It can be a scalar, which means a per-tensor/layer - dequantization, or a 1-D tensor for per-axis dequantization. -x_zero_point - Type T1. - Zero point for input 'x'. Shape must match x_scale. It's optional. Zero - point is 0 when it's not specified. -axis - Attribute. - (Optional) The axis of the dequantizing dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). - -Returns -======= -y : Var - Type T2. - N-D full precision output tensor. It has same shape as input 'x'. - -Notes -===== -Signature: ``ai.onnx@19::DequantizeLinear``. - -Type constraints: - - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` + The linear dequantization operator. It consumes a quantized tensor, a + scale, and a zero point to compute the full precision tensor. The + dequantization formula is ``y = (x - x_zero_point) * x_scale``. + ``x_scale`` and ``x_zero_point`` must have same shape, and can be either + a scalar for per-tensor / per layer quantization, or a 1-D tensor for + per-axis quantization. ``x_zero_point`` and ``x`` must have same type. + ``x`` and ``y`` must have same shape. In the case of dequantizing int32, + there's no zero point (zero point is supposed to be 0). ``zero-point`` + is usually not used in the case of float8e4m3fn, float8e4m3fnuz, + float8e5m2, float8e5m2fnuz quantization, but the dequantization formula + remains the same for consistency and 'x_scale' still determines the + output type. + + Parameters + ========== + x + Type T1. + N-D quantized input tensor to be de-quantized. + x_scale + Type T2. + Scale for input 'x'. It can be a scalar, which means a per-tensor/layer + dequantization, or a 1-D tensor for per-axis dequantization. + x_zero_point + Type T1. + Zero point for input 'x'. Shape must match x_scale. It's optional. Zero + point is 0 when it's not specified. + axis + Attribute. + (Optional) The axis of the dequantizing dimension of the input tensor. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + + Returns + ======= + y : Var + Type T2. + N-D full precision output tensor. It has same shape as input 'x'. + + Notes + ===== + Signature: ``ai.onnx@19::DequantizeLinear``. + + Type constraints: + - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - return _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _DequantizeLinear.Inputs( - x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), ).get_output_vars( - x=get_value(x), x_scale=get_value(x_scale), x_zero_point=get_value(x_zero_point), ).y + return ( + _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _DequantizeLinear.Inputs( + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + ) + .y + ) -def equal(A: Var, B: Var, ) -> Var: +def equal( + A: Var, + B: Var, +) -> Var: r""" -Returns the tensor resulted from performing the ``equal`` logical -operation elementwise on the input tensors ``A`` and ``B`` (with -Numpy-style broadcasting support). - -This operator supports **multidirectional (i.e., Numpy-style) -broadcasting**; for more details please check `the -doc `__. - -Parameters -========== -A - Type T. - First input operand for the logical operator. -B - Type T. - Second input operand for the logical operator. - -Returns -======= -C : Var - Type T1. - Result tensor. - -Notes -===== -Signature: ``ai.onnx@19::Equal``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(bool)` + Returns the tensor resulted from performing the ``equal`` logical + operation elementwise on the input tensors ``A`` and ``B`` (with + Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) + broadcasting**; for more details please check `the + doc `__. + + Parameters + ========== + A + Type T. + First input operand for the logical operator. + B + Type T. + Second input operand for the logical operator. + + Returns + ======= + C : Var + Type T1. + Result tensor. + + Notes + ===== + Signature: ``ai.onnx@19::Equal``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(bool)` """ - return _Equal( - _Equal.Attributes( - ), _Equal.Inputs( - A=unwrap_vars(A), B=unwrap_vars(B), ), ).get_output_vars( - A=get_value(A), B=get_value(B), ).C + return ( + _Equal( + _Equal.Attributes(), + _Equal.Inputs( + A=unwrap_vars(A), + B=unwrap_vars(B), + ), + ) + .get_output_vars( + A=get_value(A), + B=get_value(B), + ) + .C + ) -def identity(input: Var, ) -> Var: +def identity( + input: Var, +) -> Var: r""" -Identity operator - -Parameters -========== -input - Type V. - Input tensor - -Returns -======= -output : Var - Type V. - Tensor to copy input into. - -Notes -===== -Signature: ``ai.onnx@19::Identity``. - -Type constraints: - - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Identity operator + + Parameters + ========== + input + Type V. + Input tensor + + Returns + ======= + output : Var + Type V. + Tensor to copy input into. + + Notes + ===== + Signature: ``ai.onnx@19::Identity``. + + Type constraints: + - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Identity( - _Identity.Attributes( - ), _Identity.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Identity( + _Identity.Attributes(), + _Identity.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def if_(cond: Var, *, else_branch: Callable[[], Iterable[Var]], then_branch: Callable[[], Iterable[Var]], ) -> Sequence[Var]: +def if_( + cond: Var, + *, + else_branch: Callable[[], Iterable[Var]], + then_branch: Callable[[], Iterable[Var]], +) -> Sequence[Var]: r""" -If conditional - -Parameters -========== -cond - Type B. - Condition for the if. The tensor must contain a single element. -else_branch - Attribute. - Graph to run if condition is false. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the then_branch. -then_branch - Attribute. - Graph to run if condition is true. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the else_branch. - -Returns -======= -outputs : Sequence[Var] - Type V. - Values that are live-out to the enclosing scope. The return values in - the ``then_branch`` and ``else_branch`` must be of the same data type. - The ``then_branch`` and ``else_branch`` may produce tensors with the - same element type and different shapes. If corresponding outputs from - the then-branch and the else-branch have static shapes S1 and S2, then - the shape of the corresponding output variable of the if-node (if - present) must be compatible with both S1 and S2 as it represents the - union of both possible shapes.For example, if in a model file, the first - output of ``then_branch`` is typed float tensor with shape [2] and the - first output of ``else_branch`` is another float tensor with shape [3], - If's first output should have (a) no shape set, or (b) a shape of rank 1 - with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank - 1 with a unique ``dim_param``. In contrast, the first output cannot have - the shape [2] since [2] and [3] are not compatible. - -Notes -===== -Signature: ``ai.onnx@19::If``. - -Type constraints: - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + If conditional + + Parameters + ========== + cond + Type B. + Condition for the if. The tensor must contain a single element. + else_branch + Attribute. + Graph to run if condition is false. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the then_branch. + then_branch + Attribute. + Graph to run if condition is true. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the else_branch. + + Returns + ======= + outputs : Sequence[Var] + Type V. + Values that are live-out to the enclosing scope. The return values in + the ``then_branch`` and ``else_branch`` must be of the same data type. + The ``then_branch`` and ``else_branch`` may produce tensors with the + same element type and different shapes. If corresponding outputs from + the then-branch and the else-branch have static shapes S1 and S2, then + the shape of the corresponding output variable of the if-node (if + present) must be compatible with both S1 and S2 as it represents the + union of both possible shapes.For example, if in a model file, the first + output of ``then_branch`` is typed float tensor with shape [2] and the + first output of ``else_branch`` is another float tensor with shape [3], + If's first output should have (a) no shape set, or (b) a shape of rank 1 + with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank + 1 with a unique ``dim_param``. In contrast, the first output cannot have + the shape [2] since [2] and [3] are not compatible. + + Notes + ===== + Signature: ``ai.onnx@19::If``. + + Type constraints: + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - _else_branch_subgraph: Graph = subgraph( - (), - else_branch - ) - _then_branch_subgraph: Graph = subgraph( - (), - then_branch + _else_branch_subgraph: Graph = subgraph((), else_branch) + _then_branch_subgraph: Graph = subgraph((), then_branch) + return ( + _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), + _If.Inputs( + cond=unwrap_vars(cond), + ), + out_variadic=len(_else_branch_subgraph.requested_results), + ) + .get_output_vars( + cond=get_value(cond), + ) + .outputs ) - return _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), _If.Inputs( - cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), ).get_output_vars( - cond=get_value(cond), ).outputs -def loop(M: Optional[Var] = None, cond: Optional[Var] = None, v_initial: Sequence[Var] = (), *, body: Callable[..., Iterable[Var]], ) -> Sequence[Var]: +def loop( + M: Optional[Var] = None, + cond: Optional[Var] = None, + v_initial: Sequence[Var] = (), + *, + body: Callable[..., Iterable[Var]], +) -> Sequence[Var]: r""" -Generic Looping construct. This loop has multiple termination -conditions: - -1) Trip count. Iteration count specified at runtime. Set by specifying - the input M. Optional. Set to empty string to omit. Note that a - static trip count (specified at graph construction time) can be - specified by passing in a constant node for input M. -2) Loop termination condition. This is an input to the op that - determines whether to run the first iteration and also a loop-carried - dependency for the body graph. The body graph must yield a value for - the condition variable, whether this input is provided or not. - -This table summarizes the operating modes of this operator with -equivalent C-style code: - -Operator inputs defined as (max_trip_count, condition_var). - -- input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } - -- input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } - -- input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } - -- input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } - -- input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } - -*Sample usage - cond as well as trip count* - -:: - - graph predict-net { - %a = Constant[value = ]() - %b = Constant[value = ]() - %keepgoing = Constant[value = ]() - %max_trip_count = Constant[value = ]() - %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) - return - } - - graph body-net ( - %i[INT32, scalar] // iteration number - %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used - %b_in[INT32, scalar] // incoming value of loop-carried-dependency b - ) { - %my_local = Add(%a, %b_in) - %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b - %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition - %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated - return %keepgoing_out, %b_out, %user_defined_val - } - -*Sample equivalent C code* - -:: - - { - /* User-defined code (enclosing scope) */ - int a = 3, b = 6; - bool keepgoing = true; // Analogous to input cond - /* End user-defined code */ - - /* Implicitly-defined code */ - const int max_trip_count = 10; // Analogous to input M - int user_defined_vals[]; // Imagine this is resizable - /* End implicitly-defined code */ - /* initialize loop-carried variables and scan-output variables */ - bool keepgoing_out = keepgoing - int b_out = b - - for (int i=0; i < max_trip_count && keepgoing_out; ++i) { - /* Implicitly-defined code: bind actual parameter values - to formal parameter variables of loop-body */ - bool keepgoing_in = keepgoing_out; - bool b_in = b_out; - - /* User-defined code (loop body) */ - int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine - b_out = a - b_in; - keepgoing_out = my_local > b_out; - user_defined_val = b_in + b_in; // b_in and b_out are different variables - /* End user-defined code */ - - /* Implicitly defined-code */ - user_defined_vals[i] = user_defined_val // accumulate scan-output values - } - // int t = my_local; // Can't do this. my_local is not accessible here. - - // The values below are bound to the output variables of the loop and therefore accessible - // b_out; user_defined_vals; keepgoing_out; - } - -There are several things of note in this code snippet: - -1) Values from the enclosing scope (i.e. variable "a" here) are in scope - and can be referenced in the inputs of the loop. -2) Any values computed in the loop body that needs to be used in a - subsequent iteration or after the loop are modelled using a pair of - variables in the loop-body, consisting of an input variable (eg., - b_in) and an output variable (eg., b_out). These are referred to as - loop-carried dependences. The loop operation node supplies the input - value of the input variable for the first iteration, and returns the - output value of the output variable produced by the final iteration. -3) Scan_output variables are used to implicitly concatenate values - computed across all the iterations. In the above example, the value - of user_defined_val computed over all iterations are concatenated and - returned as the value of user_defined_vals after the loop. -4) Values created in the body cannot be accessed in the enclosing scope, - except using the mechanism described above. - -Note that the semantics of this op support "diagonal" or "wavefront" -execution. (See Step 3 here for an example: -https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). -Frontends should emit multi-layer RNNs as a series of While operators -(with time being the inner looping dimension), with each successive -layer consuming the scan_outputs from the previous layer, possibly going -through several point-wise operators (e.g. dropout, residual -connections, linear layer). - -The input/output of subgraph (produced by loop node) matching is based -on order instead of name. The implementation will figure out the names -based on this order. - -Parameters -========== -M - Type I. - A maximum trip-count for the loop specified at runtime. Optional. Pass - empty string to skip. -cond - Type B. - A boolean termination condition. Optional. Pass empty string to skip. -v_initial - Type V. - The initial values of any loop-carried dependencies (values that change - across loop iterations) -body - Attribute. - The graph run each iteration. It has 2+N inputs: (iteration_num, - condition, loop carried dependencies...). It has 1+N+K outputs: - (condition, loop carried dependencies..., scan_outputs...). Each - scan_output is created by concatenating the value of the specified - output value at the end of each iteration of the loop. It is an error if - the dimensions or data type of these scan_outputs change across loop - iterations. - -Returns -======= -v_final_and_scan_outputs : Sequence[Var] - Type V. - Final N loop carried dependency values then K scan_outputs. Scan outputs - must be Tensors. - -Notes -===== -Signature: ``ai.onnx@19::Loop``. - -Type constraints: - - I: `tensor(int64)` - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Generic Looping construct. This loop has multiple termination + conditions: + + 1) Trip count. Iteration count specified at runtime. Set by specifying + the input M. Optional. Set to empty string to omit. Note that a + static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. + 2) Loop termination condition. This is an input to the op that + determines whether to run the first iteration and also a loop-carried + dependency for the body graph. The body graph must yield a value for + the condition variable, whether this input is provided or not. + + This table summarizes the operating modes of this operator with + equivalent C-style code: + + Operator inputs defined as (max_trip_count, condition_var). + + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } + + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } + + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } + + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } + + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } + + *Sample usage - cond as well as trip count* + + :: + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + + *Sample equivalent C code* + + :: + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + + There are several things of note in this code snippet: + + 1) Values from the enclosing scope (i.e. variable "a" here) are in scope + and can be referenced in the inputs of the loop. + 2) Any values computed in the loop body that needs to be used in a + subsequent iteration or after the loop are modelled using a pair of + variables in the loop-body, consisting of an input variable (eg., + b_in) and an output variable (eg., b_out). These are referred to as + loop-carried dependences. The loop operation node supplies the input + value of the input variable for the first iteration, and returns the + output value of the output variable produced by the final iteration. + 3) Scan_output variables are used to implicitly concatenate values + computed across all the iterations. In the above example, the value + of user_defined_val computed over all iterations are concatenated and + returned as the value of user_defined_vals after the loop. + 4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + + Note that the semantics of this op support "diagonal" or "wavefront" + execution. (See Step 3 here for an example: + https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). + Frontends should emit multi-layer RNNs as a series of While operators + (with time being the inner looping dimension), with each successive + layer consuming the scan_outputs from the previous layer, possibly going + through several point-wise operators (e.g. dropout, residual + connections, linear layer). + + The input/output of subgraph (produced by loop node) matching is based + on order instead of name. The implementation will figure out the names + based on this order. + + Parameters + ========== + M + Type I. + A maximum trip-count for the loop specified at runtime. Optional. Pass + empty string to skip. + cond + Type B. + A boolean termination condition. Optional. Pass empty string to skip. + v_initial + Type V. + The initial values of any loop-carried dependencies (values that change + across loop iterations) + body + Attribute. + The graph run each iteration. It has 2+N inputs: (iteration_num, + condition, loop carried dependencies...). It has 1+N+K outputs: + (condition, loop carried dependencies..., scan_outputs...). Each + scan_output is created by concatenating the value of the specified + output value at the end of each iteration of the loop. It is an error if + the dimensions or data type of these scan_outputs change across loop + iterations. + + Returns + ======= + v_final_and_scan_outputs : Sequence[Var] + Type V. + Final N loop carried dependency values then K scan_outputs. Scan outputs + must be Tensors. + + Notes + ===== + Signature: ``ai.onnx@19::Loop``. + + Type constraints: + - I: `tensor(int64)` + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ _body_subgraph: Graph = subgraph( - typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))])+ [var.unwrap_type() for var in v_initial], - body + typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))]) + + [var.unwrap_type() for var in v_initial], + body, + ) + return ( + _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), + _Loop.Inputs( + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), + ), + out_variadic=len(_body_subgraph.requested_results) - 1, + ) + .get_output_vars( + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), + ) + .v_final_and_scan_outputs ) - return _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), _Loop.Inputs( - M=unwrap_vars(M), cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, ).get_output_vars( - M=get_value(M), cond=get_value(cond), v_initial=get_value(v_initial), ).v_final_and_scan_outputs -def pad(data: Var, pads: Var, constant_value: Optional[Var] = None, axes: Optional[Var] = None, *, mode: str = "constant", ) -> Var: +def pad( + data: Var, + pads: Var, + constant_value: Optional[Var] = None, + axes: Optional[Var] = None, + *, + mode: str = "constant", +) -> Var: r""" -Given a tensor containing the data to be padded (``data``), a tensor -containing the number of start and end pad values for axis (``pads``), -(optionally) a ``mode``, and (optionally) ``constant_value``, a padded -tensor (``output``) is generated. + Given a tensor containing the data to be padded (``data``), a tensor + containing the number of start and end pad values for axis (``pads``), + (optionally) a ``mode``, and (optionally) ``constant_value``, a padded + tensor (``output``) is generated. + + The three supported ``modes`` are (similar to corresponding modes + supported by ``numpy.pad``): + + 1) ``constant``\ (default) - pads with a given constant value as + specified by ``constant_value`` (which defaults to 0, empty string, + or False) + + 2) ``reflect`` - pads with the reflection of the vector mirrored on the + first and last values of the vector along each axis + + 3) ``edge`` - pads with the edge values of array + + 4) ``wrap`` - wrap-around padding as if the data tensor forms a torus + + Example 1 (``constant`` mode): + + Insert 0 pads to the beginning of the second dimension. + + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + + Example 2 (``reflect`` mode): -The three supported ``modes`` are (similar to corresponding modes -supported by ``numpy.pad``): + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' -1) ``constant``\ (default) - pads with a given constant value as - specified by ``constant_value`` (which defaults to 0, empty string, - or False) + output = [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] -2) ``reflect`` - pads with the reflection of the vector mirrored on the - first and last values of the vector along each axis + Example 3 (``edge`` mode): -3) ``edge`` - pads with the edge values of array + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] -4) ``wrap`` - wrap-around padding as if the data tensor forms a torus + pads = [0, 2, 0, 0] -Example 1 (``constant`` mode): + mode = 'edge' -Insert 0 pads to the beginning of the second dimension. + output = [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] -:: + Example 4 (``wrap`` mode): - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] + :: - pads = [0, 2, 0, 0] - - mode = 'constant' - - constant_value = 0.0 - - output = [ - [0.0, 0.0, 1.0, 1.2], - [0.0, 0.0, 2.3, 3.4], - [0.0, 0.0, 4.5, 5.7], - ] - -Example 2 (``reflect`` mode): - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'reflect' - - output = [ - [1.0, 1.2, 1.0, 1.2], - [2.3, 3.4, 2.3, 3.4], - [4.5, 5.7, 4.5, 5.7], - ] - -Example 3 (``edge`` mode): - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'edge' - - output = [ - [1.0, 1.0, 1.0, 1.2], - [2.3, 2.3, 2.3, 3.4], - [4.5, 4.5, 4.5, 5.7], - ] - -Example 4 (``wrap`` mode): - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [2, 1, 1, 1] - - mode = 'wrap' - - output = [ - [3.4, 2.3, 3.4, 2.3], - [5.7, 4.5, 5.7, 4.5], - [1.2, 1.0, 1.2, 1.0], - [3.4, 2.3, 3.4, 2.3], - [5.7, 4.5, 5.7, 4.5], - [1.2, 1.0, 1.2, 1.0], - ] - -Parameters -========== -data - Type T. - Input tensor. -pads - Type tensor(int64). - Tensor of integers indicating the number of padding elements to add or - remove (if negative) at the beginning and end of each axis. For 2D input - tensor, it is the number of pixels. ``pads`` should be a 1D tensor of - shape [2 \* num_axes] where ``num_axes`` refers to the number of - elements in the ``axes`` input or the input rank if ``axes`` are not - provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, - ..., x1_end, x2_end,...], where xi_begin is the number of pad values - added at the beginning of axis ``axes[i]`` and xi_end, the number of pad - values added at the end of axis ``axes[i]``. -constant_value - Type T. - (Optional) A scalar value to be used if the mode chosen is ``constant`` - (by default it is 0, empty string or False). -axes - Type Tind. - 1-D tensor of axes that ``pads`` apply to. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(data). Behavior is undefined if an axis is repeated. If not - provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). -mode - Attribute. - Supported modes: ``constant``\ (default), ``reflect``, ``edge``, - ``wrap`` - -Returns -======= -output : Var - Type T. - Tensor after padding. - -Notes -===== -Signature: ``ai.onnx@19::Pad``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [2, 1, 1, 1] + + mode = 'wrap' + + output = [ + [3.4, 2.3, 3.4, 2.3], + [5.7, 4.5, 5.7, 4.5], + [1.2, 1.0, 1.2, 1.0], + [3.4, 2.3, 3.4, 2.3], + [5.7, 4.5, 5.7, 4.5], + [1.2, 1.0, 1.2, 1.0], + ] + + Parameters + ========== + data + Type T. + Input tensor. + pads + Type tensor(int64). + Tensor of integers indicating the number of padding elements to add or + remove (if negative) at the beginning and end of each axis. For 2D input + tensor, it is the number of pixels. ``pads`` should be a 1D tensor of + shape [2 \* num_axes] where ``num_axes`` refers to the number of + elements in the ``axes`` input or the input rank if ``axes`` are not + provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, + ..., x1_end, x2_end,...], where xi_begin is the number of pad values + added at the beginning of axis ``axes[i]`` and xi_end, the number of pad + values added at the end of axis ``axes[i]``. + constant_value + Type T. + (Optional) A scalar value to be used if the mode chosen is ``constant`` + (by default it is 0, empty string or False). + axes + Type Tind. + 1-D tensor of axes that ``pads`` apply to. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(data). Behavior is undefined if an axis is repeated. If not + provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). + mode + Attribute. + Supported modes: ``constant``\ (default), ``reflect``, ``edge``, + ``wrap`` + + Returns + ======= + output : Var + Type T. + Tensor after padding. + + Notes + ===== + Signature: ``ai.onnx@19::Pad``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), _Pad.Inputs( - data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), pads=get_value(pads), constant_value=get_value(constant_value), axes=get_value(axes), ).output + return ( + _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), + _Pad.Inputs( + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), + ) + .output + ) -def quantize_linear(x: Var, y_scale: Var, y_zero_point: Optional[Var] = None, *, axis: int = 1, saturate: int = 1, ) -> Var: +def quantize_linear( + x: Var, + y_scale: Var, + y_zero_point: Optional[Var] = None, + *, + axis: int = 1, + saturate: int = 1, +) -> Var: r""" -The linear quantization operator. It consumes a high precision tensor, a -scale, and a zero point to compute the low precision / quantized tensor. -The scale factor and zero point must have same shape, and can be either -a scalar for per-tensor / per layer quantization, or a 1-D tensor for -per-axis quantization. The quantization formula is -``y = saturate ((x / y_scale) + y_zero_point)``. For saturation, it -saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8. For (x -/ y_scale), it's rounding to the nearest even. Refer to -https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and -'y' must have same type. 'y_zero_point' is usually not used for -quantization to float8e4m3fn, float8e4m3fnuz, float8e5m2, -float8e5m2fnuz, but the quantization formula remains the same for -consistency and the type of the attribute 'y_zero_point' still -determines the quantization type. - -Parameters -========== -x - Type T1. - N-D full precision Input tensor to be quantized. -y_scale - Type T1. - Scale for doing quantization to get 'y'. It can be a scalar, which means - per-tensor/layer quantization, or a 1-D Tensor for per-axis - quantization. -y_zero_point - Type T2. - Zero point for doing quantization to get 'y'. Shape must match y_scale. - Default is uint8 with zero point of 0 if it's not specified. -axis - Attribute. - (Optional) The axis of the quantization dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). -saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. All cases are fully described in two tables - inserted in the operator description. - -Returns -======= -y : Var - Type T2. - N-D quantized output tensor. It has same shape as input 'x'. - -Notes -===== -Signature: ``ai.onnx@19::QuantizeLinear``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` + The linear quantization operator. It consumes a high precision tensor, a + scale, and a zero point to compute the low precision / quantized tensor. + The scale factor and zero point must have same shape, and can be either + a scalar for per-tensor / per layer quantization, or a 1-D tensor for + per-axis quantization. The quantization formula is + ``y = saturate ((x / y_scale) + y_zero_point)``. For saturation, it + saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8. For (x + / y_scale), it's rounding to the nearest even. Refer to + https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and + 'y' must have same type. 'y_zero_point' is usually not used for + quantization to float8e4m3fn, float8e4m3fnuz, float8e5m2, + float8e5m2fnuz, but the quantization formula remains the same for + consistency and the type of the attribute 'y_zero_point' still + determines the quantization type. + + Parameters + ========== + x + Type T1. + N-D full precision Input tensor to be quantized. + y_scale + Type T1. + Scale for doing quantization to get 'y'. It can be a scalar, which means + per-tensor/layer quantization, or a 1-D Tensor for per-axis + quantization. + y_zero_point + Type T2. + Zero point for doing quantization to get 'y'. Shape must match y_scale. + Default is uint8 with zero point of 0 if it's not specified. + axis + Attribute. + (Optional) The axis of the quantization dimension of the input tensor. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). + saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. All cases are fully described in two tables + inserted in the operator description. + + Returns + ======= + y : Var + Type T2. + N-D quantized output tensor. It has same shape as input 'x'. + + Notes + ===== + Signature: ``ai.onnx@19::QuantizeLinear``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` + - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - return _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - saturate=AttrInt64(saturate, name="saturate"), - ), _QuantizeLinear.Inputs( - x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( - x=get_value(x), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y + return ( + _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + saturate=AttrInt64(saturate, name="saturate"), + ), + _QuantizeLinear.Inputs( + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) -def reshape(data: Var, shape: Var, *, allowzero: int = 0, ) -> Var: +def reshape( + data: Var, + shape: Var, + *, + allowzero: int = 0, +) -> Var: r""" -Reshape the input tensor similar to numpy.reshape. First input is the -data tensor, second input is a shape tensor which specifies the output -shape. It outputs the reshaped tensor. At most one dimension of the new -shape can be -1. In this case, the value is inferred from the size of -the tensor and the remaining dimensions. A dimension could also be 0, in -which case the actual dimension value is unchanged (i.e. taken from the -input tensor). If 'allowzero' is set, and the new shape includes 0, the -dimension will be set explicitly to zero (i.e. not taken from input -tensor). Shape (second input) could be an empty shape, which means -converting to a scalar. The input tensor's shape and the output tensor's -shape are required to have the same number of elements. - -If the attribute 'allowzero' is set, it is invalid for the specified -shape to contain both a zero value and -1, as the value of the dimension -corresponding to -1 cannot be determined uniquely. - -Parameters -========== -data - Type T. - An input tensor. -shape - Type tensor(int64). - Specified shape for output. -allowzero - Attribute. - (Optional) By default, when any value in the 'shape' input is equal to - zero the corresponding dimension value is copied from the input tensor - dynamically. allowzero=1 indicates that if any value in the 'shape' - input is set to zero, the zero value is honored, similar to NumPy. - -Returns -======= -reshaped : Var - Type T. - Reshaped data. - -Notes -===== -Signature: ``ai.onnx@19::Reshape``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Reshape the input tensor similar to numpy.reshape. First input is the + data tensor, second input is a shape tensor which specifies the output + shape. It outputs the reshaped tensor. At most one dimension of the new + shape can be -1. In this case, the value is inferred from the size of + the tensor and the remaining dimensions. A dimension could also be 0, in + which case the actual dimension value is unchanged (i.e. taken from the + input tensor). If 'allowzero' is set, and the new shape includes 0, the + dimension will be set explicitly to zero (i.e. not taken from input + tensor). Shape (second input) could be an empty shape, which means + converting to a scalar. The input tensor's shape and the output tensor's + shape are required to have the same number of elements. + + If the attribute 'allowzero' is set, it is invalid for the specified + shape to contain both a zero value and -1, as the value of the dimension + corresponding to -1 cannot be determined uniquely. + + Parameters + ========== + data + Type T. + An input tensor. + shape + Type tensor(int64). + Specified shape for output. + allowzero + Attribute. + (Optional) By default, when any value in the 'shape' input is equal to + zero the corresponding dimension value is copied from the input tensor + dynamically. allowzero=1 indicates that if any value in the 'shape' + input is set to zero, the zero value is honored, similar to NumPy. + + Returns + ======= + reshaped : Var + Type T. + Reshaped data. + + Notes + ===== + Signature: ``ai.onnx@19::Reshape``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), _Reshape.Inputs( - data=unwrap_vars(data), shape=unwrap_vars(shape), ), ).get_output_vars( - data=get_value(data), shape=get_value(shape), ).reshaped + return ( + _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), + _Reshape.Inputs( + data=unwrap_vars(data), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + data=get_value(data), + shape=get_value(shape), + ) + .reshaped + ) -def resize(X: Var, roi: Optional[Var] = None, scales: Optional[Var] = None, sizes: Optional[Var] = None, *, antialias: int = 0, axes: Optional[Iterable[int]] = None, coordinate_transformation_mode: str = "half_pixel", cubic_coeff_a: float = -0.75, exclude_outside: int = 0, extrapolation_value: float = 0.0, keep_aspect_ratio_policy: str = "stretch", mode: str = "nearest", nearest_mode: str = "round_prefer_floor", ) -> Var: +def resize( + X: Var, + roi: Optional[Var] = None, + scales: Optional[Var] = None, + sizes: Optional[Var] = None, + *, + antialias: int = 0, + axes: Optional[Iterable[int]] = None, + coordinate_transformation_mode: str = "half_pixel", + cubic_coeff_a: float = -0.75, + exclude_outside: int = 0, + extrapolation_value: float = 0.0, + keep_aspect_ratio_policy: str = "stretch", + mode: str = "nearest", + nearest_mode: str = "round_prefer_floor", +) -> Var: r""" -Resize the input tensor. In general, it calculates every value in the -output tensor as a weighted average of neighborhood (a.k.a. sampling -locations) in the input tensor. Each dimension value of the output -tensor is: - -:: - - output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) - -if input "sizes" is not specified. - -Parameters -========== -X - Type T1. - N-D tensor -roi - Type T2. - 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is - the rank of X or the length of axes, if provided. The RoIs' coordinates - are normalized in the coordinate system of the input image. It only - takes effect when coordinate_transformation_mode is "tf_crop_and_resize" -scales - Type tensor(float). - The scale array along each dimension. It takes value greater than 0. If - it's less than 1, it's sampling down, otherwise, it's upsampling. The - number of elements of 'scales' should be the same as the rank of input - 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' - MUST be specified and it is an error if both are specified. If 'sizes' - is needed, the user can use an empty string as the name of 'scales' in - this operator's input list. -sizes - Type tensor(int64). - Target size of the output tensor. Its interpretation depends on the - 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' - should be the same as the rank of input 'X', or the length of 'axes', if - provided. Only one of 'scales' and 'sizes' can be specified. -antialias - Attribute. - If set to 1, "linear" and "cubic" interpolation modes will use an - antialiasing filter when downscaling. Antialiasing is achieved by - stretching the resampling filter by a factor max(1, 1 / scale), which - means that when downsampling, more input pixels contribute to an output - pixel. -axes - Attribute. - If provided, it specifies a subset of axes that 'roi', 'scales' and - 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., - r-1], where r = rank(data). Non-specified dimensions are interpreted as - non-resizable. Negative value means counting dimensions from the back. - Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined - if an axis is repeated. -coordinate_transformation_mode - Attribute. - This attribute describes how to transform the coordinate in the resized - tensor to the coordinate in the original tensor. - - The coordinate of each dimension is transformed individually. Let's - describe a case using axis x as an example. Denote ``x_resized`` as the - coordinate of axis x in the resized tensor, ``x_original`` as the - coordinate of axis x in the original tensor, ``length_original`` as the - length of the original tensor in axis x, ``length_resized`` as the - length of the resized tensor in axis x, - ``scale = length_resized / length_original``, ``output_width`` the - target length on the axis x which can be a fractional number when it is - calculated out of a scale factor, and ``output_width_int`` the effective - output width as an integer. - - if coordinate_transformation_mode is ``"half_pixel"``, + Resize the input tensor. In general, it calculates every value in the + output tensor as a weighted average of neighborhood (a.k.a. sampling + locations) in the input tensor. Each dimension value of the output + tensor is: :: - x_original = (x_resized + 0.5) / scale - 0.5 + output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) + + if input "sizes" is not specified. + + Parameters + ========== + X + Type T1. + N-D tensor + roi + Type T2. + 1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is + the rank of X or the length of axes, if provided. The RoIs' coordinates + are normalized in the coordinate system of the input image. It only + takes effect when coordinate_transformation_mode is "tf_crop_and_resize" + scales + Type tensor(float). + The scale array along each dimension. It takes value greater than 0. If + it's less than 1, it's sampling down, otherwise, it's upsampling. The + number of elements of 'scales' should be the same as the rank of input + 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' + MUST be specified and it is an error if both are specified. If 'sizes' + is needed, the user can use an empty string as the name of 'scales' in + this operator's input list. + sizes + Type tensor(int64). + Target size of the output tensor. Its interpretation depends on the + 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' + should be the same as the rank of input 'X', or the length of 'axes', if + provided. Only one of 'scales' and 'sizes' can be specified. + antialias + Attribute. + If set to 1, "linear" and "cubic" interpolation modes will use an + antialiasing filter when downscaling. Antialiasing is achieved by + stretching the resampling filter by a factor max(1, 1 / scale), which + means that when downsampling, more input pixels contribute to an output + pixel. + axes + Attribute. + If provided, it specifies a subset of axes that 'roi', 'scales' and + 'sizes' refer to. If not provided, all axes are assumed [0, 1, ..., + r-1], where r = rank(data). Non-specified dimensions are interpreted as + non-resizable. Negative value means counting dimensions from the back. + Accepted range is [-r, r-1], where r = rank(data). Behavior is undefined + if an axis is repeated. + coordinate_transformation_mode + Attribute. + This attribute describes how to transform the coordinate in the resized + tensor to the coordinate in the original tensor. + + The coordinate of each dimension is transformed individually. Let's + describe a case using axis x as an example. Denote ``x_resized`` as the + coordinate of axis x in the resized tensor, ``x_original`` as the + coordinate of axis x in the original tensor, ``length_original`` as the + length of the original tensor in axis x, ``length_resized`` as the + length of the resized tensor in axis x, + ``scale = length_resized / length_original``, ``output_width`` the + target length on the axis x which can be a fractional number when it is + calculated out of a scale factor, and ``output_width_int`` the effective + output width as an integer. + + if coordinate_transformation_mode is ``"half_pixel"``, + + :: + + x_original = (x_resized + 0.5) / scale - 0.5 + + if coordinate_transformation_mode is ``"half_pixel_symmetric"``, + + :: + + adjustment = output_width_int / output_width + center = input_width / 2 + offset = center * (1 - adjustment) + x_ori = offset + (x + 0.5) / scale - 0.5 + + if coordinate_transformation_mode is ``"pytorch_half_pixel"``, + + :: + + x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0 + + if coordinate_transformation_mode is ``"align_corners"``, + + :: + + x_original = x_resized * (length_original - 1) / (length_resized - 1) + + if coordinate_transformation_mode is ``"asymmetric"``, + + :: + + x_original = x_resized / scale + + if coordinate_transformation_mode is ``"tf_crop_and_resize"``, + + :: + + x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1) + + . + cubic_coeff_a + Attribute. + The coefficient 'a' used in cubic interpolation. Two common choice are + -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out + Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the + details. This attribute is valid only if mode is "cubic". + exclude_outside + Attribute. + If set to 1, the weight of sampling locations outside the tensor will be + set to 0 and the weight will be renormalized so that their sum is 1.0. + The default value is 0. + extrapolation_value + Attribute. + When coordinate_transformation_mode is "tf_crop_and_resize" and + x_original is outside the range [0, length_original - 1], this value is + used as the corresponding output value. Default is 0.0f. + keep_aspect_ratio_policy + Attribute. + This attribute describes how to interpret the ``sizes`` input with + regard to keeping the original aspect ratio of the input, and it is not + applicable when the ``scales`` input is used. + + Given a set of ``sizes``, associated with a subset of ``axes`` + (explicitly provided or default), and assuming ``d = axes[i]``, with + ``i`` being the index of the provided ``sizes``. + + If ``keep_aspect_ratio_policy`` is ``"stretch"``, the original aspect + ratio is disregarded, and the input is resized to the specified size: + ``out_size[d] = sizes[i]`` + + If ``keep_aspect_ratio_policy`` is ``"not_larger"``, the sizes are + adjusted so that no extent of the output is larger than the specified + size, while keeping the original aspect ratio: + + :: + + scale = Min(sizes[i] / in_size[d]) + out_size[d] = round_int(scale * in_size[i]) + + If ``keep_aspect_ratio_policy`` is ``"not_smaller"``, the sizes are + adjusted so that no extent of the output is smaller than the specified + size, while keeping the original aspect ratio: + + :: + + scale = Max(sizes[i] / in_size[d]) + out_size[d] = round_int(scale * in_size[i]) - if coordinate_transformation_mode is ``"half_pixel_symmetric"``, - - :: + For non-resizable axes (those not specified in ``axes``), the output + size will be equal to the input size. + + Note: ``round_int`` stands for computing the nearest integer value, + rounding halfway cases up. + mode + Attribute. + Three interpolation modes: "nearest" (default), "linear" and "cubic". + The "linear" mode includes linear interpolation for 1D tensor and + N-linear interpolation for N-D tensor (for example, bilinear + interpolation for 2D tensor). The "cubic" mode includes cubic + interpolation for 1D tensor and N-cubic interpolation for N-D tensor + (for example, bicubic interpolation for 2D tensor). + nearest_mode + Attribute. + Four modes: "round_prefer_floor" (default, as known as round half down), + "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only + used by nearest interpolation. It indicates how to get "nearest" pixel + in input tensor from x_original, so this attribute is valid only if + "mode" is "nearest". + + Returns + ======= + Y : Var + Type T1. + N-D tensor after resizing + + Notes + ===== + Signature: ``ai.onnx@19::Resize``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` + """ + return ( + _Resize( + _Resize.Attributes( + antialias=AttrInt64(antialias, name="antialias"), + axes=AttrInt64s.maybe(axes, name="axes"), + coordinate_transformation_mode=AttrString( + coordinate_transformation_mode, + name="coordinate_transformation_mode", + ), + cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), + exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), + extrapolation_value=AttrFloat32( + extrapolation_value, name="extrapolation_value" + ), + keep_aspect_ratio_policy=AttrString( + keep_aspect_ratio_policy, name="keep_aspect_ratio_policy" + ), + mode=AttrString(mode, name="mode"), + nearest_mode=AttrString(nearest_mode, name="nearest_mode"), + ), + _Resize.Inputs( + X=unwrap_vars(X), + roi=unwrap_vars(roi), + scales=unwrap_vars(scales), + sizes=unwrap_vars(sizes), + ), + ) + .get_output_vars( + X=get_value(X), + roi=get_value(roi), + scales=get_value(scales), + sizes=get_value(sizes), + ) + .Y + ) - adjustment = output_width_int / output_width - center = input_width / 2 - offset = center * (1 - adjustment) - x_ori = offset + (x + 0.5) / scale - 0.5 - if coordinate_transformation_mode is ``"pytorch_half_pixel"``, +def scan( + initial_state_and_scan_inputs: Sequence[Var], + *, + body: Callable[..., Iterable[Var]], + num_scan_inputs: int, + scan_input_axes: Optional[Iterable[int]] = None, + scan_input_directions: Optional[Iterable[int]] = None, + scan_output_axes: Optional[Iterable[int]] = None, + scan_output_directions: Optional[Iterable[int]] = None, +) -> Sequence[Var]: + r""" + Scan can be used to iterate over one or more scan_input tensors, + constructing zero or more scan_output tensors. It combines ideas from + general recurrences, functional programming constructs such as scan, + fold, map, and zip, and is intended to enable generalizations of + RNN-like constructs for sequence-to-sequence processing. Other tensors + (referred to as state_variables here) can be used to carry a state when + iterating from one element to another (similar to hidden-state in RNNs, + also referred to as loop-carried dependences in the context of loops). + Many common usages involve a single scan_input tensor (where + functionality similar to scan, fold and map can be obtained). When more + than one scan_input is used, a behavior similar to zip is obtained. + + The attribute body must be a graph, specifying the computation to be + performed in every iteration. It takes as input the current values of + the state_variables and the current iterated element of the scan_inputs. + It must return the (updated) values of the state_variables and zero or + more scan_output_element tensors. The values of the scan_output_element + tensors are concatenated over all the iterations to produce the + scan_output values of the scan construct (similar to the concatenated + intermediate hidden-state values of RNN-like constructs). All the output + tensors (state_variables as well as scan_output_element tensors) are + required to have the same shape in each iteration of the loop (a + restriction imposed to enable efficient memory allocation). + + Note that the iterated element passed to the body subgraph does not have + a sequence axis. It will have a rank one less than the rank of the + corresponding scan_input. + + The scan operation returns the final values of the state_variables as + well as the scan_outputs. + + The optional attribute scan_input_directions specifies the direction + (forward or backward) for each scan input. If this attribute is omitted, + all sequences are scanned in the forward direction. A bidirectional scan + may be performed by specifying the same tensor input twice in the + scan_inputs, once with a forward direction, and once with a backward + direction. + + The scan_output of the operation is produced by concatenating the + scan_output_element values produced by the body in each iteration. The + optional attribute scan_output_directions specifies the direction in + which scan_output is constructed (by appending or prepending the + scan_output_element to scan_output in each iteration) for each + scan_output. If this attribute is omitted, the scan_output_element is + appended to the scan_output in each iteration. + + The optional attribute scan_input_axes specifies the axis to be scanned + for each scan_input. If omitted, every scan_input will be scanned in + axis 0. For example, if axis 0 is the batch axis and axis 1 is the time + axis (to be scanned), specify an axis value of 1. Note that scanning a + non-zero axis may be less efficient than scanning axis zero. + + The optional attribute scan_output_axes specifies the axis along which + the scan_outputs are accumulated for each scan_output. For example, if + axis 1 is the time axis (to be scanned) for both inputs and outputs, + specify a scan_input axis and scan_output axis value of 1. + + Note that because of the ONNX restriction that only the last parameter + of an operator can be variadic, the initial-states and scan-inputs are + listed together as one input parameter. Similarly, the final-states and + scan-outputs are listed together as one output parameter. The attribute + num_scan_inputs indicates the number M of scan-inputs. + + The behavior of :: - x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0 + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) - if coordinate_transformation_mode is ``"align_corners"``, + is equivalent to the following pseudo-code: :: - x_original = x_resized * (length_original - 1) / (length_resized - 1) - - if coordinate_transformation_mode is ``"asymmetric"``, + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + + *Sample usage: Encoding RNN using a Scan* + + The following example shows how a simple RNN over an input tensor %X, + with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi + and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. + Note that the loop-body is a nested graph, and it directly computes %Wi, + %Ri, %Wbi, and %Rbi (typically constants or initializers in the body + graph). If these values are computed in the outer graph, they need to be + passed in as extra state_variables. :: - x_original = x_resized / scale + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + + Parameters + ========== + initial_state_and_scan_inputs + Type V. + Initial values of the loop's N state variables followed by M scan_inputs + body + Attribute. + The graph run each iteration. It has N+M inputs: (loop state + variables..., scan_input_elts...). It has N+K outputs: (loop state + variables..., scan_output_elts...). Each scan_output is created by + concatenating the value of the specified scan_output_elt value at the + end of each iteration of the loop. It is an error if the dimensions of + these values change across loop iterations. + num_scan_inputs + Attribute. + An attribute specifying the number of scan_inputs M. + scan_input_axes + Attribute. + An optional list of M flags. The i-th element of the list specifies the + axis to be scanned (the sequence axis) for the i-th scan_input. If + omitted, 0 will be used as the scan axis for every scan_input. Negative + value for an axis means counting dimensions from the back. Accepted + range is [-r, r-1] where r = rank(input). + scan_input_directions + Attribute. + An optional list of M flags. The i-th element of the list specifies the + direction to be scanned for the i-th scan_input tensor: 0 indicates + forward direction and 1 indicates reverse direction. If omitted, all + scan_input tensors will be scanned in the forward direction. + scan_output_axes + Attribute. + An optional list of K flags. The i-th element of the list specifies the + axis for the i-th scan_output. The scan outputs are accumulated along + the specified axis. If omitted, 0 will be used as the scan axis for + every scan_output. Negative value for an axis means counting dimensions + from the back. Accepted range is [-r, r-1]. + scan_output_directions + Attribute. + An optional list of K flags, one for each scan_output. The i-th element + of the list specifies whether the i-th scan_output should be constructed + by appending or prepending a new value in each iteration: 0 indicates + appending and 1 indicates prepending. If omitted, all scan_output + tensors will be produced by appending a value in each iteration. + + Returns + ======= + final_state_and_scan_outputs : Sequence[Var] + Type V. + Final values of the loop's N state variables followed by K scan_outputs + + Notes + ===== + Signature: ``ai.onnx@19::Scan``. + + Type constraints: + - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + """ + _body_subgraph: Graph = subgraph( + [ + Tensor( + var.unwrap_tensor().dtype, + (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape), + ) + for var in initial_state_and_scan_inputs[:num_scan_inputs] + ] + + [ + Tensor(var.unwrap_tensor().dtype) + for var in initial_state_and_scan_inputs[num_scan_inputs:] + ], + body, + ) + return ( + _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe( + scan_input_axes, name="scan_input_axes" + ), + scan_input_directions=AttrInt64s.maybe( + scan_input_directions, name="scan_input_directions" + ), + scan_output_axes=AttrInt64s.maybe( + scan_output_axes, name="scan_output_axes" + ), + scan_output_directions=AttrInt64s.maybe( + scan_output_directions, name="scan_output_directions" + ), + ), + _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars( + initial_state_and_scan_inputs + ), + ), + out_variadic=len(_body_subgraph.requested_results), + ) + .get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + ) + .final_state_and_scan_outputs + ) + - if coordinate_transformation_mode is ``"tf_crop_and_resize"``, +def shape( + data: Var, + *, + end: Optional[int] = None, + start: int = 0, +) -> Var: + r""" + Takes a tensor as input and outputs an 1D int64 tensor containing the + shape of the input tensor. Optional attributes start and end can be used + to compute a slice of the input tensor's shape. If start axis is + omitted, the slice starts from axis 0. The end axis, if specified, is + exclusive (and the returned value will not include the size of that + axis). If the end axis is omitted, the axes upto the last one will be + included. Negative axes indicate counting back from the last axis. Note + that axes will be clamped to the range [0, r-1], where r is the rank of + the input tensor if they are out-of-range (after adding r in the case of + negative axis). Thus, specifying any end value > r is equivalent to + specifying an end value of r, and specifying any start value < -r is + equivalent to specifying a start value of 0. + + Examples: :: - x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1) - - . -cubic_coeff_a - Attribute. - The coefficient 'a' used in cubic interpolation. Two common choice are - -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out - Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the - details. This attribute is valid only if mode is "cubic". -exclude_outside - Attribute. - If set to 1, the weight of sampling locations outside the tensor will be - set to 0 and the weight will be renormalized so that their sum is 1.0. - The default value is 0. -extrapolation_value - Attribute. - When coordinate_transformation_mode is "tf_crop_and_resize" and - x_original is outside the range [0, length_original - 1], this value is - used as the corresponding output value. Default is 0.0f. -keep_aspect_ratio_policy - Attribute. - This attribute describes how to interpret the ``sizes`` input with - regard to keeping the original aspect ratio of the input, and it is not - applicable when the ``scales`` input is used. - - Given a set of ``sizes``, associated with a subset of ``axes`` - (explicitly provided or default), and assuming ``d = axes[i]``, with - ``i`` being the index of the provided ``sizes``. - - If ``keep_aspect_ratio_policy`` is ``"stretch"``, the original aspect - ratio is disregarded, and the input is resized to the specified size: - ``out_size[d] = sizes[i]`` - - If ``keep_aspect_ratio_policy`` is ``"not_larger"``, the sizes are - adjusted so that no extent of the output is larger than the specified - size, while keeping the original aspect ratio: + Input tensor with shape: [2, 3, 4] + No attributes specified. + Output: [2, 3, 4] :: - scale = Min(sizes[i] / in_size[d]) - out_size[d] = round_int(scale * in_size[i]) + Input tensor with shape: [2, 3, 4] + start: -1 + Output: [4] - If ``keep_aspect_ratio_policy`` is ``"not_smaller"``, the sizes are - adjusted so that no extent of the output is smaller than the specified - size, while keeping the original aspect ratio: + :: + + Input tensor with shape: [2, 3, 4] + end: -1 + Output: [2, 3] :: - scale = Max(sizes[i] / in_size[d]) - out_size[d] = round_int(scale * in_size[i]) - - For non-resizable axes (those not specified in ``axes``), the output - size will be equal to the input size. - - Note: ``round_int`` stands for computing the nearest integer value, - rounding halfway cases up. -mode - Attribute. - Three interpolation modes: "nearest" (default), "linear" and "cubic". - The "linear" mode includes linear interpolation for 1D tensor and - N-linear interpolation for N-D tensor (for example, bilinear - interpolation for 2D tensor). The "cubic" mode includes cubic - interpolation for 1D tensor and N-cubic interpolation for N-D tensor - (for example, bicubic interpolation for 2D tensor). -nearest_mode - Attribute. - Four modes: "round_prefer_floor" (default, as known as round half down), - "round_prefer_ceil" (as known as round half up), "floor", "ceil". Only - used by nearest interpolation. It indicates how to get "nearest" pixel - in input tensor from x_original, so this attribute is valid only if - "mode" is "nearest". - -Returns -======= -Y : Var - Type T1. - N-D tensor after resizing - -Notes -===== -Signature: ``ai.onnx@19::Resize``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Resize( - _Resize.Attributes( - antialias=AttrInt64(antialias, name="antialias"), - axes=AttrInt64s.maybe(axes, name="axes"), - coordinate_transformation_mode=AttrString(coordinate_transformation_mode, name="coordinate_transformation_mode"), - cubic_coeff_a=AttrFloat32(cubic_coeff_a, name="cubic_coeff_a"), - exclude_outside=AttrInt64(exclude_outside, name="exclude_outside"), - extrapolation_value=AttrFloat32(extrapolation_value, name="extrapolation_value"), - keep_aspect_ratio_policy=AttrString(keep_aspect_ratio_policy, name="keep_aspect_ratio_policy"), - mode=AttrString(mode, name="mode"), - nearest_mode=AttrString(nearest_mode, name="nearest_mode"), - ), _Resize.Inputs( - X=unwrap_vars(X), roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), ).get_output_vars( - X=get_value(X), roi=get_value(roi), scales=get_value(scales), sizes=get_value(sizes), ).Y - - -def scan(initial_state_and_scan_inputs: Sequence[Var], *, body: Callable[..., Iterable[Var]], num_scan_inputs: int, scan_input_axes: Optional[Iterable[int]] = None, scan_input_directions: Optional[Iterable[int]] = None, scan_output_axes: Optional[Iterable[int]] = None, scan_output_directions: Optional[Iterable[int]] = None, ) -> Sequence[Var]: - r""" -Scan can be used to iterate over one or more scan_input tensors, -constructing zero or more scan_output tensors. It combines ideas from -general recurrences, functional programming constructs such as scan, -fold, map, and zip, and is intended to enable generalizations of -RNN-like constructs for sequence-to-sequence processing. Other tensors -(referred to as state_variables here) can be used to carry a state when -iterating from one element to another (similar to hidden-state in RNNs, -also referred to as loop-carried dependences in the context of loops). -Many common usages involve a single scan_input tensor (where -functionality similar to scan, fold and map can be obtained). When more -than one scan_input is used, a behavior similar to zip is obtained. - -The attribute body must be a graph, specifying the computation to be -performed in every iteration. It takes as input the current values of -the state_variables and the current iterated element of the scan_inputs. -It must return the (updated) values of the state_variables and zero or -more scan_output_element tensors. The values of the scan_output_element -tensors are concatenated over all the iterations to produce the -scan_output values of the scan construct (similar to the concatenated -intermediate hidden-state values of RNN-like constructs). All the output -tensors (state_variables as well as scan_output_element tensors) are -required to have the same shape in each iteration of the loop (a -restriction imposed to enable efficient memory allocation). - -Note that the iterated element passed to the body subgraph does not have -a sequence axis. It will have a rank one less than the rank of the -corresponding scan_input. - -The scan operation returns the final values of the state_variables as -well as the scan_outputs. - -The optional attribute scan_input_directions specifies the direction -(forward or backward) for each scan input. If this attribute is omitted, -all sequences are scanned in the forward direction. A bidirectional scan -may be performed by specifying the same tensor input twice in the -scan_inputs, once with a forward direction, and once with a backward -direction. - -The scan_output of the operation is produced by concatenating the -scan_output_element values produced by the body in each iteration. The -optional attribute scan_output_directions specifies the direction in -which scan_output is constructed (by appending or prepending the -scan_output_element to scan_output in each iteration) for each -scan_output. If this attribute is omitted, the scan_output_element is -appended to the scan_output in each iteration. - -The optional attribute scan_input_axes specifies the axis to be scanned -for each scan_input. If omitted, every scan_input will be scanned in -axis 0. For example, if axis 0 is the batch axis and axis 1 is the time -axis (to be scanned), specify an axis value of 1. Note that scanning a -non-zero axis may be less efficient than scanning axis zero. - -The optional attribute scan_output_axes specifies the axis along which -the scan_outputs are accumulated for each scan_output. For example, if -axis 1 is the time axis (to be scanned) for both inputs and outputs, -specify a scan_input axis and scan_output axis value of 1. - -Note that because of the ONNX restriction that only the last parameter -of an operator can be variadic, the initial-states and scan-inputs are -listed together as one input parameter. Similarly, the final-states and -scan-outputs are listed together as one output parameter. The attribute -num_scan_inputs indicates the number M of scan-inputs. - -The behavior of - -:: - - Scan < - num_scan_inputs = m, - body = loop-body, - scan_input_axes = [axis_1, ..., axis_m] - > (init_1, ..., init_n, scan_1, ..., scan_m) - -is equivalent to the following pseudo-code: - -:: - - // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i - // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. - sequence_length = scan_1.shape[axis_1]; - - // initialize state-variables - st_1 = init_1; ... st_n = init_n; - // initialize scan-output variables: [] denotes an empty tensor - scan_out_1 = []; ...; scan_out_k = []; - // identify number of iterations: - - // execute loop - for (int t = 0; t < sequence_length; ++t) { - // generate the scan-input elements: the notation T[t] indicates the sub-tensor - // of rank one less than T obtained by indexing T at position t along axis k. - si_1 = scan_1[t]; - ... ; - si_m = scan_m[t]; - // execute loop-body - st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) - // accumulate the scan-output elements - scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); - } - - return st_1, ..., st_n, scan_out_1, ..., scan_out_k; - -*Sample usage: Encoding RNN using a Scan* - -The following example shows how a simple RNN over an input tensor %X, -with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi -and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. -Note that the loop-body is a nested graph, and it directly computes %Wi, -%Ri, %Wbi, and %Rbi (typically constants or initializers in the body -graph). If these values are computed in the outer graph, they need to be -passed in as extra state_variables. - -:: - - graph rnn-encoding { - %H_0 = ... - %X = ... - %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) - return %Y, %Y_h - } - - graph rnn-cell-1 ( - %H_tminus1[FLOAT, tensor] - %X_t[FLOAT, tensor] - ) { - %Wi = ... - %Ri = ... - %Wbi = ... - %Rbi = ... - %t1 = X_t * (Wi^T) - %t2 = H_tminus1*(Ri^T) - %t3 = Add(%t1, %t2) - %t4 = Add(%t3, %Wbi) - %t5 = Add(%t4, %Rbi) - %Ht = Tanh(%t5) - %Accumulate = Identity(%Ht) - return %Ht, %Accumulate - } - -Parameters -========== -initial_state_and_scan_inputs - Type V. - Initial values of the loop's N state variables followed by M scan_inputs -body - Attribute. - The graph run each iteration. It has N+M inputs: (loop state - variables..., scan_input_elts...). It has N+K outputs: (loop state - variables..., scan_output_elts...). Each scan_output is created by - concatenating the value of the specified scan_output_elt value at the - end of each iteration of the loop. It is an error if the dimensions of - these values change across loop iterations. -num_scan_inputs - Attribute. - An attribute specifying the number of scan_inputs M. -scan_input_axes - Attribute. - An optional list of M flags. The i-th element of the list specifies the - axis to be scanned (the sequence axis) for the i-th scan_input. If - omitted, 0 will be used as the scan axis for every scan_input. Negative - value for an axis means counting dimensions from the back. Accepted - range is [-r, r-1] where r = rank(input). -scan_input_directions - Attribute. - An optional list of M flags. The i-th element of the list specifies the - direction to be scanned for the i-th scan_input tensor: 0 indicates - forward direction and 1 indicates reverse direction. If omitted, all - scan_input tensors will be scanned in the forward direction. -scan_output_axes - Attribute. - An optional list of K flags. The i-th element of the list specifies the - axis for the i-th scan_output. The scan outputs are accumulated along - the specified axis. If omitted, 0 will be used as the scan axis for - every scan_output. Negative value for an axis means counting dimensions - from the back. Accepted range is [-r, r-1]. -scan_output_directions - Attribute. - An optional list of K flags, one for each scan_output. The i-th element - of the list specifies whether the i-th scan_output should be constructed - by appending or prepending a new value in each iteration: 0 indicates - appending and 1 indicates prepending. If omitted, all scan_output - tensors will be produced by appending a value in each iteration. - -Returns -======= -final_state_and_scan_outputs : Sequence[Var] - Type V. - Final values of the loop's N state variables followed by K scan_outputs - -Notes -===== -Signature: ``ai.onnx@19::Scan``. - -Type constraints: - - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Input tensor with shape: [2, 3, 4] + start: 1 + end: 2 + Output: [3] + + Parameters + ========== + data + Type T. + An input tensor. + end + Attribute. + (Optional) Ending axis for slicing the shape. Negative value means + counting dimensions from the back. If omitted, sizes of all axes upto + (including) the last one will be included. + start + Attribute. + (Optional) Starting axis for slicing the shape. Default value is + 0.Negative value means counting dimensions from the back. + + Returns + ======= + shape : Var + Type T1. + Shape of the input tensor + + Notes + ===== + Signature: ``ai.onnx@19::Shape``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` """ - _body_subgraph: Graph = subgraph( - [Tensor(var.unwrap_tensor().dtype, (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape)) for var in initial_state_and_scan_inputs[:num_scan_inputs]] + [Tensor(var.unwrap_tensor().dtype) for var in initial_state_and_scan_inputs[num_scan_inputs:]], - body + return ( + _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), + _Shape.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .shape ) - return _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), - scan_input_directions=AttrInt64s.maybe(scan_input_directions, name="scan_input_directions"), - scan_output_axes=AttrInt64s.maybe(scan_output_axes, name="scan_output_axes"), - scan_output_directions=AttrInt64s.maybe(scan_output_directions, name="scan_output_directions"), - ), _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), ).final_state_and_scan_outputs - - -def shape(data: Var, *, end: Optional[int] = None, start: int = 0, ) -> Var: - r""" -Takes a tensor as input and outputs an 1D int64 tensor containing the -shape of the input tensor. Optional attributes start and end can be used -to compute a slice of the input tensor's shape. If start axis is -omitted, the slice starts from axis 0. The end axis, if specified, is -exclusive (and the returned value will not include the size of that -axis). If the end axis is omitted, the axes upto the last one will be -included. Negative axes indicate counting back from the last axis. Note -that axes will be clamped to the range [0, r-1], where r is the rank of -the input tensor if they are out-of-range (after adding r in the case of -negative axis). Thus, specifying any end value > r is equivalent to -specifying an end value of r, and specifying any start value < -r is -equivalent to specifying a start value of 0. - -Examples: - -:: - - Input tensor with shape: [2, 3, 4] - No attributes specified. - Output: [2, 3, 4] - -:: - - Input tensor with shape: [2, 3, 4] - start: -1 - Output: [4] - -:: - - Input tensor with shape: [2, 3, 4] - end: -1 - Output: [2, 3] - -:: - - Input tensor with shape: [2, 3, 4] - start: 1 - end: 2 - Output: [3] - -Parameters -========== -data - Type T. - An input tensor. -end - Attribute. - (Optional) Ending axis for slicing the shape. Negative value means - counting dimensions from the back. If omitted, sizes of all axes upto - (including) the last one will be included. -start - Attribute. - (Optional) Starting axis for slicing the shape. Default value is - 0.Negative value means counting dimensions from the back. - -Returns -======= -shape : Var - Type T1. - Shape of the input tensor - -Notes -===== -Signature: ``ai.onnx@19::Shape``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` - """ - return _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), _Shape.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).shape -def size(data: Var, ) -> Var: +def size( + data: Var, +) -> Var: r""" -Takes a tensor as input and outputs a int64 scalar that equals to the -total number of elements of the input tensor. - -Parameters -========== -data - Type T. - An input tensor. - -Returns -======= -size : Var - Type T1. - Total number of elements of the input tensor - -Notes -===== -Signature: ``ai.onnx@19::Size``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` + Takes a tensor as input and outputs a int64 scalar that equals to the + total number of elements of the input tensor. + + Parameters + ========== + data + Type T. + An input tensor. + + Returns + ======= + size : Var + Type T1. + Total number of elements of the input tensor + + Notes + ===== + Signature: ``ai.onnx@19::Size``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` """ - return _Size( - _Size.Attributes( - ), _Size.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).size + return ( + _Size( + _Size.Attributes(), + _Size.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .size + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -2637,4 +3134,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 004b613b..0e1d406a 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -1,219 +1,384 @@ +# Copyright (c) QuantCo 2023-2024 +# SPDX-License-Identifier: BSD-3-Clause + # ruff: noqa: E741 -- Allow ambiguous variable name -import typing -import warnings from dataclasses import dataclass -from collections.abc import Iterable, Sequence from typing import ( - Any, - Callable, Optional, - Union, ) -from typing import cast as typing_cast import numpy as np import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( - AttrDtype, - AttrFloat32, - AttrFloat32s, - AttrGraph, AttrInt64, - AttrInt64s, AttrString, - AttrStrings, AttrTensor, - AttrType, ) -from spox._graph import Graph, subgraph -from spox._internal_op import intro +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType -from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence -from spox._value_prop import PropValueType - - -from spox.opset.ai.onnx.v19 import _Abs, abs -from spox.opset.ai.onnx.v19 import _Acos, acos -from spox.opset.ai.onnx.v19 import _Acosh, acosh -from spox.opset.ai.onnx.v19 import _Add, add -from spox.opset.ai.onnx.v19 import _And, and_ -from spox.opset.ai.onnx.v19 import _ArgMax, arg_max -from spox.opset.ai.onnx.v19 import _ArgMin, arg_min -from spox.opset.ai.onnx.v19 import _Asin, asin -from spox.opset.ai.onnx.v19 import _Asinh, asinh -from spox.opset.ai.onnx.v19 import _Atan, atan -from spox.opset.ai.onnx.v19 import _Atanh, atanh -from spox.opset.ai.onnx.v19 import _AveragePool, average_pool -from spox.opset.ai.onnx.v19 import _BatchNormalization, batch_normalization -from spox.opset.ai.onnx.v19 import _Bernoulli, bernoulli -from spox.opset.ai.onnx.v19 import _BitShift, bit_shift -from spox.opset.ai.onnx.v19 import _BitwiseAnd, bitwise_and -from spox.opset.ai.onnx.v19 import _BitwiseNot, bitwise_not -from spox.opset.ai.onnx.v19 import _BitwiseOr, bitwise_or -from spox.opset.ai.onnx.v19 import _BitwiseXor, bitwise_xor -from spox.opset.ai.onnx.v19 import _BlackmanWindow, blackman_window -from spox.opset.ai.onnx.v19 import _Cast, cast -from spox.opset.ai.onnx.v19 import _CastLike, cast_like -from spox.opset.ai.onnx.v19 import _Ceil, ceil -from spox.opset.ai.onnx.v19 import _Celu, celu -from spox.opset.ai.onnx.v19 import _CenterCropPad, center_crop_pad -from spox.opset.ai.onnx.v19 import _Clip, clip -from spox.opset.ai.onnx.v19 import _Col2Im, col2_im -from spox.opset.ai.onnx.v19 import _Compress, compress -from spox.opset.ai.onnx.v19 import _Concat, concat -from spox.opset.ai.onnx.v19 import _ConcatFromSequence, concat_from_sequence -from spox.opset.ai.onnx.v19 import _Constant, constant -from spox.opset.ai.onnx.v19 import _Conv, conv -from spox.opset.ai.onnx.v19 import _ConvInteger, conv_integer -from spox.opset.ai.onnx.v19 import _ConvTranspose, conv_transpose -from spox.opset.ai.onnx.v19 import _Cos, cos -from spox.opset.ai.onnx.v19 import _Cosh, cosh -from spox.opset.ai.onnx.v19 import _CumSum, cumsum -from spox.opset.ai.onnx.v19 import _DeformConv, deform_conv -from spox.opset.ai.onnx.v19 import _DepthToSpace, depth_to_space -from spox.opset.ai.onnx.v19 import _DequantizeLinear, dequantize_linear -from spox.opset.ai.onnx.v19 import _Det, det -from spox.opset.ai.onnx.v19 import _Div, div -from spox.opset.ai.onnx.v19 import _Dropout, dropout -from spox.opset.ai.onnx.v19 import _DynamicQuantizeLinear, dynamic_quantize_linear -from spox.opset.ai.onnx.v19 import _Einsum, einsum -from spox.opset.ai.onnx.v19 import _Elu, elu -from spox.opset.ai.onnx.v19 import _Equal, equal -from spox.opset.ai.onnx.v19 import _Erf, erf -from spox.opset.ai.onnx.v19 import _Exp, exp -from spox.opset.ai.onnx.v19 import _Expand, expand -from spox.opset.ai.onnx.v19 import _EyeLike, eye_like -from spox.opset.ai.onnx.v19 import _Flatten, flatten -from spox.opset.ai.onnx.v19 import _Floor, floor -from spox.opset.ai.onnx.v19 import _GRU, gru -from spox.opset.ai.onnx.v19 import _Gather, gather -from spox.opset.ai.onnx.v19 import _GatherElements, gather_elements -from spox.opset.ai.onnx.v19 import _GatherND, gather_nd -from spox.opset.ai.onnx.v19 import _Gemm, gemm -from spox.opset.ai.onnx.v19 import _GlobalAveragePool, global_average_pool -from spox.opset.ai.onnx.v19 import _GlobalLpPool, global_lp_pool -from spox.opset.ai.onnx.v19 import _GlobalMaxPool, global_max_pool -from spox.opset.ai.onnx.v19 import _Greater, greater -from spox.opset.ai.onnx.v19 import _GreaterOrEqual, greater_or_equal -from spox.opset.ai.onnx.v19 import _GroupNormalization, group_normalization -from spox.opset.ai.onnx.v19 import _HammingWindow, hamming_window -from spox.opset.ai.onnx.v19 import _HannWindow, hann_window -from spox.opset.ai.onnx.v19 import _HardSigmoid, hard_sigmoid -from spox.opset.ai.onnx.v19 import _HardSwish, hard_swish -from spox.opset.ai.onnx.v19 import _Hardmax, hardmax -from spox.opset.ai.onnx.v19 import _Identity, identity -from spox.opset.ai.onnx.v19 import _If, if_ -from spox.opset.ai.onnx.v19 import _InstanceNormalization, instance_normalization -from spox.opset.ai.onnx.v19 import _LRN, lrn -from spox.opset.ai.onnx.v19 import _LSTM, lstm -from spox.opset.ai.onnx.v19 import _LayerNormalization, layer_normalization -from spox.opset.ai.onnx.v19 import _LeakyRelu, leaky_relu -from spox.opset.ai.onnx.v19 import _Less, less -from spox.opset.ai.onnx.v19 import _LessOrEqual, less_or_equal -from spox.opset.ai.onnx.v19 import _Log, log -from spox.opset.ai.onnx.v19 import _LogSoftmax, log_softmax -from spox.opset.ai.onnx.v19 import _Loop, loop -from spox.opset.ai.onnx.v19 import _LpNormalization, lp_normalization -from spox.opset.ai.onnx.v19 import _LpPool, lp_pool -from spox.opset.ai.onnx.v19 import _MatMul, matmul -from spox.opset.ai.onnx.v19 import _MatMulInteger, matmul_integer -from spox.opset.ai.onnx.v19 import _Max, max -from spox.opset.ai.onnx.v19 import _MaxPool, max_pool -from spox.opset.ai.onnx.v19 import _MaxRoiPool, max_roi_pool -from spox.opset.ai.onnx.v19 import _MaxUnpool, max_unpool -from spox.opset.ai.onnx.v19 import _Mean, mean -from spox.opset.ai.onnx.v19 import _MeanVarianceNormalization, mean_variance_normalization -from spox.opset.ai.onnx.v19 import _MelWeightMatrix, mel_weight_matrix -from spox.opset.ai.onnx.v19 import _Min, min -from spox.opset.ai.onnx.v19 import _Mish, mish -from spox.opset.ai.onnx.v19 import _Mod, mod -from spox.opset.ai.onnx.v19 import _Mul, mul -from spox.opset.ai.onnx.v19 import _Multinomial, multinomial -from spox.opset.ai.onnx.v19 import _Neg, neg -from spox.opset.ai.onnx.v19 import _NegativeLogLikelihoodLoss, negative_log_likelihood_loss -from spox.opset.ai.onnx.v19 import _NonMaxSuppression, non_max_suppression -from spox.opset.ai.onnx.v19 import _NonZero, non_zero -from spox.opset.ai.onnx.v19 import _Not, not_ -from spox.opset.ai.onnx.v19 import _OneHot, one_hot -from spox.opset.ai.onnx.v19 import _Optional, optional -from spox.opset.ai.onnx.v19 import _OptionalGetElement, optional_get_element -from spox.opset.ai.onnx.v19 import _OptionalHasElement, optional_has_element -from spox.opset.ai.onnx.v19 import _Or, or_ -from spox.opset.ai.onnx.v19 import _PRelu, prelu -from spox.opset.ai.onnx.v19 import _Pad, pad -from spox.opset.ai.onnx.v19 import _Pow, pow -from spox.opset.ai.onnx.v19 import _QLinearConv, qlinear_conv -from spox.opset.ai.onnx.v19 import _QLinearMatMul, qlinear_matmul -from spox.opset.ai.onnx.v19 import _QuantizeLinear, quantize_linear -from spox.opset.ai.onnx.v19 import _RNN, rnn -from spox.opset.ai.onnx.v19 import _RandomNormal, random_normal -from spox.opset.ai.onnx.v19 import _RandomNormalLike, random_normal_like -from spox.opset.ai.onnx.v19 import _RandomUniform, random_uniform -from spox.opset.ai.onnx.v19 import _RandomUniformLike, random_uniform_like -from spox.opset.ai.onnx.v19 import _Range, range -from spox.opset.ai.onnx.v19 import _Reciprocal, reciprocal -from spox.opset.ai.onnx.v19 import _ReduceL1, reduce_l1 -from spox.opset.ai.onnx.v19 import _ReduceL2, reduce_l2 -from spox.opset.ai.onnx.v19 import _ReduceLogSum, reduce_log_sum -from spox.opset.ai.onnx.v19 import _ReduceLogSumExp, reduce_log_sum_exp -from spox.opset.ai.onnx.v19 import _ReduceMean, reduce_mean -from spox.opset.ai.onnx.v19 import _ReduceProd, reduce_prod -from spox.opset.ai.onnx.v19 import _ReduceSum, reduce_sum -from spox.opset.ai.onnx.v19 import _ReduceSumSquare, reduce_sum_square -from spox.opset.ai.onnx.v19 import _Relu, relu -from spox.opset.ai.onnx.v19 import _Reshape, reshape -from spox.opset.ai.onnx.v19 import _Resize, resize -from spox.opset.ai.onnx.v19 import _ReverseSequence, reverse_sequence -from spox.opset.ai.onnx.v19 import _RoiAlign, roi_align -from spox.opset.ai.onnx.v19 import _Round, round -from spox.opset.ai.onnx.v19 import _STFT, stft -from spox.opset.ai.onnx.v19 import _Scan, scan -from spox.opset.ai.onnx.v19 import _ScatterElements, scatter_elements -from spox.opset.ai.onnx.v19 import _ScatterND, scatter_nd -from spox.opset.ai.onnx.v19 import _Selu, selu -from spox.opset.ai.onnx.v19 import _SequenceAt, sequence_at -from spox.opset.ai.onnx.v19 import _SequenceConstruct, sequence_construct -from spox.opset.ai.onnx.v19 import _SequenceEmpty, sequence_empty -from spox.opset.ai.onnx.v19 import _SequenceErase, sequence_erase -from spox.opset.ai.onnx.v19 import _SequenceInsert, sequence_insert -from spox.opset.ai.onnx.v19 import _SequenceLength, sequence_length -from spox.opset.ai.onnx.v19 import _SequenceMap, sequence_map -from spox.opset.ai.onnx.v19 import _Shape, shape -from spox.opset.ai.onnx.v19 import _Shrink, shrink -from spox.opset.ai.onnx.v19 import _Sigmoid, sigmoid -from spox.opset.ai.onnx.v19 import _Sign, sign -from spox.opset.ai.onnx.v19 import _Sin, sin -from spox.opset.ai.onnx.v19 import _Sinh, sinh -from spox.opset.ai.onnx.v19 import _Size, size -from spox.opset.ai.onnx.v19 import _Slice, slice -from spox.opset.ai.onnx.v19 import _Softmax, softmax -from spox.opset.ai.onnx.v19 import _SoftmaxCrossEntropyLoss, softmax_cross_entropy_loss -from spox.opset.ai.onnx.v19 import _Softplus, softplus -from spox.opset.ai.onnx.v19 import _Softsign, softsign -from spox.opset.ai.onnx.v19 import _SpaceToDepth, space_to_depth -from spox.opset.ai.onnx.v19 import _Split, split -from spox.opset.ai.onnx.v19 import _SplitToSequence, split_to_sequence -from spox.opset.ai.onnx.v19 import _Sqrt, sqrt -from spox.opset.ai.onnx.v19 import _Squeeze, squeeze -from spox.opset.ai.onnx.v19 import _StringNormalizer, string_normalizer -from spox.opset.ai.onnx.v19 import _Sub, sub -from spox.opset.ai.onnx.v19 import _Sum, sum -from spox.opset.ai.onnx.v19 import _Tan, tan -from spox.opset.ai.onnx.v19 import _Tanh, tanh -from spox.opset.ai.onnx.v19 import _TfIdfVectorizer, tf_idf_vectorizer -from spox.opset.ai.onnx.v19 import _ThresholdedRelu, thresholded_relu -from spox.opset.ai.onnx.v19 import _Tile, tile -from spox.opset.ai.onnx.v19 import _TopK, top_k -from spox.opset.ai.onnx.v19 import _Transpose, transpose -from spox.opset.ai.onnx.v19 import _Trilu, trilu -from spox.opset.ai.onnx.v19 import _Unique, unique -from spox.opset.ai.onnx.v19 import _Unsqueeze, unsqueeze -from spox.opset.ai.onnx.v19 import _Where, where -from spox.opset.ai.onnx.v19 import _Xor, xor +from spox._standard import StandardNode +from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox.opset.ai.onnx.v19 import ( + _GRU, + _LRN, + _LSTM, + _RNN, + _STFT, + _Abs, + _Acos, + _Acosh, + _Add, + _And, + _ArgMax, + _ArgMin, + _Asin, + _Asinh, + _Atan, + _Atanh, + _AveragePool, + _BatchNormalization, + _Bernoulli, + _BitShift, + _BitwiseAnd, + _BitwiseNot, + _BitwiseOr, + _BitwiseXor, + _BlackmanWindow, + _Cast, + _CastLike, + _Ceil, + _Celu, + _CenterCropPad, + _Clip, + _Col2Im, + _Compress, + _Concat, + _ConcatFromSequence, + _Constant, + _Conv, + _ConvInteger, + _ConvTranspose, + _Cos, + _Cosh, + _CumSum, + _DeformConv, + _DepthToSpace, + _DequantizeLinear, + _Det, + _Div, + _Dropout, + _DynamicQuantizeLinear, + _Einsum, + _Elu, + _Equal, + _Erf, + _Exp, + _Expand, + _EyeLike, + _Flatten, + _Floor, + _Gather, + _GatherElements, + _GatherND, + _Gemm, + _GlobalAveragePool, + _GlobalLpPool, + _GlobalMaxPool, + _Greater, + _GreaterOrEqual, + _GroupNormalization, + _HammingWindow, + _HannWindow, + _Hardmax, + _HardSigmoid, + _HardSwish, + _Identity, + _If, + _InstanceNormalization, + _LayerNormalization, + _LeakyRelu, + _Less, + _LessOrEqual, + _Log, + _LogSoftmax, + _Loop, + _LpNormalization, + _LpPool, + _MatMul, + _MatMulInteger, + _Max, + _MaxPool, + _MaxRoiPool, + _MaxUnpool, + _Mean, + _MeanVarianceNormalization, + _MelWeightMatrix, + _Min, + _Mish, + _Mod, + _Mul, + _Multinomial, + _Neg, + _NegativeLogLikelihoodLoss, + _NonMaxSuppression, + _NonZero, + _Not, + _OneHot, + _Optional, + _OptionalGetElement, + _OptionalHasElement, + _Or, + _Pad, + _Pow, + _PRelu, + _QLinearConv, + _QLinearMatMul, + _QuantizeLinear, + _RandomNormal, + _RandomNormalLike, + _RandomUniform, + _RandomUniformLike, + _Range, + _Reciprocal, + _ReduceL1, + _ReduceL2, + _ReduceLogSum, + _ReduceLogSumExp, + _ReduceMean, + _ReduceProd, + _ReduceSum, + _ReduceSumSquare, + _Relu, + _Reshape, + _Resize, + _ReverseSequence, + _RoiAlign, + _Round, + _Scan, + _ScatterElements, + _ScatterND, + _Selu, + _SequenceAt, + _SequenceConstruct, + _SequenceEmpty, + _SequenceErase, + _SequenceInsert, + _SequenceLength, + _SequenceMap, + _Shape, + _Shrink, + _Sigmoid, + _Sign, + _Sin, + _Sinh, + _Size, + _Slice, + _Softmax, + _SoftmaxCrossEntropyLoss, + _Softplus, + _Softsign, + _SpaceToDepth, + _Split, + _SplitToSequence, + _Sqrt, + _Squeeze, + _StringNormalizer, + _Sub, + _Sum, + _Tan, + _Tanh, + _TfIdfVectorizer, + _ThresholdedRelu, + _Tile, + _TopK, + _Transpose, + _Trilu, + _Unique, + _Unsqueeze, + _Where, + _Xor, + abs, + acos, + acosh, + add, + and_, + arg_max, + arg_min, + asin, + asinh, + atan, + atanh, + average_pool, + batch_normalization, + bernoulli, + bit_shift, + bitwise_and, + bitwise_not, + bitwise_or, + bitwise_xor, + blackman_window, + cast, + cast_like, + ceil, + celu, + center_crop_pad, + clip, + col2_im, + compress, + concat, + concat_from_sequence, + constant, + conv, + conv_integer, + conv_transpose, + cos, + cosh, + cumsum, + deform_conv, + depth_to_space, + dequantize_linear, + det, + div, + dropout, + dynamic_quantize_linear, + einsum, + elu, + equal, + erf, + exp, + expand, + eye_like, + flatten, + floor, + gather, + gather_elements, + gather_nd, + gemm, + global_average_pool, + global_lp_pool, + global_max_pool, + greater, + greater_or_equal, + group_normalization, + gru, + hamming_window, + hann_window, + hard_sigmoid, + hard_swish, + hardmax, + identity, + if_, + instance_normalization, + layer_normalization, + leaky_relu, + less, + less_or_equal, + log, + log_softmax, + loop, + lp_normalization, + lp_pool, + lrn, + lstm, + matmul, + matmul_integer, + max, + max_pool, + max_roi_pool, + max_unpool, + mean, + mean_variance_normalization, + mel_weight_matrix, + min, + mish, + mod, + mul, + multinomial, + neg, + negative_log_likelihood_loss, + non_max_suppression, + non_zero, + not_, + one_hot, + optional, + optional_get_element, + optional_has_element, + or_, + pad, + pow, + prelu, + qlinear_conv, + qlinear_matmul, + quantize_linear, + random_normal, + random_normal_like, + random_uniform, + random_uniform_like, + range, + reciprocal, + reduce_l1, + reduce_l2, + reduce_log_sum, + reduce_log_sum_exp, + reduce_mean, + reduce_prod, + reduce_sum, + reduce_sum_square, + relu, + reshape, + resize, + reverse_sequence, + rnn, + roi_align, + round, + scan, + scatter_elements, + scatter_nd, + selu, + sequence_at, + sequence_construct, + sequence_empty, + sequence_erase, + sequence_insert, + sequence_length, + sequence_map, + shape, + shrink, + sigmoid, + sign, + sin, + sinh, + size, + slice, + softmax, + softmax_cross_entropy_loss, + softplus, + softsign, + space_to_depth, + split, + split_to_sequence, + sqrt, + squeeze, + stft, + string_normalizer, + sub, + sum, + tan, + tanh, + tf_idf_vectorizer, + thresholded_relu, + tile, + top_k, + transpose, + trilu, + unique, + unsqueeze, + where, + xor, +) + + class _AffineGrid(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -234,6 +399,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ConstantOfShape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -253,6 +419,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _DFT(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -275,6 +442,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Gelu(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -294,6 +462,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GridSample(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -316,6 +485,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ImageDecoder(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -335,6 +505,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _IsInf(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -355,6 +526,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _IsNaN(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -374,6 +546,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceMax(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -395,6 +568,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _ReduceMin(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -416,6 +590,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _RegexFullMatch(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -435,6 +610,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _StringConcat(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -455,6 +631,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _StringSplit(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -476,770 +653,953 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs -def affine_grid(theta: Var, size: Var, *, align_corners: int = 0, ) -> Var: + +def affine_grid( + theta: Var, + size: Var, + *, + align_corners: int = 0, +) -> Var: r""" -Generates a 2D or 3D flow field (sampling grid), given a batch of affine -matrices theta -(https://pytorch.org/docs/stable/generated/torch.nn.functional.affine_grid.html). -An affine matrix ``theta`` is applied to a position tensor represented -in its homogeneous expression. Here is an example in 3D: - -:: - - [r00, r01, r02, t0] [x] [x'] - [r10, r11, r12, t1] * [y] = [y'] - [r20, r21, r22, t2] [z] [z'] - [0, 0, 0, 1 ] [1] [1 ] - -where ``(x, y, z)`` is the position in the original space, -``(x', y', z')`` is the position in the output space. The last row is -always ``[0, 0, 0, 1]`` and is not stored in the affine matrix. -Therefore we have ``theta`` of shape ``(N, 2, 3)`` for 2D or -``(N, 3, 4)`` for 3D. - -Input ``size`` is used to define grid of positions evenly spaced in the -original 2D or 3D space, with dimensions ranging from ``-1`` to ``1``. -The output ``grid`` contains positions in the output space. - -When ``align_corners=1``, consider ``-1`` and ``1`` to refer to the -centers of the corner pixels (mark ``v`` in illustration). - -:: - - v v v v - |-------------------|------------------| - -1 0 1 - -When ``align_corners=0``, consider ``-1`` and ``1`` to refer to the -outer edge of the corner pixels. - -:: - - v v v v - |------------------|-------------------| - -1 0 1 - -Parameters -========== -theta - Type T1. - input batch of affine matrices with shape (N, 2, 3) for 2D or (N, 3, 4) - for 3D -size - Type T2. - the target output image size (N, C, H, W) for 2D or (N, C, D, H, W) for - 3D -align_corners - Attribute. - if align_corners=1, consider -1 and 1 to refer to the centers of the - corner pixels. if align_corners=0, consider -1 and 1 to refer to the - outer edge the corner pixels. - -Returns -======= -grid : Var - Type T1. - output tensor of shape (N, H, W, 2) of 2D sample coordinates or (N, D, - H, W, 3) of 3D sample coordinates. - -Notes -===== -Signature: ``ai.onnx@20::AffineGrid``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int64)` + Generates a 2D or 3D flow field (sampling grid), given a batch of affine + matrices theta + (https://pytorch.org/docs/stable/generated/torch.nn.functional.affine_grid.html). + An affine matrix ``theta`` is applied to a position tensor represented + in its homogeneous expression. Here is an example in 3D: + + :: + + [r00, r01, r02, t0] [x] [x'] + [r10, r11, r12, t1] * [y] = [y'] + [r20, r21, r22, t2] [z] [z'] + [0, 0, 0, 1 ] [1] [1 ] + + where ``(x, y, z)`` is the position in the original space, + ``(x', y', z')`` is the position in the output space. The last row is + always ``[0, 0, 0, 1]`` and is not stored in the affine matrix. + Therefore we have ``theta`` of shape ``(N, 2, 3)`` for 2D or + ``(N, 3, 4)`` for 3D. + + Input ``size`` is used to define grid of positions evenly spaced in the + original 2D or 3D space, with dimensions ranging from ``-1`` to ``1``. + The output ``grid`` contains positions in the output space. + + When ``align_corners=1``, consider ``-1`` and ``1`` to refer to the + centers of the corner pixels (mark ``v`` in illustration). + + :: + + v v v v + |-------------------|------------------| + -1 0 1 + + When ``align_corners=0``, consider ``-1`` and ``1`` to refer to the + outer edge of the corner pixels. + + :: + + v v v v + |------------------|-------------------| + -1 0 1 + + Parameters + ========== + theta + Type T1. + input batch of affine matrices with shape (N, 2, 3) for 2D or (N, 3, 4) + for 3D + size + Type T2. + the target output image size (N, C, H, W) for 2D or (N, C, D, H, W) for + 3D + align_corners + Attribute. + if align_corners=1, consider -1 and 1 to refer to the centers of the + corner pixels. if align_corners=0, consider -1 and 1 to refer to the + outer edge the corner pixels. + + Returns + ======= + grid : Var + Type T1. + output tensor of shape (N, H, W, 2) of 2D sample coordinates or (N, D, + H, W, 3) of 3D sample coordinates. + + Notes + ===== + Signature: ``ai.onnx@20::AffineGrid``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int64)` """ - return _AffineGrid( - _AffineGrid.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - ), _AffineGrid.Inputs( - theta=unwrap_vars(theta), size=unwrap_vars(size), ), ).get_output_vars( - theta=get_value(theta), size=get_value(size), ).grid - - -def constant_of_shape(input: Var, *, value: Optional[np.ndarray] = None, ) -> Var: + return ( + _AffineGrid( + _AffineGrid.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + ), + _AffineGrid.Inputs( + theta=unwrap_vars(theta), + size=unwrap_vars(size), + ), + ) + .get_output_vars( + theta=get_value(theta), + size=get_value(size), + ) + .grid + ) + + +def constant_of_shape( + input: Var, + *, + value: Optional[np.ndarray] = None, +) -> Var: r""" -Generate a tensor with given value and shape. - -Parameters -========== -input - Type T1. - 1D tensor. The shape of the expected output tensor. If empty tensor is - given, the output would be a scalar. All values must be >= 0. -value - Attribute. - (Optional) The value of the output elements.Should be a one-element - tensor. If not specified, it defaults to a tensor of value 0 and - datatype float32 - -Returns -======= -output : Var - Type T2. - Output tensor of shape specified by 'input'.If attribute 'value' is - specified, the value and datatype of the output tensor is taken from - 'value'.If attribute 'value' is not specified, the value in the output - defaults to 0, and the datatype defaults to float32. - -Notes -===== -Signature: ``ai.onnx@20::ConstantOfShape``. - -Type constraints: - - T1: `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Generate a tensor with given value and shape. + + Parameters + ========== + input + Type T1. + 1D tensor. The shape of the expected output tensor. If empty tensor is + given, the output would be a scalar. All values must be >= 0. + value + Attribute. + (Optional) The value of the output elements.Should be a one-element + tensor. If not specified, it defaults to a tensor of value 0 and + datatype float32 + + Returns + ======= + output : Var + Type T2. + Output tensor of shape specified by 'input'.If attribute 'value' is + specified, the value and datatype of the output tensor is taken from + 'value'.If attribute 'value' is not specified, the value in the output + defaults to 0, and the datatype defaults to float32. + + Notes + ===== + Signature: ``ai.onnx@20::ConstantOfShape``. + + Type constraints: + - T1: `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), _ConstantOfShape.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), + _ConstantOfShape.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) + + +def dft( + input: Var, + dft_length: Optional[Var] = None, + axis: Optional[Var] = None, + *, + inverse: int = 0, + onesided: int = 0, +) -> Var: + r""" + Computes the discrete Fourier Transform (DFT) of the input. + Assuming the input has shape ``[M, N]``, where ``N`` is the dimension + over which the DFT is computed and ``M`` denotes the conceptual "all + other dimensions," the DFT ``y[m, k]`` of shape ``[M, N]`` is defined as -def dft(input: Var, dft_length: Optional[Var] = None, axis: Optional[Var] = None, *, inverse: int = 0, onesided: int = 0, ) -> Var: - r""" -Computes the discrete Fourier Transform (DFT) of the input. - -Assuming the input has shape ``[M, N]``, where ``N`` is the dimension -over which the DFT is computed and ``M`` denotes the conceptual "all -other dimensions," the DFT ``y[m, k]`` of shape ``[M, N]`` is defined as - -.. math:: y[m, k] = \sum_{n=0}^{N-1} e^{-2 \pi j \frac{k n}{N} } x[m, n] , - -and the inverse transform is defined as - -.. math:: x[m, n] = \frac{1}{N} \sum_{k=0}^{N-1} e^{2 \pi j \frac{k n}{N} } y[m, k] , - -where :math:`j` is the imaginary unit. - -The actual shape of the output is specified in the "output" section. - -Reference: https://docs.scipy.org/doc/scipy/tutorial/fft.html - -Parameters -========== -input - Type T1. - For real input, the following shape is expected: - ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][1]``. For - complex input, the following shape is expected: - ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][2]``. The - final dimension represents the real and imaginary parts of the value in - that order. -dft_length - Type T2. - The length of the signal as a scalar. If greater than the axis - dimension, the signal will be zero-padded up to ``dft_length``. If less - than the axis dimension, only the first ``dft_length`` values will be - used as the signal. -axis - Type tensor(int64). - The axis as a scalar on which to perform the DFT. Default is ``-2`` - (last signal axis). Negative value means counting dimensions from the - back. Accepted range is :math:`[-r, -2] \cup [0, r-2]` where - ``r = rank(input)``. The last dimension is for representing complex - numbers and thus is an invalid axis. -inverse - Attribute. - Whether to perform the inverse discrete Fourier Transform. Default is 0, - which corresponds to ``false``. -onesided - Attribute. - If ``onesided`` is ``1`` and input is real, only values for ``k`` in - ``[0, 1, 2, ..., floor(n_fft/2) + 1]`` are returned because the - real-to-complex Fourier transform satisfies the conjugate symmetry, - i.e., ``X[m, k] = X[m, n_fft-k]*``, where ``m`` denotes "all other - dimensions" DFT was not applied on. If the input tensor is complex, - onesided output is not possible. Value can be ``0`` or ``1``. Default is - ``0``. - -Returns -======= -output : Var - Type T1. - The Fourier Transform of the input vector. If ``onesided`` is ``0``, the - following shape is expected: - ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][2]``. If - ``axis=0`` and ``onesided`` is ``1``, the following shape is expected: - ``[floor(signal_dim0/2)+1][signal_dim1][signal_dim2]...[signal_dimN][2]``. - If ``axis=1`` and ``onesided`` is ``1``, the following shape is - expected: - ``[signal_dim0][floor(signal_dim1/2)+1][signal_dim2]...[signal_dimN][2]``. - If ``axis=N`` and ``onesided`` is ``1``, the following shape is - expected: - ``[signal_dim0][signal_dim1][signal_dim2]...[floor(signal_dimN/2)+1][2]``. - The ``signal_dim`` at the specified ``axis`` is equal to the - ``dft_length``. - -Notes -===== -Signature: ``ai.onnx@20::DFT``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(int32)`, `tensor(int64)` - """ - return _DFT( - _DFT.Attributes( - inverse=AttrInt64(inverse, name="inverse"), - onesided=AttrInt64(onesided, name="onesided"), - ), _DFT.Inputs( - input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), axis=unwrap_vars(axis), ), ).get_output_vars( - input=get_value(input), dft_length=get_value(dft_length), axis=get_value(axis), ).output + .. math:: y[m, k] = \sum_{n=0}^{N-1} e^{-2 \pi j \frac{k n}{N} } x[m, n] , + and the inverse transform is defined as -def gelu(X: Var, *, approximate: str = "none", ) -> Var: - r""" -Gelu takes one input data (Tensor) and produces one output data -(Tensor) where the gaussian error linear units function, -:math:`y = 0.5 * x * (1 + erf(x/sqrt(2)))` is applied to the tensor -elementwise. If the attribute "approximate" is set to "tanh", the -function estimation, -:math:`y = 0.5 * x * (1 + Tanh(sqrt(2/\pi) * (x + 0.044715 * x^3)))` is -used and applied to the tensor elementwise. - -Parameters -========== -X - Type T. - Input tensor -approximate - Attribute. - Gelu approximation algorithm: ``"tanh"``, - ``"none"``\ (default).\ ``"none"``: do not use - approximation.\ ``"tanh"``: use tanh approximation. - -Returns -======= -Y : Var - Type T. - Output tensor - -Notes -===== -Signature: ``ai.onnx@20::Gelu``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _Gelu( - _Gelu.Attributes( - approximate=AttrString(approximate, name="approximate"), - ), _Gelu.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y + .. math:: x[m, n] = \frac{1}{N} \sum_{k=0}^{N-1} e^{2 \pi j \frac{k n}{N} } y[m, k] , + where :math:`j` is the imaginary unit. -def grid_sample(X: Var, grid: Var, *, align_corners: int = 0, mode: str = "linear", padding_mode: str = "zeros", ) -> Var: - r""" -Given an input ``X`` and a flow-field ``grid``, computes the output -``Y`` using ``X`` values and pixel locations from the ``grid``. For -spatial input ``X`` with shape (N, C, H, W), the ``grid`` will have -shape (N, H_out, W_out, 2), the output ``Y`` will have shape (N, C, -H_out, W_out). For volumetric input ``X`` with shape (N, C, D, H, W), -the ``grid`` will have shape (N, D_out, H_out, W_out, 3), the output -``Y`` will have shape (N, C, D_out, H_out, W_out). More generally, for -an input ``X`` of rank r+2 with shape (N, C, d1, d2, ..., dr), the -``grid`` will have shape (N, D1_out, D2_out, ..., Dr_out, r), the output -``Y`` will have shape (N, C, D1_out, D2_out, ..., Dr_out). - -The tensor ``X`` contains values at centers of square pixels (voxels, -etc) locations such as (n, c, d1_in, d2_in, ..., dr_in). The (n, d1_out, -d2_out, ..., dr_out, :) values from the tensor ``grid`` are the -normalized positions for interpolating the values at the (n, c, d1_out, -d2_out, ..., dr_out) locations from the output tensor ``Y`` using a -specified interpolation method (the mode) and a padding mode (for -``grid`` positions falling outside the 2-dimensional image). - -For example, the values in ``grid[n, h_out, w_out, :]`` are size-2 -vectors specifying normalized positions in the 2-dimensional space of -``X``. They are used to interpolate output values of -``Y[n, c, h_out, w_out]``. - -The GridSample operator is often used in doing grid generator and -sampler in the `Spatial Transformer -Networks `__. See also in -`torch.nn.functional.grid_sample `__. - -Parameters -========== -X - Type T1. - Input tensor of rank r+2 that has shape (N, C, D1, D2, ..., Dr), where N - is the batch size, C is the number of channels, D1, D2, ..., Dr are the - spatial dimensions. -grid - Type T2. - Input offset of shape (N, D1_out, D2_out, ..., Dr_out, r), where D1_out, - D2_out, ..., Dr_out are the spatial dimensions of the grid and output, - and r is the number of spatial dimensions. Grid specifies the sampling - locations normalized by the input spatial dimensions. Therefore, it - should have most values in the range of [-1, 1]. If the grid has values - outside the range of [-1, 1], the corresponding outputs will be handled - as defined by padding_mode. Following computer vision convention, the - coordinates in the length-r location vector are listed from the - innermost tensor dimension to the outermost, the opposite of regular - tensor indexing. -align_corners - Attribute. - If align_corners=1, the extrema (-1 and 1) are considered as referring - to the center points of the input's corner pixels (voxels, etc.). If - align_corners=0, they are instead considered as referring to the corner - points of the input's corner pixels (voxels, etc.), making the sampling - more resolution agnostic. -mode - Attribute. - Three interpolation modes: linear (default), nearest and cubic. The - "linear" mode includes linear and N-linear interpolation modes depending - on the number of spatial dimensions of the input tensor (i.e. linear for - 1 spatial dimension, bilinear for 2 spatial dimensions, etc.). The - "cubic" mode also includes N-cubic interpolation modes following the - same rules. The "nearest" mode rounds to the nearest even index when the - sampling point falls halfway between two indices. -padding_mode - Attribute. - Support padding modes for outside grid values: ``zeros``\ (default), - ``border``, ``reflection``. zeros: use 0 for out-of-bound grid - locations, border: use border values for out-of-bound grid locations, - reflection: use values at locations reflected by the border for - out-of-bound grid locations. If index 0 represents the margin pixel, the - reflected value at index -1 will be the same as the value at index 1. - For location far away from the border, it will keep being reflected - until becoming in bound. If pixel location x = -3.5 reflects by border - -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = - 0.5. - -Returns -======= -Y : Var - Type T1. - Output tensor of rank r+2 that has shape (N, C, D1_out, D2_out, ..., - Dr_out) of the sampled values. For integer input types, intermediate - values are computed as floating point and cast to integer at the end. - -Notes -===== -Signature: ``ai.onnx@20::GridSample``. - -Type constraints: - - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` - """ - return _GridSample( - _GridSample.Attributes( - align_corners=AttrInt64(align_corners, name="align_corners"), - mode=AttrString(mode, name="mode"), - padding_mode=AttrString(padding_mode, name="padding_mode"), - ), _GridSample.Inputs( - X=unwrap_vars(X), grid=unwrap_vars(grid), ), ).get_output_vars( - X=get_value(X), grid=get_value(grid), ).Y + The actual shape of the output is specified in the "output" section. + Reference: https://docs.scipy.org/doc/scipy/tutorial/fft.html -def image_decoder(encoded_stream: Var, *, pixel_format: str = "RGB", ) -> Var: + Parameters + ========== + input + Type T1. + For real input, the following shape is expected: + ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][1]``. For + complex input, the following shape is expected: + ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][2]``. The + final dimension represents the real and imaginary parts of the value in + that order. + dft_length + Type T2. + The length of the signal as a scalar. If greater than the axis + dimension, the signal will be zero-padded up to ``dft_length``. If less + than the axis dimension, only the first ``dft_length`` values will be + used as the signal. + axis + Type tensor(int64). + The axis as a scalar on which to perform the DFT. Default is ``-2`` + (last signal axis). Negative value means counting dimensions from the + back. Accepted range is :math:`[-r, -2] \cup [0, r-2]` where + ``r = rank(input)``. The last dimension is for representing complex + numbers and thus is an invalid axis. + inverse + Attribute. + Whether to perform the inverse discrete Fourier Transform. Default is 0, + which corresponds to ``false``. + onesided + Attribute. + If ``onesided`` is ``1`` and input is real, only values for ``k`` in + ``[0, 1, 2, ..., floor(n_fft/2) + 1]`` are returned because the + real-to-complex Fourier transform satisfies the conjugate symmetry, + i.e., ``X[m, k] = X[m, n_fft-k]*``, where ``m`` denotes "all other + dimensions" DFT was not applied on. If the input tensor is complex, + onesided output is not possible. Value can be ``0`` or ``1``. Default is + ``0``. + + Returns + ======= + output : Var + Type T1. + The Fourier Transform of the input vector. If ``onesided`` is ``0``, the + following shape is expected: + ``[signal_dim0][signal_dim1][signal_dim2]...[signal_dimN][2]``. If + ``axis=0`` and ``onesided`` is ``1``, the following shape is expected: + ``[floor(signal_dim0/2)+1][signal_dim1][signal_dim2]...[signal_dimN][2]``. + If ``axis=1`` and ``onesided`` is ``1``, the following shape is + expected: + ``[signal_dim0][floor(signal_dim1/2)+1][signal_dim2]...[signal_dimN][2]``. + If ``axis=N`` and ``onesided`` is ``1``, the following shape is + expected: + ``[signal_dim0][signal_dim1][signal_dim2]...[floor(signal_dimN/2)+1][2]``. + The ``signal_dim`` at the specified ``axis`` is equal to the + ``dft_length``. + + Notes + ===== + Signature: ``ai.onnx@20::DFT``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(int32)`, `tensor(int64)` + """ + return ( + _DFT( + _DFT.Attributes( + inverse=AttrInt64(inverse, name="inverse"), + onesided=AttrInt64(onesided, name="onesided"), + ), + _DFT.Inputs( + input=unwrap_vars(input), + dft_length=unwrap_vars(dft_length), + axis=unwrap_vars(axis), + ), + ) + .get_output_vars( + input=get_value(input), + dft_length=get_value(dft_length), + axis=get_value(axis), + ) + .output + ) + + +def gelu( + X: Var, + *, + approximate: str = "none", +) -> Var: r""" -Loads and decodes and image from a file. If it can't decode for any -reason (e.g. corrupted encoded stream, invalid format, it will return an -empty matrix). The following image formats are supported: - -- BMP -- JPEG (note: Lossless JPEG support is optional) -- JPEG2000 -- TIFF -- PNG -- WebP -- Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow - a channel-last layout: (Height, Width, Channels). **JPEG chroma - upsampling method:** When upsampling the chroma components by a - factor of 2, the pixels are linearly interpolated so that the centers - of the output pixels are 1/4 and 3/4 of the way between input pixel - centers. When rounding, 0.5 is rounded down and up at alternative - pixels locations to prevent bias towards larger values (ordered - dither pattern). Considering adjacent input pixels A, B, and C, B is - upsampled to pixels B0 and B1 so that - -:: - - B0 = round_half_down((1/4) * A + (3/4) * B) - B1 = round_half_up((3/4) * B + (1/4) * C) - -This method, is the default chroma upsampling method in the -well-established libjpeg-turbo library, also referred as "smooth" or -"fancy" upsampling. - -Parameters -========== -encoded_stream - Type T1. - Encoded stream -pixel_format - Attribute. - Pixel format. Can be one of "RGB", "BGR", or "Grayscale". - -Returns -======= -image : Var - Type T2. - Decoded image - -Notes -===== -Signature: ``ai.onnx@20::ImageDecoder``. - -Type constraints: - - T1: `tensor(uint8)` - - T2: `tensor(uint8)` + Gelu takes one input data (Tensor) and produces one output data + (Tensor) where the gaussian error linear units function, + :math:`y = 0.5 * x * (1 + erf(x/sqrt(2)))` is applied to the tensor + elementwise. If the attribute "approximate" is set to "tanh", the + function estimation, + :math:`y = 0.5 * x * (1 + Tanh(sqrt(2/\pi) * (x + 0.044715 * x^3)))` is + used and applied to the tensor elementwise. + + Parameters + ========== + X + Type T. + Input tensor + approximate + Attribute. + Gelu approximation algorithm: ``"tanh"``, + ``"none"``\ (default).\ ``"none"``: do not use + approximation.\ ``"tanh"``: use tanh approximation. + + Returns + ======= + Y : Var + Type T. + Output tensor + + Notes + ===== + Signature: ``ai.onnx@20::Gelu``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _ImageDecoder( - _ImageDecoder.Attributes( - pixel_format=AttrString(pixel_format, name="pixel_format"), - ), _ImageDecoder.Inputs( - encoded_stream=unwrap_vars(encoded_stream), ), ).get_output_vars( - encoded_stream=get_value(encoded_stream), ).image - - -def isinf(X: Var, *, detect_negative: int = 1, detect_positive: int = 1, ) -> Var: + return ( + _Gelu( + _Gelu.Attributes( + approximate=AttrString(approximate, name="approximate"), + ), + _Gelu.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def grid_sample( + X: Var, + grid: Var, + *, + align_corners: int = 0, + mode: str = "linear", + padding_mode: str = "zeros", +) -> Var: r""" -Map infinity to true and other values to false. - -Parameters -========== -X - Type T1. - input -detect_negative - Attribute. - (Optional) Whether map negative infinity to true. Default to 1 so that - negative infinity induces true. Set this attribute to 0 if negative - infinity should be mapped to false. -detect_positive - Attribute. - (Optional) Whether map positive infinity to true. Default to 1 so that - positive infinity induces true. Set this attribute to 0 if positive - infinity should be mapped to false. - -Returns -======= -Y : Var - Type T2. - output - -Notes -===== -Signature: ``ai.onnx@20::IsInf``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - - T2: `tensor(bool)` + Given an input ``X`` and a flow-field ``grid``, computes the output + ``Y`` using ``X`` values and pixel locations from the ``grid``. For + spatial input ``X`` with shape (N, C, H, W), the ``grid`` will have + shape (N, H_out, W_out, 2), the output ``Y`` will have shape (N, C, + H_out, W_out). For volumetric input ``X`` with shape (N, C, D, H, W), + the ``grid`` will have shape (N, D_out, H_out, W_out, 3), the output + ``Y`` will have shape (N, C, D_out, H_out, W_out). More generally, for + an input ``X`` of rank r+2 with shape (N, C, d1, d2, ..., dr), the + ``grid`` will have shape (N, D1_out, D2_out, ..., Dr_out, r), the output + ``Y`` will have shape (N, C, D1_out, D2_out, ..., Dr_out). + + The tensor ``X`` contains values at centers of square pixels (voxels, + etc) locations such as (n, c, d1_in, d2_in, ..., dr_in). The (n, d1_out, + d2_out, ..., dr_out, :) values from the tensor ``grid`` are the + normalized positions for interpolating the values at the (n, c, d1_out, + d2_out, ..., dr_out) locations from the output tensor ``Y`` using a + specified interpolation method (the mode) and a padding mode (for + ``grid`` positions falling outside the 2-dimensional image). + + For example, the values in ``grid[n, h_out, w_out, :]`` are size-2 + vectors specifying normalized positions in the 2-dimensional space of + ``X``. They are used to interpolate output values of + ``Y[n, c, h_out, w_out]``. + + The GridSample operator is often used in doing grid generator and + sampler in the `Spatial Transformer + Networks `__. See also in + `torch.nn.functional.grid_sample `__. + + Parameters + ========== + X + Type T1. + Input tensor of rank r+2 that has shape (N, C, D1, D2, ..., Dr), where N + is the batch size, C is the number of channels, D1, D2, ..., Dr are the + spatial dimensions. + grid + Type T2. + Input offset of shape (N, D1_out, D2_out, ..., Dr_out, r), where D1_out, + D2_out, ..., Dr_out are the spatial dimensions of the grid and output, + and r is the number of spatial dimensions. Grid specifies the sampling + locations normalized by the input spatial dimensions. Therefore, it + should have most values in the range of [-1, 1]. If the grid has values + outside the range of [-1, 1], the corresponding outputs will be handled + as defined by padding_mode. Following computer vision convention, the + coordinates in the length-r location vector are listed from the + innermost tensor dimension to the outermost, the opposite of regular + tensor indexing. + align_corners + Attribute. + If align_corners=1, the extrema (-1 and 1) are considered as referring + to the center points of the input's corner pixels (voxels, etc.). If + align_corners=0, they are instead considered as referring to the corner + points of the input's corner pixels (voxels, etc.), making the sampling + more resolution agnostic. + mode + Attribute. + Three interpolation modes: linear (default), nearest and cubic. The + "linear" mode includes linear and N-linear interpolation modes depending + on the number of spatial dimensions of the input tensor (i.e. linear for + 1 spatial dimension, bilinear for 2 spatial dimensions, etc.). The + "cubic" mode also includes N-cubic interpolation modes following the + same rules. The "nearest" mode rounds to the nearest even index when the + sampling point falls halfway between two indices. + padding_mode + Attribute. + Support padding modes for outside grid values: ``zeros``\ (default), + ``border``, ``reflection``. zeros: use 0 for out-of-bound grid + locations, border: use border values for out-of-bound grid locations, + reflection: use values at locations reflected by the border for + out-of-bound grid locations. If index 0 represents the margin pixel, the + reflected value at index -1 will be the same as the value at index 1. + For location far away from the border, it will keep being reflected + until becoming in bound. If pixel location x = -3.5 reflects by border + -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = + 0.5. + + Returns + ======= + Y : Var + Type T1. + Output tensor of rank r+2 that has shape (N, C, D1_out, D2_out, ..., + Dr_out) of the sampled values. For integer input types, intermediate + values are computed as floating point and cast to integer at the end. + + Notes + ===== + Signature: ``ai.onnx@20::GridSample``. + + Type constraints: + - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _IsInf( - _IsInf.Attributes( - detect_negative=AttrInt64(detect_negative, name="detect_negative"), - detect_positive=AttrInt64(detect_positive, name="detect_positive"), - ), _IsInf.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def isnan(X: Var, ) -> Var: + return ( + _GridSample( + _GridSample.Attributes( + align_corners=AttrInt64(align_corners, name="align_corners"), + mode=AttrString(mode, name="mode"), + padding_mode=AttrString(padding_mode, name="padding_mode"), + ), + _GridSample.Inputs( + X=unwrap_vars(X), + grid=unwrap_vars(grid), + ), + ) + .get_output_vars( + X=get_value(X), + grid=get_value(grid), + ) + .Y + ) + + +def image_decoder( + encoded_stream: Var, + *, + pixel_format: str = "RGB", +) -> Var: r""" -Returns which elements of the input are NaN. - -Parameters -========== -X - Type T1. - input - -Returns -======= -Y : Var - Type T2. - output - -Notes -===== -Signature: ``ai.onnx@20::IsNaN``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - - T2: `tensor(bool)` + Loads and decodes and image from a file. If it can't decode for any + reason (e.g. corrupted encoded stream, invalid format, it will return an + empty matrix). The following image formats are supported: + + - BMP + - JPEG (note: Lossless JPEG support is optional) + - JPEG2000 + - TIFF + - PNG + - WebP + - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow + a channel-last layout: (Height, Width, Channels). **JPEG chroma + upsampling method:** When upsampling the chroma components by a + factor of 2, the pixels are linearly interpolated so that the centers + of the output pixels are 1/4 and 3/4 of the way between input pixel + centers. When rounding, 0.5 is rounded down and up at alternative + pixels locations to prevent bias towards larger values (ordered + dither pattern). Considering adjacent input pixels A, B, and C, B is + upsampled to pixels B0 and B1 so that + + :: + + B0 = round_half_down((1/4) * A + (3/4) * B) + B1 = round_half_up((3/4) * B + (1/4) * C) + + This method, is the default chroma upsampling method in the + well-established libjpeg-turbo library, also referred as "smooth" or + "fancy" upsampling. + + Parameters + ========== + encoded_stream + Type T1. + Encoded stream + pixel_format + Attribute. + Pixel format. Can be one of "RGB", "BGR", or "Grayscale". + + Returns + ======= + image : Var + Type T2. + Decoded image + + Notes + ===== + Signature: ``ai.onnx@20::ImageDecoder``. + + Type constraints: + - T1: `tensor(uint8)` + - T2: `tensor(uint8)` """ - return _IsNaN( - _IsNaN.Attributes( - ), _IsNaN.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def reduce_max(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _ImageDecoder( + _ImageDecoder.Attributes( + pixel_format=AttrString(pixel_format, name="pixel_format"), + ), + _ImageDecoder.Inputs( + encoded_stream=unwrap_vars(encoded_stream), + ), + ) + .get_output_vars( + encoded_stream=get_value(encoded_stream), + ) + .image + ) + + +def isinf( + X: Var, + *, + detect_negative: int = 1, + detect_positive: int = 1, +) -> Var: r""" -Computes the max of the input tensor's elements along the provided axes. -The resulting tensor has the same rank as the input if ``keepdims`` -equals 1. If ``keepdims`` equals 0, then the resulting tensor has the -reduced dimension pruned. Input tensors of rank zero are valid. -Reduction over an empty set of values yields minus infinity (if -supported by the datatype) or the minimum value of the data type -otherwise. - -If the input data type is Boolean, the comparison should consider -``False < True``. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@20::ReduceMax``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Map infinity to true and other values to false. + + Parameters + ========== + X + Type T1. + input + detect_negative + Attribute. + (Optional) Whether map negative infinity to true. Default to 1 so that + negative infinity induces true. Set this attribute to 0 if negative + infinity should be mapped to false. + detect_positive + Attribute. + (Optional) Whether map positive infinity to true. Default to 1 so that + positive infinity induces true. Set this attribute to 0 if positive + infinity should be mapped to false. + + Returns + ======= + Y : Var + Type T2. + output + + Notes + ===== + Signature: ``ai.onnx@20::IsInf``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` + - T2: `tensor(bool)` """ - return _ReduceMax( - _ReduceMax.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceMax.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def reduce_min(data: Var, axes: Optional[Var] = None, *, keepdims: int = 1, noop_with_empty_axes: int = 0, ) -> Var: + return ( + _IsInf( + _IsInf.Attributes( + detect_negative=AttrInt64(detect_negative, name="detect_negative"), + detect_positive=AttrInt64(detect_positive, name="detect_positive"), + ), + _IsInf.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def isnan( + X: Var, +) -> Var: r""" -Computes the min of the input tensor's elements along the provided axes. -The resulting tensor has the same rank as the input if ``keepdims`` -equals 1. If ``keepdims`` equals 0, then the resulting tensor has the -reduced dimension pruned. Input tensors of rank zero are valid. -Reduction over an empty set of values yields plus infinity (if supported -by the datatype) or the maximum value of the data type otherwise. - -If the input data type is Boolean, the comparison should consider -``False < True``. - -The above behavior is similar to numpy, with the exception that numpy -defaults ``keepdims`` to ``False`` instead of ``True``. - -Parameters -========== -data - Type T. - An input tensor. -axes - Type tensor(int64). - Optional input list of integers, along which to reduce. The default is - to reduce over all the dimensions of the input tensor if - 'noop_with_empty_axes' is false, else act as an Identity op when - 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = - rank(data). -keepdims - Attribute. - Keep the reduced dimension or not, default 1 means keep reduced - dimension. -noop_with_empty_axes - Attribute. - Defines behavior if 'axes' is empty. Default behavior with 'false' is to - reduce all axes. When axes is empty and this attribute is set to true, - input tensor will not be reduced,and the output tensor would be - equivalent to input tensor. - -Returns -======= -reduced : Var - Type T. - Reduced output tensor. - -Notes -===== -Signature: ``ai.onnx@20::ReduceMin``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` + Returns which elements of the input are NaN. + + Parameters + ========== + X + Type T1. + input + + Returns + ======= + Y : Var + Type T2. + output + + Notes + ===== + Signature: ``ai.onnx@20::IsNaN``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` + - T2: `tensor(bool)` """ - return _ReduceMin( - _ReduceMin.Attributes( - keepdims=AttrInt64(keepdims, name="keepdims"), - noop_with_empty_axes=AttrInt64(noop_with_empty_axes, name="noop_with_empty_axes"), - ), _ReduceMin.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).reduced - - -def regex_full_match(X: Var, *, pattern: Optional[str] = None, ) -> Var: + return ( + _IsNaN( + _IsNaN.Attributes(), + _IsNaN.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def reduce_max( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -RegexFullMatch performs a full regex match on each element of the input -tensor. If an element fully matches the regex pattern specified as an -attribute, the corresponding element in the output is True and it is -False otherwise. `RE2 `__ -regex syntax is used. - -Parameters -========== -X - Type T1. - Tensor with strings to match on. -pattern - Attribute. - Regex pattern to match on. This must be valid RE2 syntax. - -Returns -======= -Y : Var - Type T2. - Tensor of bools indicating if each input string fully matches the regex - pattern specified. - -Notes -===== -Signature: ``ai.onnx@20::RegexFullMatch``. - -Type constraints: - - T1: `tensor(string)` - - T2: `tensor(bool)` + Computes the max of the input tensor's elements along the provided axes. + The resulting tensor has the same rank as the input if ``keepdims`` + equals 1. If ``keepdims`` equals 0, then the resulting tensor has the + reduced dimension pruned. Input tensors of rank zero are valid. + Reduction over an empty set of values yields minus infinity (if + supported by the datatype) or the minimum value of the data type + otherwise. + + If the input data type is Boolean, the comparison should consider + ``False < True``. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@20::ReduceMax``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _RegexFullMatch( - _RegexFullMatch.Attributes( - pattern=AttrString.maybe(pattern, name="pattern"), - ), _RegexFullMatch.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), ).Y - - -def string_concat(X: Var, Y: Var, ) -> Var: + return ( + _ReduceMax( + _ReduceMax.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceMax.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def reduce_min( + data: Var, + axes: Optional[Var] = None, + *, + keepdims: int = 1, + noop_with_empty_axes: int = 0, +) -> Var: r""" -StringConcat concatenates string tensors elementwise (with NumPy-style -broadcasting support) - -Parameters -========== -X - Type T. - Tensor to prepend in concatenation -Y - Type T. - Tensor to append in concatenation - -Returns -======= -Z : Var - Type T. - Concatenated string tensor - -Notes -===== -Signature: ``ai.onnx@20::StringConcat``. - -Type constraints: - - T: `tensor(string)` + Computes the min of the input tensor's elements along the provided axes. + The resulting tensor has the same rank as the input if ``keepdims`` + equals 1. If ``keepdims`` equals 0, then the resulting tensor has the + reduced dimension pruned. Input tensors of rank zero are valid. + Reduction over an empty set of values yields plus infinity (if supported + by the datatype) or the maximum value of the data type otherwise. + + If the input data type is Boolean, the comparison should consider + ``False < True``. + + The above behavior is similar to numpy, with the exception that numpy + defaults ``keepdims`` to ``False`` instead of ``True``. + + Parameters + ========== + data + Type T. + An input tensor. + axes + Type tensor(int64). + Optional input list of integers, along which to reduce. The default is + to reduce over all the dimensions of the input tensor if + 'noop_with_empty_axes' is false, else act as an Identity op when + 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = + rank(data). + keepdims + Attribute. + Keep the reduced dimension or not, default 1 means keep reduced + dimension. + noop_with_empty_axes + Attribute. + Defines behavior if 'axes' is empty. Default behavior with 'false' is to + reduce all axes. When axes is empty and this attribute is set to true, + input tensor will not be reduced,and the output tensor would be + equivalent to input tensor. + + Returns + ======= + reduced : Var + Type T. + Reduced output tensor. + + Notes + ===== + Signature: ``ai.onnx@20::ReduceMin``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - return _StringConcat( - _StringConcat.Attributes( - ), _StringConcat.Inputs( - X=unwrap_vars(X), Y=unwrap_vars(Y), ), ).get_output_vars( - X=get_value(X), Y=get_value(Y), ).Z - - -def string_split(X: Var, *, delimiter: Optional[str] = None, maxsplit: Optional[int] = None, ) -> tuple[Var, Var]: + return ( + _ReduceMin( + _ReduceMin.Attributes( + keepdims=AttrInt64(keepdims, name="keepdims"), + noop_with_empty_axes=AttrInt64( + noop_with_empty_axes, name="noop_with_empty_axes" + ), + ), + _ReduceMin.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .reduced + ) + + +def regex_full_match( + X: Var, + *, + pattern: Optional[str] = None, +) -> Var: + r""" + RegexFullMatch performs a full regex match on each element of the input + tensor. If an element fully matches the regex pattern specified as an + attribute, the corresponding element in the output is True and it is + False otherwise. `RE2 `__ + regex syntax is used. + + Parameters + ========== + X + Type T1. + Tensor with strings to match on. + pattern + Attribute. + Regex pattern to match on. This must be valid RE2 syntax. + + Returns + ======= + Y : Var + Type T2. + Tensor of bools indicating if each input string fully matches the regex + pattern specified. + + Notes + ===== + Signature: ``ai.onnx@20::RegexFullMatch``. + + Type constraints: + - T1: `tensor(string)` + - T2: `tensor(bool)` + """ + return ( + _RegexFullMatch( + _RegexFullMatch.Attributes( + pattern=AttrString.maybe(pattern, name="pattern"), + ), + _RegexFullMatch.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + .Y + ) + + +def string_concat( + X: Var, + Y: Var, +) -> Var: + r""" + StringConcat concatenates string tensors elementwise (with NumPy-style + broadcasting support) + + Parameters + ========== + X + Type T. + Tensor to prepend in concatenation + Y + Type T. + Tensor to append in concatenation + + Returns + ======= + Z : Var + Type T. + Concatenated string tensor + + Notes + ===== + Signature: ``ai.onnx@20::StringConcat``. + + Type constraints: + - T: `tensor(string)` + """ + return ( + _StringConcat( + _StringConcat.Attributes(), + _StringConcat.Inputs( + X=unwrap_vars(X), + Y=unwrap_vars(Y), + ), + ) + .get_output_vars( + X=get_value(X), + Y=get_value(Y), + ) + .Z + ) + + +def string_split( + X: Var, + *, + delimiter: Optional[str] = None, + maxsplit: Optional[int] = None, +) -> tuple[Var, Var]: r""" -StringSplit splits a string tensor's elements into substrings based on a -delimiter attribute and a maxsplit attribute. - -The first output of this operator is a tensor of strings representing -the substrings from splitting each input string on the ``delimiter`` -substring. This tensor has one additional rank compared to the input -tensor in order to store the substrings for each input element (where -the input tensor is not empty). Note that, in order to ensure the same -number of elements are present in the final dimension, this tensor will -pad empty strings as illustrated in the examples below. Consecutive -delimiters are not grouped together and are deemed to delimit empty -strings, except if the ``delimiter`` is unspecified or is the empty -string (""). In the case where the ``delimiter`` is unspecified or the -empty string, consecutive whitespace characters are regarded as a single -separator and leading or trailing whitespace is removed in the output. - -The second output tensor represents the number of substrings generated. -``maxsplit`` can be used to limit the number of splits performed - after -the ``maxsplit``\ th split if the string is not fully split, the -trailing suffix of input string after the final split point is also -added. For elements where fewer splits are possible than specified in -``maxsplit``, it has no effect. - -Parameters -========== -X - Type T1. - Tensor of strings to split. -delimiter - Attribute. - Delimiter to split on. If left unset or set to the empty string (""), - the input is split on consecutive whitespace. -maxsplit - Attribute. - Maximum number of splits (from left to right). If left unset (or if the - number of possible splits are less than maxsplit), it will make as many - splits as possible. Note that the maximum possible number of substrings - returned with ``maxsplit`` specified is ``maxsplit+1`` since the - remaining suffix after the ``maxsplit``\ th split is included in the - output. - -Returns -======= -Y : Var - Type T2. - Tensor of substrings representing the outcome of splitting the strings - in the input on the delimiter. Note that to ensure the same number of - elements are present in the final rank, this tensor will pad any - necessary empty strings. -Z : Var - Type T3. - The number of substrings generated for each input element. - -Notes -===== -Signature: ``ai.onnx@20::StringSplit``. - -Type constraints: - - T1: `tensor(string)` - - T2: `tensor(string)` - - T3: `tensor(int64)` + StringSplit splits a string tensor's elements into substrings based on a + delimiter attribute and a maxsplit attribute. + + The first output of this operator is a tensor of strings representing + the substrings from splitting each input string on the ``delimiter`` + substring. This tensor has one additional rank compared to the input + tensor in order to store the substrings for each input element (where + the input tensor is not empty). Note that, in order to ensure the same + number of elements are present in the final dimension, this tensor will + pad empty strings as illustrated in the examples below. Consecutive + delimiters are not grouped together and are deemed to delimit empty + strings, except if the ``delimiter`` is unspecified or is the empty + string (""). In the case where the ``delimiter`` is unspecified or the + empty string, consecutive whitespace characters are regarded as a single + separator and leading or trailing whitespace is removed in the output. + + The second output tensor represents the number of substrings generated. + ``maxsplit`` can be used to limit the number of splits performed - after + the ``maxsplit``\ th split if the string is not fully split, the + trailing suffix of input string after the final split point is also + added. For elements where fewer splits are possible than specified in + ``maxsplit``, it has no effect. + + Parameters + ========== + X + Type T1. + Tensor of strings to split. + delimiter + Attribute. + Delimiter to split on. If left unset or set to the empty string (""), + the input is split on consecutive whitespace. + maxsplit + Attribute. + Maximum number of splits (from left to right). If left unset (or if the + number of possible splits are less than maxsplit), it will make as many + splits as possible. Note that the maximum possible number of substrings + returned with ``maxsplit`` specified is ``maxsplit+1`` since the + remaining suffix after the ``maxsplit``\ th split is included in the + output. + + Returns + ======= + Y : Var + Type T2. + Tensor of substrings representing the outcome of splitting the strings + in the input on the delimiter. Note that to ensure the same number of + elements are present in the final rank, this tensor will pad any + necessary empty strings. + Z : Var + Type T3. + The number of substrings generated for each input element. + + Notes + ===== + Signature: ``ai.onnx@20::StringSplit``. + + Type constraints: + - T1: `tensor(string)` + - T2: `tensor(string)` + - T3: `tensor(int64)` """ - return _StringSplit( - _StringSplit.Attributes( - delimiter=AttrString.maybe(delimiter, name="delimiter"), - maxsplit=AttrInt64.maybe(maxsplit, name="maxsplit"), - ), _StringSplit.Inputs( - X=unwrap_vars(X), ), ).get_output_vars( - X=get_value(X), )._unpack_to_any() + return ( + _StringSplit( + _StringSplit.Attributes( + delimiter=AttrString.maybe(delimiter, name="delimiter"), + maxsplit=AttrInt64.maybe(maxsplit, name="maxsplit"), + ), + _StringSplit.Inputs( + X=unwrap_vars(X), + ), + ) + .get_output_vars( + X=get_value(X), + ) + ._unpack_to_any() + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -1641,4 +2001,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index b51ae180..52e3027a 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -1,21 +1,18 @@ +# Copyright (c) QuantCo 2023-2024 +# SPDX-License-Identifier: BSD-3-Clause + # ruff: noqa: E741 -- Allow ambiguous variable name -import typing -import warnings -from dataclasses import dataclass from collections.abc import Iterable, Sequence +from dataclasses import dataclass from typing import ( - Any, Callable, Optional, - Union, ) from typing import cast as typing_cast import numpy as np import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, AttrFloat32, @@ -26,187 +23,360 @@ AttrString, AttrStrings, AttrTensor, - AttrType, ) +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._graph import Graph, subgraph -from spox._internal_op import intro from spox._node import OpType -from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._standard import StandardNode +from spox._type_system import Tensor, Type from spox._value_prop import PropValueType +from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox.opset.ai.onnx.v20 import ( + _DFT, + _GRU, + _LRN, + _LSTM, + _RNN, + _STFT, + _Abs, + _Acos, + _Acosh, + _Add, + _AffineGrid, + _And, + _ArgMax, + _ArgMin, + _Asin, + _Asinh, + _Atan, + _Atanh, + _AveragePool, + _BatchNormalization, + _Bernoulli, + _BitShift, + _BitwiseAnd, + _BitwiseNot, + _BitwiseOr, + _BitwiseXor, + _BlackmanWindow, + _Ceil, + _Celu, + _CenterCropPad, + _Clip, + _Col2Im, + _Compress, + _Concat, + _ConcatFromSequence, + _Conv, + _ConvInteger, + _ConvTranspose, + _Cos, + _Cosh, + _CumSum, + _DeformConv, + _DepthToSpace, + _Det, + _Div, + _Dropout, + _DynamicQuantizeLinear, + _Einsum, + _Elu, + _Equal, + _Erf, + _Exp, + _Expand, + _EyeLike, + _Floor, + _Gather, + _GatherElements, + _GatherND, + _Gelu, + _Gemm, + _GlobalAveragePool, + _GlobalLpPool, + _GlobalMaxPool, + _Greater, + _GreaterOrEqual, + _GridSample, + _HammingWindow, + _HannWindow, + _Hardmax, + _HardSigmoid, + _HardSwish, + _ImageDecoder, + _InstanceNormalization, + _IsInf, + _IsNaN, + _LayerNormalization, + _LeakyRelu, + _Less, + _LessOrEqual, + _Log, + _LogSoftmax, + _LpNormalization, + _LpPool, + _MatMul, + _MatMulInteger, + _Max, + _MaxPool, + _MaxRoiPool, + _MaxUnpool, + _Mean, + _MeanVarianceNormalization, + _MelWeightMatrix, + _Min, + _Mish, + _Mod, + _Mul, + _Multinomial, + _Neg, + _NegativeLogLikelihoodLoss, + _NonMaxSuppression, + _NonZero, + _Not, + _OneHot, + _Optional, + _OptionalGetElement, + _OptionalHasElement, + _Or, + _Pow, + _PRelu, + _QLinearConv, + _RandomNormal, + _RandomNormalLike, + _RandomUniform, + _RandomUniformLike, + _Range, + _Reciprocal, + _ReduceL1, + _ReduceL2, + _ReduceLogSum, + _ReduceLogSumExp, + _ReduceMax, + _ReduceMean, + _ReduceMin, + _ReduceProd, + _ReduceSum, + _ReduceSumSquare, + _RegexFullMatch, + _Relu, + _Resize, + _ReverseSequence, + _RoiAlign, + _Round, + _ScatterElements, + _ScatterND, + _Selu, + _SequenceAt, + _SequenceConstruct, + _SequenceEmpty, + _SequenceErase, + _SequenceInsert, + _SequenceLength, + _SequenceMap, + _Shrink, + _Sigmoid, + _Sign, + _Sin, + _Sinh, + _Slice, + _Softmax, + _SoftmaxCrossEntropyLoss, + _Softplus, + _Softsign, + _SpaceToDepth, + _Split, + _SplitToSequence, + _Sqrt, + _StringConcat, + _StringNormalizer, + _StringSplit, + _Sub, + _Sum, + _Tan, + _Tanh, + _TfIdfVectorizer, + _ThresholdedRelu, + _Tile, + _TopK, + _Trilu, + _Unique, + _Where, + _Xor, + abs, + acos, + acosh, + add, + affine_grid, + and_, + arg_max, + arg_min, + asin, + asinh, + atan, + atanh, + average_pool, + batch_normalization, + bernoulli, + bit_shift, + bitwise_and, + bitwise_not, + bitwise_or, + bitwise_xor, + blackman_window, + ceil, + celu, + center_crop_pad, + clip, + col2_im, + compress, + concat, + concat_from_sequence, + conv, + conv_integer, + conv_transpose, + cos, + cosh, + cumsum, + deform_conv, + depth_to_space, + det, + dft, + div, + dropout, + dynamic_quantize_linear, + einsum, + elu, + equal, + erf, + exp, + expand, + eye_like, + floor, + gather, + gather_elements, + gather_nd, + gelu, + gemm, + global_average_pool, + global_lp_pool, + global_max_pool, + greater, + greater_or_equal, + grid_sample, + gru, + hamming_window, + hann_window, + hard_sigmoid, + hard_swish, + hardmax, + image_decoder, + instance_normalization, + isinf, + isnan, + layer_normalization, + leaky_relu, + less, + less_or_equal, + log, + log_softmax, + lp_normalization, + lp_pool, + lrn, + lstm, + matmul, + matmul_integer, + max, + max_pool, + max_roi_pool, + max_unpool, + mean, + mean_variance_normalization, + mel_weight_matrix, + min, + mish, + mod, + mul, + multinomial, + neg, + negative_log_likelihood_loss, + non_max_suppression, + non_zero, + not_, + one_hot, + optional, + optional_get_element, + optional_has_element, + or_, + pow, + prelu, + qlinear_conv, + random_normal, + random_normal_like, + random_uniform, + random_uniform_like, + range, + reciprocal, + reduce_l1, + reduce_l2, + reduce_log_sum, + reduce_log_sum_exp, + reduce_max, + reduce_mean, + reduce_min, + reduce_prod, + reduce_sum, + reduce_sum_square, + regex_full_match, + relu, + resize, + reverse_sequence, + rnn, + roi_align, + round, + scatter_elements, + scatter_nd, + selu, + sequence_at, + sequence_construct, + sequence_empty, + sequence_erase, + sequence_insert, + sequence_length, + sequence_map, + shrink, + sigmoid, + sign, + sin, + sinh, + slice, + softmax, + softmax_cross_entropy_loss, + softplus, + softsign, + space_to_depth, + split, + split_to_sequence, + sqrt, + stft, + string_concat, + string_normalizer, + string_split, + sub, + sum, + tan, + tanh, + tf_idf_vectorizer, + thresholded_relu, + tile, + top_k, + trilu, + unique, + where, + xor, +) -from spox.opset.ai.onnx.v20 import _Abs, abs -from spox.opset.ai.onnx.v20 import _Acos, acos -from spox.opset.ai.onnx.v20 import _Acosh, acosh -from spox.opset.ai.onnx.v20 import _Add, add -from spox.opset.ai.onnx.v20 import _AffineGrid, affine_grid -from spox.opset.ai.onnx.v20 import _And, and_ -from spox.opset.ai.onnx.v20 import _ArgMax, arg_max -from spox.opset.ai.onnx.v20 import _ArgMin, arg_min -from spox.opset.ai.onnx.v20 import _Asin, asin -from spox.opset.ai.onnx.v20 import _Asinh, asinh -from spox.opset.ai.onnx.v20 import _Atan, atan -from spox.opset.ai.onnx.v20 import _Atanh, atanh -from spox.opset.ai.onnx.v20 import _AveragePool, average_pool -from spox.opset.ai.onnx.v20 import _BatchNormalization, batch_normalization -from spox.opset.ai.onnx.v20 import _Bernoulli, bernoulli -from spox.opset.ai.onnx.v20 import _BitShift, bit_shift -from spox.opset.ai.onnx.v20 import _BitwiseAnd, bitwise_and -from spox.opset.ai.onnx.v20 import _BitwiseNot, bitwise_not -from spox.opset.ai.onnx.v20 import _BitwiseOr, bitwise_or -from spox.opset.ai.onnx.v20 import _BitwiseXor, bitwise_xor -from spox.opset.ai.onnx.v20 import _BlackmanWindow, blackman_window -from spox.opset.ai.onnx.v20 import _Ceil, ceil -from spox.opset.ai.onnx.v20 import _Celu, celu -from spox.opset.ai.onnx.v20 import _CenterCropPad, center_crop_pad -from spox.opset.ai.onnx.v20 import _Clip, clip -from spox.opset.ai.onnx.v20 import _Col2Im, col2_im -from spox.opset.ai.onnx.v20 import _Compress, compress -from spox.opset.ai.onnx.v20 import _Concat, concat -from spox.opset.ai.onnx.v20 import _ConcatFromSequence, concat_from_sequence -from spox.opset.ai.onnx.v20 import _Conv, conv -from spox.opset.ai.onnx.v20 import _ConvInteger, conv_integer -from spox.opset.ai.onnx.v20 import _ConvTranspose, conv_transpose -from spox.opset.ai.onnx.v20 import _Cos, cos -from spox.opset.ai.onnx.v20 import _Cosh, cosh -from spox.opset.ai.onnx.v20 import _CumSum, cumsum -from spox.opset.ai.onnx.v20 import _DFT, dft -from spox.opset.ai.onnx.v20 import _DeformConv, deform_conv -from spox.opset.ai.onnx.v20 import _DepthToSpace, depth_to_space -from spox.opset.ai.onnx.v20 import _Det, det -from spox.opset.ai.onnx.v20 import _Div, div -from spox.opset.ai.onnx.v20 import _Dropout, dropout -from spox.opset.ai.onnx.v20 import _DynamicQuantizeLinear, dynamic_quantize_linear -from spox.opset.ai.onnx.v20 import _Einsum, einsum -from spox.opset.ai.onnx.v20 import _Elu, elu -from spox.opset.ai.onnx.v20 import _Equal, equal -from spox.opset.ai.onnx.v20 import _Erf, erf -from spox.opset.ai.onnx.v20 import _Exp, exp -from spox.opset.ai.onnx.v20 import _Expand, expand -from spox.opset.ai.onnx.v20 import _EyeLike, eye_like -from spox.opset.ai.onnx.v20 import _Floor, floor -from spox.opset.ai.onnx.v20 import _GRU, gru -from spox.opset.ai.onnx.v20 import _Gather, gather -from spox.opset.ai.onnx.v20 import _GatherElements, gather_elements -from spox.opset.ai.onnx.v20 import _GatherND, gather_nd -from spox.opset.ai.onnx.v20 import _Gelu, gelu -from spox.opset.ai.onnx.v20 import _Gemm, gemm -from spox.opset.ai.onnx.v20 import _GlobalAveragePool, global_average_pool -from spox.opset.ai.onnx.v20 import _GlobalLpPool, global_lp_pool -from spox.opset.ai.onnx.v20 import _GlobalMaxPool, global_max_pool -from spox.opset.ai.onnx.v20 import _Greater, greater -from spox.opset.ai.onnx.v20 import _GreaterOrEqual, greater_or_equal -from spox.opset.ai.onnx.v20 import _GridSample, grid_sample -from spox.opset.ai.onnx.v20 import _HammingWindow, hamming_window -from spox.opset.ai.onnx.v20 import _HannWindow, hann_window -from spox.opset.ai.onnx.v20 import _HardSigmoid, hard_sigmoid -from spox.opset.ai.onnx.v20 import _HardSwish, hard_swish -from spox.opset.ai.onnx.v20 import _Hardmax, hardmax -from spox.opset.ai.onnx.v20 import _ImageDecoder, image_decoder -from spox.opset.ai.onnx.v20 import _InstanceNormalization, instance_normalization -from spox.opset.ai.onnx.v20 import _IsInf, isinf -from spox.opset.ai.onnx.v20 import _IsNaN, isnan -from spox.opset.ai.onnx.v20 import _LRN, lrn -from spox.opset.ai.onnx.v20 import _LSTM, lstm -from spox.opset.ai.onnx.v20 import _LayerNormalization, layer_normalization -from spox.opset.ai.onnx.v20 import _LeakyRelu, leaky_relu -from spox.opset.ai.onnx.v20 import _Less, less -from spox.opset.ai.onnx.v20 import _LessOrEqual, less_or_equal -from spox.opset.ai.onnx.v20 import _Log, log -from spox.opset.ai.onnx.v20 import _LogSoftmax, log_softmax -from spox.opset.ai.onnx.v20 import _LpNormalization, lp_normalization -from spox.opset.ai.onnx.v20 import _LpPool, lp_pool -from spox.opset.ai.onnx.v20 import _MatMul, matmul -from spox.opset.ai.onnx.v20 import _MatMulInteger, matmul_integer -from spox.opset.ai.onnx.v20 import _Max, max -from spox.opset.ai.onnx.v20 import _MaxPool, max_pool -from spox.opset.ai.onnx.v20 import _MaxRoiPool, max_roi_pool -from spox.opset.ai.onnx.v20 import _MaxUnpool, max_unpool -from spox.opset.ai.onnx.v20 import _Mean, mean -from spox.opset.ai.onnx.v20 import _MeanVarianceNormalization, mean_variance_normalization -from spox.opset.ai.onnx.v20 import _MelWeightMatrix, mel_weight_matrix -from spox.opset.ai.onnx.v20 import _Min, min -from spox.opset.ai.onnx.v20 import _Mish, mish -from spox.opset.ai.onnx.v20 import _Mod, mod -from spox.opset.ai.onnx.v20 import _Mul, mul -from spox.opset.ai.onnx.v20 import _Multinomial, multinomial -from spox.opset.ai.onnx.v20 import _Neg, neg -from spox.opset.ai.onnx.v20 import _NegativeLogLikelihoodLoss, negative_log_likelihood_loss -from spox.opset.ai.onnx.v20 import _NonMaxSuppression, non_max_suppression -from spox.opset.ai.onnx.v20 import _NonZero, non_zero -from spox.opset.ai.onnx.v20 import _Not, not_ -from spox.opset.ai.onnx.v20 import _OneHot, one_hot -from spox.opset.ai.onnx.v20 import _Optional, optional -from spox.opset.ai.onnx.v20 import _OptionalGetElement, optional_get_element -from spox.opset.ai.onnx.v20 import _OptionalHasElement, optional_has_element -from spox.opset.ai.onnx.v20 import _Or, or_ -from spox.opset.ai.onnx.v20 import _PRelu, prelu -from spox.opset.ai.onnx.v20 import _Pow, pow -from spox.opset.ai.onnx.v20 import _QLinearConv, qlinear_conv -from spox.opset.ai.onnx.v20 import _RNN, rnn -from spox.opset.ai.onnx.v20 import _RandomNormal, random_normal -from spox.opset.ai.onnx.v20 import _RandomNormalLike, random_normal_like -from spox.opset.ai.onnx.v20 import _RandomUniform, random_uniform -from spox.opset.ai.onnx.v20 import _RandomUniformLike, random_uniform_like -from spox.opset.ai.onnx.v20 import _Range, range -from spox.opset.ai.onnx.v20 import _Reciprocal, reciprocal -from spox.opset.ai.onnx.v20 import _ReduceL1, reduce_l1 -from spox.opset.ai.onnx.v20 import _ReduceL2, reduce_l2 -from spox.opset.ai.onnx.v20 import _ReduceLogSum, reduce_log_sum -from spox.opset.ai.onnx.v20 import _ReduceLogSumExp, reduce_log_sum_exp -from spox.opset.ai.onnx.v20 import _ReduceMax, reduce_max -from spox.opset.ai.onnx.v20 import _ReduceMean, reduce_mean -from spox.opset.ai.onnx.v20 import _ReduceMin, reduce_min -from spox.opset.ai.onnx.v20 import _ReduceProd, reduce_prod -from spox.opset.ai.onnx.v20 import _ReduceSum, reduce_sum -from spox.opset.ai.onnx.v20 import _ReduceSumSquare, reduce_sum_square -from spox.opset.ai.onnx.v20 import _RegexFullMatch, regex_full_match -from spox.opset.ai.onnx.v20 import _Relu, relu -from spox.opset.ai.onnx.v20 import _Resize, resize -from spox.opset.ai.onnx.v20 import _ReverseSequence, reverse_sequence -from spox.opset.ai.onnx.v20 import _RoiAlign, roi_align -from spox.opset.ai.onnx.v20 import _Round, round -from spox.opset.ai.onnx.v20 import _STFT, stft -from spox.opset.ai.onnx.v20 import _ScatterElements, scatter_elements -from spox.opset.ai.onnx.v20 import _ScatterND, scatter_nd -from spox.opset.ai.onnx.v20 import _Selu, selu -from spox.opset.ai.onnx.v20 import _SequenceAt, sequence_at -from spox.opset.ai.onnx.v20 import _SequenceConstruct, sequence_construct -from spox.opset.ai.onnx.v20 import _SequenceEmpty, sequence_empty -from spox.opset.ai.onnx.v20 import _SequenceErase, sequence_erase -from spox.opset.ai.onnx.v20 import _SequenceInsert, sequence_insert -from spox.opset.ai.onnx.v20 import _SequenceLength, sequence_length -from spox.opset.ai.onnx.v20 import _SequenceMap, sequence_map -from spox.opset.ai.onnx.v20 import _Shrink, shrink -from spox.opset.ai.onnx.v20 import _Sigmoid, sigmoid -from spox.opset.ai.onnx.v20 import _Sign, sign -from spox.opset.ai.onnx.v20 import _Sin, sin -from spox.opset.ai.onnx.v20 import _Sinh, sinh -from spox.opset.ai.onnx.v20 import _Slice, slice -from spox.opset.ai.onnx.v20 import _Softmax, softmax -from spox.opset.ai.onnx.v20 import _SoftmaxCrossEntropyLoss, softmax_cross_entropy_loss -from spox.opset.ai.onnx.v20 import _Softplus, softplus -from spox.opset.ai.onnx.v20 import _Softsign, softsign -from spox.opset.ai.onnx.v20 import _SpaceToDepth, space_to_depth -from spox.opset.ai.onnx.v20 import _Split, split -from spox.opset.ai.onnx.v20 import _SplitToSequence, split_to_sequence -from spox.opset.ai.onnx.v20 import _Sqrt, sqrt -from spox.opset.ai.onnx.v20 import _StringConcat, string_concat -from spox.opset.ai.onnx.v20 import _StringNormalizer, string_normalizer -from spox.opset.ai.onnx.v20 import _StringSplit, string_split -from spox.opset.ai.onnx.v20 import _Sub, sub -from spox.opset.ai.onnx.v20 import _Sum, sum -from spox.opset.ai.onnx.v20 import _Tan, tan -from spox.opset.ai.onnx.v20 import _Tanh, tanh -from spox.opset.ai.onnx.v20 import _TfIdfVectorizer, tf_idf_vectorizer -from spox.opset.ai.onnx.v20 import _ThresholdedRelu, thresholded_relu -from spox.opset.ai.onnx.v20 import _Tile, tile -from spox.opset.ai.onnx.v20 import _TopK, top_k -from spox.opset.ai.onnx.v20 import _Trilu, trilu -from spox.opset.ai.onnx.v20 import _Unique, unique -from spox.opset.ai.onnx.v20 import _Where, where -from spox.opset.ai.onnx.v20 import _Xor, xor class _Cast(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -227,6 +397,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _CastLike(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -247,6 +418,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Constant(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -265,7 +437,9 @@ class Outputs(BaseOutputs): output: VarInfo def propagate_values(self, initializers) -> dict[str, PropValueType]: - ((key, raw),) = ((k, v.value) for k, v in self.attrs.get_fields().items() if v is not None) + ((key, raw),) = ( + (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None + ) if key == "value": value = raw elif key == "value_float": @@ -283,14 +457,18 @@ def propagate_values(self, initializers) -> dict[str, PropValueType]: elif key == "sparse_value": return {} else: - raise RuntimeError(f"Could not extract the set Constant value attribute, got: {key}") + raise RuntimeError( + f"Could not extract the set Constant value attribute, got: {key}" + ) return {"output": value} + op_type = OpType("Constant", "", 21) attrs: Attributes inputs: BaseInputs outputs: Outputs + class _ConstantOfShape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -310,6 +488,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _DequantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -332,6 +511,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Flatten(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -351,6 +531,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _GroupNormalization(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -374,6 +555,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Identity(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -393,6 +575,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _If(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -413,6 +596,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Loop(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -434,6 +618,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Pad(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -456,6 +641,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _QLinearMatMul(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -482,6 +668,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _QuantizeLinear(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -506,6 +693,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Reshape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -526,6 +714,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Scan(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -550,6 +739,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Shape(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -570,6 +760,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Size(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -589,6 +780,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Squeeze(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -609,6 +801,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Transpose(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -628,6 +821,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs + class _Unsqueeze(StandardNode): @dataclass class Attributes(BaseAttributes): @@ -648,1592 +842,1917 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs -def cast(input: Var, *, saturate: int = 1, to: npt.DTypeLike, ) -> Var: + +def cast( + input: Var, + *, + saturate: int = 1, + to: npt.DTypeLike, +) -> Var: r""" -The operator casts the elements of a given input tensor to a data type -specified by the 'to' argument and returns an output tensor of the same -size in the converted type. The 'to' argument must be one of the data -types specified in the 'DataType' enum field in the TensorProto message. - -Casting from string tensor in plain (e.g., "3.14" and "1000") and -scientific numeric representations (e.g., "1e-5" and "1E8") to float -types is supported. For example, converting string "100.5" to an integer -may yield result 100. There are some string literals reserved for -special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are -positive infinity, negative infinity, and not-a-number, respectively. -Any string which can exactly match "+INF" in a case-insensitive way -would be mapped to positive infinite. Similarly, this case-insensitive -rule is applied to "INF" and "NaN". When casting from numeric tensors to -string tensors, plain floating-point representation (such as -"314.15926") would be used. Converting non-numerical-literal string such -as "Hello World!" is an undefined behavior. Cases of converting string -representing floating-point arithmetic value, such as "2.718", to INT is -an undefined behavior. - -Conversion from a numerical type to any numerical type is always -allowed. User must be aware of precision loss and value change caused by -range difference between two types. For example, a 64-bit float -3.1415926459 may be round to a 32-bit float 3.141592. Similarly, -converting an integer 36 to Boolean may produce 1 because we truncate -bits which can't be stored in the targeted type. - -In more detail, the conversion among numerical types should follow these -rules if the destination type is not a float 8 type. - -- Casting from floating point to: - - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. - -- Casting from fixed point to: - - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. - -- Casting from bool to: - - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. - -Float 8 type were introduced to speed up the training of deep models. By -default the conversion of a float *x* obeys to the following rules. -``[x]`` means the value rounded to the target mantissa width. - -============== =========== ======== ======== ======== -x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ -============== =========== ======== ======== ======== -0 0 0 0 0 --0 -0 0 -0 0 -NaN NaN NaN NaN NaN -+/- Inf +/- FLT_MAX NaN FLT_MAX NaN -[x] > FLT_MAX FLT_MAX FLT_MAX FLT_MAX FLT_MAX -[x] < -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -else RNE RNE RNE RNE -============== =========== ======== ======== ======== - -The behavior changes if the parameter 'saturate' is set to False. The -rules then become: - -============== ====== ======== ======= ======== -x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ -============== ====== ======== ======= ======== -0 0 0 0 0 --0 -0 0 -0 0 -NaN NaN NaN NaN NaN -+/- Inf NaN NaN +/- Inf NaN -[x] > FLT_MAX NaN NaN Inf NaN -[x] < -FLT_MAX NaN NaN -Inf NaN -else RNE RNE RNE RNE -============== ====== ======== ======= ======== - -Parameters -========== -input - Type T1. - Input tensor to be cast. -saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. All cases are fully described in two tables - inserted in the operator description. -to - Attribute. - The data type to which the elements of the input tensor are cast. - Strictly must be one of the types from DataType enum in TensorProto - -Returns -======= -output : Var - Type T2. - Output tensor with the same shape as input with type specified by the - 'to' argument - -Notes -===== -Signature: ``ai.onnx@21::Cast``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + The operator casts the elements of a given input tensor to a data type + specified by the 'to' argument and returns an output tensor of the same + size in the converted type. The 'to' argument must be one of the data + types specified in the 'DataType' enum field in the TensorProto message. + + Casting from string tensor in plain (e.g., "3.14" and "1000") and + scientific numeric representations (e.g., "1e-5" and "1E8") to float + types is supported. For example, converting string "100.5" to an integer + may yield result 100. There are some string literals reserved for + special floating-point values; "+INF" (and "INF"), "-INF", and "NaN" are + positive infinity, negative infinity, and not-a-number, respectively. + Any string which can exactly match "+INF" in a case-insensitive way + would be mapped to positive infinite. Similarly, this case-insensitive + rule is applied to "INF" and "NaN". When casting from numeric tensors to + string tensors, plain floating-point representation (such as + "314.15926") would be used. Converting non-numerical-literal string such + as "Hello World!" is an undefined behavior. Cases of converting string + representing floating-point arithmetic value, such as "2.718", to INT is + an undefined behavior. + + Conversion from a numerical type to any numerical type is always + allowed. User must be aware of precision loss and value change caused by + range difference between two types. For example, a 64-bit float + 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, + converting an integer 36 to Boolean may produce 1 because we truncate + bits which can't be stored in the targeted type. + + In more detail, the conversion among numerical types should follow these + rules if the destination type is not a float 8 type. + + - Casting from floating point to: + + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. + + - Casting from fixed point to: + + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. + + - Casting from bool to: + + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. + + Float 8 type were introduced to speed up the training of deep models. By + default the conversion of a float *x* obeys to the following rules. + ``[x]`` means the value rounded to the target mantissa width. + + ============== =========== ======== ======== ======== + x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ + ============== =========== ======== ======== ======== + 0 0 0 0 0 + -0 -0 0 -0 0 + NaN NaN NaN NaN NaN + +/- Inf +/- FLT_MAX NaN FLT_MAX NaN + [x] > FLT_MAX FLT_MAX FLT_MAX FLT_MAX FLT_MAX + [x] < -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX -FLT_MAX + else RNE RNE RNE RNE + ============== =========== ======== ======== ======== + + The behavior changes if the parameter 'saturate' is set to False. The + rules then become: + + ============== ====== ======== ======= ======== + x E4M3FN E4M3FNUZ E5M2 E5M2FNUZ + ============== ====== ======== ======= ======== + 0 0 0 0 0 + -0 -0 0 -0 0 + NaN NaN NaN NaN NaN + +/- Inf NaN NaN +/- Inf NaN + [x] > FLT_MAX NaN NaN Inf NaN + [x] < -FLT_MAX NaN NaN -Inf NaN + else RNE RNE RNE RNE + ============== ====== ======== ======= ======== + + Parameters + ========== + input + Type T1. + Input tensor to be cast. + saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. All cases are fully described in two tables + inserted in the operator description. + to + Attribute. + The data type to which the elements of the input tensor are cast. + Strictly must be one of the types from DataType enum in TensorProto + + Returns + ======= + output : Var + Type T2. + Output tensor with the same shape as input with type specified by the + 'to' argument + + Notes + ===== + Signature: ``ai.onnx@21::Cast``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Cast( - _Cast.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - to=AttrDtype(to, name="to"), - ), _Cast.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Cast( + _Cast.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + to=AttrDtype(to, name="to"), + ), + _Cast.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def cast_like(input: Var, target_type: Var, *, saturate: int = 1, ) -> Var: +def cast_like( + input: Var, + target_type: Var, + *, + saturate: int = 1, +) -> Var: r""" -The operator casts the elements of a given input tensor (the first -input) to the same data type as the elements of the second input tensor. -See documentation of the Cast operator for further details. - -Parameters -========== -input - Type T1. - Input tensor to be cast. -target_type - Type T2. - The (first) input tensor will be cast to produce a tensor of the same - type as this (second input) tensor. -saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. Please refer to operator Cast description for - further details. - -Returns -======= -output : Var - Type T2. - Output tensor produced by casting the first input tensor to have the - same type as the second input tensor. - -Notes -===== -Signature: ``ai.onnx@21::CastLike``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + The operator casts the elements of a given input tensor (the first + input) to the same data type as the elements of the second input tensor. + See documentation of the Cast operator for further details. + + Parameters + ========== + input + Type T1. + Input tensor to be cast. + target_type + Type T2. + The (first) input tensor will be cast to produce a tensor of the same + type as this (second input) tensor. + saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + conversion (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. Please refer to operator Cast description for + further details. + + Returns + ======= + output : Var + Type T2. + Output tensor produced by casting the first input tensor to have the + same type as the second input tensor. + + Notes + ===== + Signature: ``ai.onnx@21::CastLike``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _CastLike( - _CastLike.Attributes( - saturate=AttrInt64(saturate, name="saturate"), - ), _CastLike.Inputs( - input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), ).get_output_vars( - input=get_value(input), target_type=get_value(target_type), ).output + return ( + _CastLike( + _CastLike.Attributes( + saturate=AttrInt64(saturate, name="saturate"), + ), + _CastLike.Inputs( + input=unwrap_vars(input), + target_type=unwrap_vars(target_type), + ), + ) + .get_output_vars( + input=get_value(input), + target_type=get_value(target_type), + ) + .output + ) -def constant(*, value: Optional[np.ndarray] = None, value_float: Optional[float] = None, value_floats: Optional[Iterable[float]] = None, value_int: Optional[int] = None, value_ints: Optional[Iterable[int]] = None, value_string: Optional[str] = None, value_strings: Optional[Iterable[str]] = None, ) -> Var: +def constant( + *, + value: Optional[np.ndarray] = None, + value_float: Optional[float] = None, + value_floats: Optional[Iterable[float]] = None, + value_int: Optional[int] = None, + value_ints: Optional[Iterable[int]] = None, + value_string: Optional[str] = None, + value_strings: Optional[Iterable[str]] = None, +) -> Var: r""" -This operator produces a constant tensor. Exactly one of the provided -attributes, either value, sparse_value, or value\_\* must be specified. - -Parameters -========== -sparse_value - Attribute. - The value for the elements of the output tensor in sparse format. -value - Attribute. - The value for the elements of the output tensor. -value_float - Attribute. - The value for the sole element for the scalar, float32, output tensor. -value_floats - Attribute. - The values for the elements for the 1D, float32, output tensor. -value_int - Attribute. - The value for the sole element for the scalar, int64, output tensor. -value_ints - Attribute. - The values for the elements for the 1D, int64, output tensor. -value_string - Attribute. - The value for the sole element for the scalar, UTF-8 string, output - tensor. -value_strings - Attribute. - The values for the elements for the 1D, UTF-8 string, output tensor. - -Returns -======= -output : Var - Type T. - Output tensor containing the same value of the provided tensor. - -Notes -===== -Signature: ``ai.onnx@21::Constant``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + This operator produces a constant tensor. Exactly one of the provided + attributes, either value, sparse_value, or value\_\* must be specified. + + Parameters + ========== + sparse_value + Attribute. + The value for the elements of the output tensor in sparse format. + value + Attribute. + The value for the elements of the output tensor. + value_float + Attribute. + The value for the sole element for the scalar, float32, output tensor. + value_floats + Attribute. + The values for the elements for the 1D, float32, output tensor. + value_int + Attribute. + The value for the sole element for the scalar, int64, output tensor. + value_ints + Attribute. + The values for the elements for the 1D, int64, output tensor. + value_string + Attribute. + The value for the sole element for the scalar, UTF-8 string, output + tensor. + value_strings + Attribute. + The values for the elements for the 1D, UTF-8 string, output tensor. + + Returns + ======= + output : Var + Type T. + Output tensor containing the same value of the provided tensor. + + Notes + ===== + Signature: ``ai.onnx@21::Constant``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Constant( - _Constant.Attributes( - value=AttrTensor.maybe(value, name="value"), - value_float=AttrFloat32.maybe(value_float, name="value_float"), - value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), - value_int=AttrInt64.maybe(value_int, name="value_int"), - value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), - value_string=AttrString.maybe(value_string, name="value_string"), - value_strings=AttrStrings.maybe(value_strings, name="value_strings"), - ), _Constant.Inputs( - ), ).get_output_vars( - ).output - - -def constant_of_shape(input: Var, *, value: Optional[np.ndarray] = None, ) -> Var: + return ( + _Constant( + _Constant.Attributes( + value=AttrTensor.maybe(value, name="value"), + value_float=AttrFloat32.maybe(value_float, name="value_float"), + value_floats=AttrFloat32s.maybe(value_floats, name="value_floats"), + value_int=AttrInt64.maybe(value_int, name="value_int"), + value_ints=AttrInt64s.maybe(value_ints, name="value_ints"), + value_string=AttrString.maybe(value_string, name="value_string"), + value_strings=AttrStrings.maybe(value_strings, name="value_strings"), + ), + _Constant.Inputs(), + ) + .get_output_vars() + .output + ) + + +def constant_of_shape( + input: Var, + *, + value: Optional[np.ndarray] = None, +) -> Var: r""" -Generate a tensor with given value and shape. - -Parameters -========== -input - Type T1. - 1D tensor. The shape of the expected output tensor. If empty tensor is - given, the output would be a scalar. All values must be >= 0. -value - Attribute. - (Optional) The value of the output elements.Should be a one-element - tensor. If not specified, it defaults to a tensor of value 0 and - datatype float32 - -Returns -======= -output : Var - Type T2. - Output tensor of shape specified by 'input'.If attribute 'value' is - specified, the value and datatype of the output tensor is taken from - 'value'.If attribute 'value' is not specified, the value in the output - defaults to 0, and the datatype defaults to float32. - -Notes -===== -Signature: ``ai.onnx@21::ConstantOfShape``. - -Type constraints: - - T1: `tensor(int64)` - - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Generate a tensor with given value and shape. + + Parameters + ========== + input + Type T1. + 1D tensor. The shape of the expected output tensor. If empty tensor is + given, the output would be a scalar. All values must be >= 0. + value + Attribute. + (Optional) The value of the output elements.Should be a one-element + tensor. If not specified, it defaults to a tensor of value 0 and + datatype float32 + + Returns + ======= + output : Var + Type T2. + Output tensor of shape specified by 'input'.If attribute 'value' is + specified, the value and datatype of the output tensor is taken from + 'value'.If attribute 'value' is not specified, the value in the output + defaults to 0, and the datatype defaults to float32. + + Notes + ===== + Signature: ``ai.onnx@21::ConstantOfShape``. + + Type constraints: + - T1: `tensor(int64)` + - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _ConstantOfShape( - _ConstantOfShape.Attributes( - value=AttrTensor.maybe(value, name="value"), - ), _ConstantOfShape.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _ConstantOfShape( + _ConstantOfShape.Attributes( + value=AttrTensor.maybe(value, name="value"), + ), + _ConstantOfShape.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def dequantize_linear(x: Var, x_scale: Var, x_zero_point: Optional[Var] = None, *, axis: int = 1, block_size: int = 0, ) -> Var: +def dequantize_linear( + x: Var, + x_scale: Var, + x_zero_point: Optional[Var] = None, + *, + axis: int = 1, + block_size: int = 0, +) -> Var: r""" -The linear dequantization operator. It consumes a quantized tensor, a -scale, and a zero point to compute the full-precision tensor. The -dequantization formula is ``y = (x - x_zero_point) * x_scale``. -``x_scale`` and ``x_zero_point`` must have the same shape, determining -the quantization's granularity: a scalar for per-tensor/per-layer -quantization, a 1-D tensor for per-axis quantization, or have a rank -identical to the input for blocked quantization. See QuantizeLinear for -details on quantization granularity. - -``x_zero_point`` and ``x`` must have the same type. ``x`` and ``y`` must -have the same shape. In the case of dequantizing ``int32``, there's no -zero point (zero point is supposed to be 0). ``zero-point`` is usually -not used in the case of float8 types quantization, but the -dequantization formula remains the same for consistency, and ``x_scale`` -still determines the output type. - -Parameters -========== -x - Type T1. - N-D quantized input tensor to be de-quantized. -x_scale - Type T2. - Scale for input ``x``. For per-tensor/layer dequantization the scale is - a scalar, for per per-axis dequantization it is a 1-D Tensor and for - blocked dequantization it has the same shape as the input, except for - one dimension in which blocking is performed. -x_zero_point - Type T1. - Zero point for input ``x``. Shape must match x_scale. It's optional. - Zero point is 0 when it's not specified. -axis - Attribute. - (Optional) The axis of the dequantizing dimension of the input tensor. - Used for per-axis and blocked quantization. Negative value means - counting dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. -block_size - Attribute. - (Optional) The size of the quantization block (number of times every - scale is replicated). Used only for blocked quantization. The block size - is a positive integer. Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, - ``y_scale`` shape ``(S0, ... Si, ...Sn)`` and ``axis=i``, the accepted - range is ``[ceil(Di/Si), ceil(Di/(Si-1))-1]`` - -Returns -======= -y : Var - Type T2. - N-D full precision output tensor. It has same shape as input ``x``. - -Notes -===== -Signature: ``ai.onnx@21::DequantizeLinear``. - -Type constraints: - - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` - - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` + The linear dequantization operator. It consumes a quantized tensor, a + scale, and a zero point to compute the full-precision tensor. The + dequantization formula is ``y = (x - x_zero_point) * x_scale``. + ``x_scale`` and ``x_zero_point`` must have the same shape, determining + the quantization's granularity: a scalar for per-tensor/per-layer + quantization, a 1-D tensor for per-axis quantization, or have a rank + identical to the input for blocked quantization. See QuantizeLinear for + details on quantization granularity. + + ``x_zero_point`` and ``x`` must have the same type. ``x`` and ``y`` must + have the same shape. In the case of dequantizing ``int32``, there's no + zero point (zero point is supposed to be 0). ``zero-point`` is usually + not used in the case of float8 types quantization, but the + dequantization formula remains the same for consistency, and ``x_scale`` + still determines the output type. + + Parameters + ========== + x + Type T1. + N-D quantized input tensor to be de-quantized. + x_scale + Type T2. + Scale for input ``x``. For per-tensor/layer dequantization the scale is + a scalar, for per per-axis dequantization it is a 1-D Tensor and for + blocked dequantization it has the same shape as the input, except for + one dimension in which blocking is performed. + x_zero_point + Type T1. + Zero point for input ``x``. Shape must match x_scale. It's optional. + Zero point is 0 when it's not specified. + axis + Attribute. + (Optional) The axis of the dequantizing dimension of the input tensor. + Used for per-axis and blocked quantization. Negative value means + counting dimensions from the back. Accepted range is ``[-r, r-1]`` where + ``r = rank(input)``. + block_size + Attribute. + (Optional) The size of the quantization block (number of times every + scale is replicated). Used only for blocked quantization. The block size + is a positive integer. Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, + ``y_scale`` shape ``(S0, ... Si, ...Sn)`` and ``axis=i``, the accepted + range is ``[ceil(Di/Si), ceil(Di/(Si-1))-1]`` + + Returns + ======= + y : Var + Type T2. + N-D full precision output tensor. It has same shape as input ``x``. + + Notes + ===== + Signature: ``ai.onnx@21::DequantizeLinear``. + + Type constraints: + - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` + - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - return _DequantizeLinear( - _DequantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - block_size=AttrInt64(block_size, name="block_size"), - ), _DequantizeLinear.Inputs( - x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), ).get_output_vars( - x=get_value(x), x_scale=get_value(x_scale), x_zero_point=get_value(x_zero_point), ).y + return ( + _DequantizeLinear( + _DequantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + block_size=AttrInt64(block_size, name="block_size"), + ), + _DequantizeLinear.Inputs( + x=unwrap_vars(x), + x_scale=unwrap_vars(x_scale), + x_zero_point=unwrap_vars(x_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + x_scale=get_value(x_scale), + x_zero_point=get_value(x_zero_point), + ) + .y + ) -def flatten(input: Var, *, axis: int = 1, ) -> Var: +def flatten( + input: Var, + *, + axis: int = 1, +) -> Var: r""" -Flattens the input tensor into a 2D matrix. If input tensor has shape -(d_0, d_1, ... d_n) then the output will have shape (d_0 X d_1 ... -d\_(axis-1), d_axis X d\_(axis+1) ... X dn). - -Parameters -========== -input - Type T. - A tensor of rank >= axis. -axis - Attribute. - Indicate up to which input dimensions (exclusive) should be flattened to - the outer dimension of the output. The value for axis must be in the - range [-r, r], where r is the rank of the input tensor. Negative value - means counting dimensions from the back. When axis = 0, the shape of the - output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input - tensor is (d_0, d_1, ... d_n). - -Returns -======= -output : Var - Type T. - A 2D tensor with the contents of the input tensor, with input dimensions - up to axis flattened to the outer dimension of the output and remaining - input dimensions flattened into the inner dimension of the output. - -Notes -===== -Signature: ``ai.onnx@21::Flatten``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Flattens the input tensor into a 2D matrix. If input tensor has shape + (d_0, d_1, ... d_n) then the output will have shape (d_0 X d_1 ... + d\_(axis-1), d_axis X d\_(axis+1) ... X dn). + + Parameters + ========== + input + Type T. + A tensor of rank >= axis. + axis + Attribute. + Indicate up to which input dimensions (exclusive) should be flattened to + the outer dimension of the output. The value for axis must be in the + range [-r, r], where r is the rank of the input tensor. Negative value + means counting dimensions from the back. When axis = 0, the shape of the + output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input + tensor is (d_0, d_1, ... d_n). + + Returns + ======= + output : Var + Type T. + A 2D tensor with the contents of the input tensor, with input dimensions + up to axis flattened to the outer dimension of the output and remaining + input dimensions flattened into the inner dimension of the output. + + Notes + ===== + Signature: ``ai.onnx@21::Flatten``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Flatten( - _Flatten.Attributes( - axis=AttrInt64(axis, name="axis"), - ), _Flatten.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Flatten( + _Flatten.Attributes( + axis=AttrInt64(axis, name="axis"), + ), + _Flatten.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def group_normalization(X: Var, scale: Var, bias: Var, *, epsilon: float = 9.999999747378752e-06, num_groups: int, stash_type: int = 1, ) -> Var: +def group_normalization( + X: Var, + scale: Var, + bias: Var, + *, + epsilon: float = 9.999999747378752e-06, + num_groups: int, + stash_type: int = 1, +) -> Var: r""" -A GroupNormalization function. Carries out group normalization as -described in the paper https://arxiv.org/abs/1803.08494 - -This operator transforms input according to - -:: - - y = scale * (x - mean) / sqrt(variance + epsilon) + bias, - -where the mean and variance are computed per instance per group of -channels, and ``scale`` and ``bias`` should be specified for each group -of channels. The number of groups ``num_groups`` should be divisible by -the number of channels so that there are an equal number of channels per -group. - -The overall computation has two stages: the first stage normalizes the -elements to have zero mean and unit variance for each instance in each -group, and the second stage scales and shifts the results of the first -stage. The floating-point precision used in the first stage is -determined by the ``stash_type`` attribute. For example, if -``stash_type`` is 1, the operator casts all input variables to 32-bit -float, performs the computation, and finally casts the normalized -results back to the original type of ``X``. The second stage does not -depend on ``stash_type``. - -When the number of groups is the same as the number of channels, this -operator is equivalent to InstanceNormalization. When there is only one -group, this operator is equivalent to LayerNormalization. - -Parameters -========== -X - Type T. - Input data tensor. Dimensions for image cases are ``(N x C x H x W)``, - where ``N`` is the batch size, ``C`` is the number of channels, and - ``H`` and ``W`` are the height and width of the data. Statistics are - computed for every group of channels over ``C``, ``H``, and ``W``. For - non-image cases, the dimensions are in the form of - ``(N x C x D1 x D2 ... Dn)``. -scale - Type T. - Scale tensor of shape ``(C)``. -bias - Type T. - Bias tensor of shape ``(C)``. -epsilon - Attribute. - The epsilon value to use to avoid division by zero. -num_groups - Attribute. - The number of groups of channels. It should be a divisor of the number - of channels ``C``. -stash_type - Attribute. - The floating-point precision used in stage one of the computation. - -Returns -======= -Y : Var - Type T. - The output tensor of the same shape as ``X``. - -Notes -===== -Signature: ``ai.onnx@21::GroupNormalization``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + A GroupNormalization function. Carries out group normalization as + described in the paper https://arxiv.org/abs/1803.08494 + + This operator transforms input according to + + :: + + y = scale * (x - mean) / sqrt(variance + epsilon) + bias, + + where the mean and variance are computed per instance per group of + channels, and ``scale`` and ``bias`` should be specified for each group + of channels. The number of groups ``num_groups`` should be divisible by + the number of channels so that there are an equal number of channels per + group. + + The overall computation has two stages: the first stage normalizes the + elements to have zero mean and unit variance for each instance in each + group, and the second stage scales and shifts the results of the first + stage. The floating-point precision used in the first stage is + determined by the ``stash_type`` attribute. For example, if + ``stash_type`` is 1, the operator casts all input variables to 32-bit + float, performs the computation, and finally casts the normalized + results back to the original type of ``X``. The second stage does not + depend on ``stash_type``. + + When the number of groups is the same as the number of channels, this + operator is equivalent to InstanceNormalization. When there is only one + group, this operator is equivalent to LayerNormalization. + + Parameters + ========== + X + Type T. + Input data tensor. Dimensions for image cases are ``(N x C x H x W)``, + where ``N`` is the batch size, ``C`` is the number of channels, and + ``H`` and ``W`` are the height and width of the data. Statistics are + computed for every group of channels over ``C``, ``H``, and ``W``. For + non-image cases, the dimensions are in the form of + ``(N x C x D1 x D2 ... Dn)``. + scale + Type T. + Scale tensor of shape ``(C)``. + bias + Type T. + Bias tensor of shape ``(C)``. + epsilon + Attribute. + The epsilon value to use to avoid division by zero. + num_groups + Attribute. + The number of groups of channels. It should be a divisor of the number + of channels ``C``. + stash_type + Attribute. + The floating-point precision used in stage one of the computation. + + Returns + ======= + Y : Var + Type T. + The output tensor of the same shape as ``X``. + + Notes + ===== + Signature: ``ai.onnx@21::GroupNormalization``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - return _GroupNormalization( - _GroupNormalization.Attributes( - epsilon=AttrFloat32(epsilon, name="epsilon"), - num_groups=AttrInt64(num_groups, name="num_groups"), - stash_type=AttrInt64(stash_type, name="stash_type"), - ), _GroupNormalization.Inputs( - X=unwrap_vars(X), scale=unwrap_vars(scale), bias=unwrap_vars(bias), ), ).get_output_vars( - X=get_value(X), scale=get_value(scale), bias=get_value(bias), ).Y + return ( + _GroupNormalization( + _GroupNormalization.Attributes( + epsilon=AttrFloat32(epsilon, name="epsilon"), + num_groups=AttrInt64(num_groups, name="num_groups"), + stash_type=AttrInt64(stash_type, name="stash_type"), + ), + _GroupNormalization.Inputs( + X=unwrap_vars(X), + scale=unwrap_vars(scale), + bias=unwrap_vars(bias), + ), + ) + .get_output_vars( + X=get_value(X), + scale=get_value(scale), + bias=get_value(bias), + ) + .Y + ) -def identity(input: Var, ) -> Var: +def identity( + input: Var, +) -> Var: r""" -Identity operator - -Parameters -========== -input - Type V. - Input tensor - -Returns -======= -output : Var - Type V. - Tensor to copy input into. - -Notes -===== -Signature: ``ai.onnx@21::Identity``. - -Type constraints: - - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Identity operator + + Parameters + ========== + input + Type V. + Input tensor + + Returns + ======= + output : Var + Type V. + Tensor to copy input into. + + Notes + ===== + Signature: ``ai.onnx@21::Identity``. + + Type constraints: + - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Identity( - _Identity.Attributes( - ), _Identity.Inputs( - input=unwrap_vars(input), ), ).get_output_vars( - input=get_value(input), ).output + return ( + _Identity( + _Identity.Attributes(), + _Identity.Inputs( + input=unwrap_vars(input), + ), + ) + .get_output_vars( + input=get_value(input), + ) + .output + ) -def if_(cond: Var, *, else_branch: Callable[[], Iterable[Var]], then_branch: Callable[[], Iterable[Var]], ) -> Sequence[Var]: +def if_( + cond: Var, + *, + else_branch: Callable[[], Iterable[Var]], + then_branch: Callable[[], Iterable[Var]], +) -> Sequence[Var]: r""" -If conditional - -Parameters -========== -cond - Type B. - Condition for the if. The tensor must contain a single element. -else_branch - Attribute. - Graph to run if condition is false. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the then_branch. -then_branch - Attribute. - Graph to run if condition is true. Has N outputs: values you wish to be - live-out to the enclosing scope. The number of outputs must match the - number of outputs in the else_branch. - -Returns -======= -outputs : Sequence[Var] - Type V. - Values that are live-out to the enclosing scope. The return values in - the ``then_branch`` and ``else_branch`` must be of the same data type. - The ``then_branch`` and ``else_branch`` may produce tensors with the - same element type and different shapes. If corresponding outputs from - the then-branch and the else-branch have static shapes S1 and S2, then - the shape of the corresponding output variable of the if-node (if - present) must be compatible with both S1 and S2 as it represents the - union of both possible shapes.For example, if in a model file, the first - output of ``then_branch`` is typed float tensor with shape [2] and the - first output of ``else_branch`` is another float tensor with shape [3], - If's first output should have (a) no shape set, or (b) a shape of rank 1 - with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank - 1 with a unique ``dim_param``. In contrast, the first output cannot have - the shape [2] since [2] and [3] are not compatible. - -Notes -===== -Signature: ``ai.onnx@21::If``. - -Type constraints: - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int4))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint4))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int4))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint4))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + If conditional + + Parameters + ========== + cond + Type B. + Condition for the if. The tensor must contain a single element. + else_branch + Attribute. + Graph to run if condition is false. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the then_branch. + then_branch + Attribute. + Graph to run if condition is true. Has N outputs: values you wish to be + live-out to the enclosing scope. The number of outputs must match the + number of outputs in the else_branch. + + Returns + ======= + outputs : Sequence[Var] + Type V. + Values that are live-out to the enclosing scope. The return values in + the ``then_branch`` and ``else_branch`` must be of the same data type. + The ``then_branch`` and ``else_branch`` may produce tensors with the + same element type and different shapes. If corresponding outputs from + the then-branch and the else-branch have static shapes S1 and S2, then + the shape of the corresponding output variable of the if-node (if + present) must be compatible with both S1 and S2 as it represents the + union of both possible shapes.For example, if in a model file, the first + output of ``then_branch`` is typed float tensor with shape [2] and the + first output of ``else_branch`` is another float tensor with shape [3], + If's first output should have (a) no shape set, or (b) a shape of rank 1 + with neither ``dim_value`` nor ``dim_param`` set, or (c) a shape of rank + 1 with a unique ``dim_param``. In contrast, the first output cannot have + the shape [2] since [2] and [3] are not compatible. + + Notes + ===== + Signature: ``ai.onnx@21::If``. + + Type constraints: + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int4))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint4))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int4))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint4))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - _else_branch_subgraph: Graph = subgraph( - (), - else_branch + _else_branch_subgraph: Graph = subgraph((), else_branch) + _then_branch_subgraph: Graph = subgraph((), then_branch) + return ( + _If( + _If.Attributes( + else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), + then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), + ), + _If.Inputs( + cond=unwrap_vars(cond), + ), + out_variadic=len(_else_branch_subgraph.requested_results), + ) + .get_output_vars( + cond=get_value(cond), + ) + .outputs ) - _then_branch_subgraph: Graph = subgraph( - (), - then_branch - ) - return _If( - _If.Attributes( - else_branch=AttrGraph(_else_branch_subgraph, name="else_branch"), - then_branch=AttrGraph(_then_branch_subgraph, name="then_branch"), - ), _If.Inputs( - cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), ).get_output_vars( - cond=get_value(cond), ).outputs -def loop(M: Optional[Var] = None, cond: Optional[Var] = None, v_initial: Sequence[Var] = (), *, body: Callable[..., Iterable[Var]], ) -> Sequence[Var]: +def loop( + M: Optional[Var] = None, + cond: Optional[Var] = None, + v_initial: Sequence[Var] = (), + *, + body: Callable[..., Iterable[Var]], +) -> Sequence[Var]: r""" -Generic Looping construct. This loop has multiple termination -conditions: - -1) Trip count. Iteration count specified at runtime. Set by specifying - the input M. Optional. Set to empty string to omit. Note that a - static trip count (specified at graph construction time) can be - specified by passing in a constant node for input M. -2) Loop termination condition. This is an input to the op that - determines whether to run the first iteration and also a loop-carried - dependency for the body graph. The body graph must yield a value for - the condition variable, whether this input is provided or not. - -This table summarizes the operating modes of this operator with -equivalent C-style code: - -Operator inputs defined as (max_trip_count, condition_var). - -- input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } - -- input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } - -- input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } - -- input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } - -- input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } - -*Sample usage - cond as well as trip count* - -:: - - graph predict-net { - %a = Constant[value = ]() - %b = Constant[value = ]() - %keepgoing = Constant[value = ]() - %max_trip_count = Constant[value = ]() - %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) - return - } - - graph body-net ( - %i[INT32, scalar] // iteration number - %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used - %b_in[INT32, scalar] // incoming value of loop-carried-dependency b - ) { - %my_local = Add(%a, %b_in) - %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b - %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition - %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated - return %keepgoing_out, %b_out, %user_defined_val - } - -*Sample equivalent C code* - -:: - - { - /* User-defined code (enclosing scope) */ - int a = 3, b = 6; - bool keepgoing = true; // Analogous to input cond - /* End user-defined code */ - - /* Implicitly-defined code */ - const int max_trip_count = 10; // Analogous to input M - int user_defined_vals[]; // Imagine this is resizable - /* End implicitly-defined code */ - /* initialize loop-carried variables and scan-output variables */ - bool keepgoing_out = keepgoing - int b_out = b - - for (int i=0; i < max_trip_count && keepgoing_out; ++i) { - /* Implicitly-defined code: bind actual parameter values - to formal parameter variables of loop-body */ - bool keepgoing_in = keepgoing_out; - bool b_in = b_out; - - /* User-defined code (loop body) */ - int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine - b_out = a - b_in; - keepgoing_out = my_local > b_out; - user_defined_val = b_in + b_in; // b_in and b_out are different variables - /* End user-defined code */ - - /* Implicitly defined-code */ - user_defined_vals[i] = user_defined_val // accumulate scan-output values - } - // int t = my_local; // Can't do this. my_local is not accessible here. - - // The values below are bound to the output variables of the loop and therefore accessible - // b_out; user_defined_vals; keepgoing_out; - } - -There are several things of note in this code snippet: - -1) Values from the enclosing scope (i.e. variable "a" here) are in scope - and can be referenced in the inputs of the loop. -2) Any values computed in the loop body that needs to be used in a - subsequent iteration or after the loop are modelled using a pair of - variables in the loop-body, consisting of an input variable (eg., - b_in) and an output variable (eg., b_out). These are referred to as - loop-carried dependences. The loop operation node supplies the input - value of the input variable for the first iteration, and returns the - output value of the output variable produced by the final iteration. -3) Scan_output variables are used to implicitly concatenate values - computed across all the iterations. In the above example, the value - of user_defined_val computed over all iterations are concatenated and - returned as the value of user_defined_vals after the loop. -4) Values created in the body cannot be accessed in the enclosing scope, - except using the mechanism described above. - -Note that the semantics of this op support "diagonal" or "wavefront" -execution. (See Step 3 here for an example: -https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). -Frontends should emit multi-layer RNNs as a series of While operators -(with time being the inner looping dimension), with each successive -layer consuming the scan_outputs from the previous layer, possibly going -through several point-wise operators (e.g. dropout, residual -connections, linear layer). - -The input/output of subgraph (produced by loop node) matching is based -on order instead of name. The implementation will figure out the names -based on this order. - -Parameters -========== -M - Type I. - A maximum trip-count for the loop specified at runtime. Optional. Pass - empty string to skip. -cond - Type B. - A boolean termination condition. Optional. Pass empty string to skip. -v_initial - Type V. - The initial values of any loop-carried dependencies (values that change - across loop iterations) -body - Attribute. - The graph run each iteration. It has 2+N inputs: (iteration_num, - condition, loop carried dependencies...). It has 1+N+K outputs: - (condition, loop carried dependencies..., scan_outputs...). Each - scan_output is created by concatenating the value of the specified - output value at the end of each iteration of the loop. It is an error if - the dimensions or data type of these scan_outputs change across loop - iterations. - -Returns -======= -v_final_and_scan_outputs : Sequence[Var] - Type V. - Final N loop carried dependency values then K scan_outputs. Scan outputs - must be Tensors. - -Notes -===== -Signature: ``ai.onnx@21::Loop``. - -Type constraints: - - I: `tensor(int64)` - - B: `tensor(bool)` - - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int4))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint4))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int4))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint4))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Generic Looping construct. This loop has multiple termination + conditions: + + 1) Trip count. Iteration count specified at runtime. Set by specifying + the input M. Optional. Set to empty string to omit. Note that a + static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. + 2) Loop termination condition. This is an input to the op that + determines whether to run the first iteration and also a loop-carried + dependency for the body graph. The body graph must yield a value for + the condition variable, whether this input is provided or not. + + This table summarizes the operating modes of this operator with + equivalent C-style code: + + Operator inputs defined as (max_trip_count, condition_var). + + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } + + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } + + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } + + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } + + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } + + *Sample usage - cond as well as trip count* + + :: + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + + *Sample equivalent C code* + + :: + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + + There are several things of note in this code snippet: + + 1) Values from the enclosing scope (i.e. variable "a" here) are in scope + and can be referenced in the inputs of the loop. + 2) Any values computed in the loop body that needs to be used in a + subsequent iteration or after the loop are modelled using a pair of + variables in the loop-body, consisting of an input variable (eg., + b_in) and an output variable (eg., b_out). These are referred to as + loop-carried dependences. The loop operation node supplies the input + value of the input variable for the first iteration, and returns the + output value of the output variable produced by the final iteration. + 3) Scan_output variables are used to implicitly concatenate values + computed across all the iterations. In the above example, the value + of user_defined_val computed over all iterations are concatenated and + returned as the value of user_defined_vals after the loop. + 4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + + Note that the semantics of this op support "diagonal" or "wavefront" + execution. (See Step 3 here for an example: + https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). + Frontends should emit multi-layer RNNs as a series of While operators + (with time being the inner looping dimension), with each successive + layer consuming the scan_outputs from the previous layer, possibly going + through several point-wise operators (e.g. dropout, residual + connections, linear layer). + + The input/output of subgraph (produced by loop node) matching is based + on order instead of name. The implementation will figure out the names + based on this order. + + Parameters + ========== + M + Type I. + A maximum trip-count for the loop specified at runtime. Optional. Pass + empty string to skip. + cond + Type B. + A boolean termination condition. Optional. Pass empty string to skip. + v_initial + Type V. + The initial values of any loop-carried dependencies (values that change + across loop iterations) + body + Attribute. + The graph run each iteration. It has 2+N inputs: (iteration_num, + condition, loop carried dependencies...). It has 1+N+K outputs: + (condition, loop carried dependencies..., scan_outputs...). Each + scan_output is created by concatenating the value of the specified + output value at the end of each iteration of the loop. It is an error if + the dimensions or data type of these scan_outputs change across loop + iterations. + + Returns + ======= + v_final_and_scan_outputs : Sequence[Var] + Type V. + Final N loop carried dependency values then K scan_outputs. Scan outputs + must be Tensors. + + Notes + ===== + Signature: ``ai.onnx@21::Loop``. + + Type constraints: + - I: `tensor(int64)` + - B: `tensor(bool)` + - V: `optional(seq(tensor(bfloat16)))`, `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bfloat16))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(float8e4m3fn))`, `optional(tensor(float8e4m3fnuz))`, `optional(tensor(float8e5m2))`, `optional(tensor(float8e5m2fnuz))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int4))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint4))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bfloat16))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(float8e4m3fn))`, `seq(tensor(float8e4m3fnuz))`, `seq(tensor(float8e5m2))`, `seq(tensor(float8e5m2fnuz))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int4))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint4))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ _body_subgraph: Graph = subgraph( - typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))])+ [var.unwrap_type() for var in v_initial], - body + typing_cast(list[Type], [Tensor(np.int64, (1,)), Tensor(np.bool_, (1,))]) + + [var.unwrap_type() for var in v_initial], + body, + ) + return ( + _Loop( + _Loop.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + ), + _Loop.Inputs( + M=unwrap_vars(M), + cond=unwrap_vars(cond), + v_initial=unwrap_vars(v_initial), + ), + out_variadic=len(_body_subgraph.requested_results) - 1, + ) + .get_output_vars( + M=get_value(M), + cond=get_value(cond), + v_initial=get_value(v_initial), + ) + .v_final_and_scan_outputs ) - return _Loop( - _Loop.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - ), _Loop.Inputs( - M=unwrap_vars(M), cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, ).get_output_vars( - M=get_value(M), cond=get_value(cond), v_initial=get_value(v_initial), ).v_final_and_scan_outputs -def pad(data: Var, pads: Var, constant_value: Optional[Var] = None, axes: Optional[Var] = None, *, mode: str = "constant", ) -> Var: +def pad( + data: Var, + pads: Var, + constant_value: Optional[Var] = None, + axes: Optional[Var] = None, + *, + mode: str = "constant", +) -> Var: r""" -Given a tensor containing the data to be padded (``data``), a tensor -containing the number of start and end pad values for axis (``pads``), -(optionally) a ``mode``, and (optionally) ``constant_value``, a padded -tensor (``output``) is generated. + Given a tensor containing the data to be padded (``data``), a tensor + containing the number of start and end pad values for axis (``pads``), + (optionally) a ``mode``, and (optionally) ``constant_value``, a padded + tensor (``output``) is generated. -The three supported ``modes`` are (similar to corresponding modes -supported by ``numpy.pad``): + The three supported ``modes`` are (similar to corresponding modes + supported by ``numpy.pad``): -1) ``constant``\ (default) - pads with a given constant value as - specified by ``constant_value`` (which defaults to 0, empty string, - or False) + 1) ``constant``\ (default) - pads with a given constant value as + specified by ``constant_value`` (which defaults to 0, empty string, + or False) -2) ``reflect`` - pads with the reflection of the vector mirrored on the - first and last values of the vector along each axis + 2) ``reflect`` - pads with the reflection of the vector mirrored on the + first and last values of the vector along each axis -3) ``edge`` - pads with the edge values of array + 3) ``edge`` - pads with the edge values of array -4) ``wrap`` - wrap-around padding as if the data tensor forms a torus + 4) ``wrap`` - wrap-around padding as if the data tensor forms a torus -Example 1 (``constant`` mode): + Example 1 (``constant`` mode): -Insert 0 pads to the beginning of the second dimension. + Insert 0 pads to the beginning of the second dimension. -:: + :: - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] - pads = [0, 2, 0, 0] - - mode = 'constant' - - constant_value = 0.0 - - output = [ - [0.0, 0.0, 1.0, 1.2], - [0.0, 0.0, 2.3, 3.4], - [0.0, 0.0, 4.5, 5.7], - ] - -Example 2 (``reflect`` mode): - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'reflect' - - output = [ - [1.0, 1.2, 1.0, 1.2], - [2.3, 3.4, 2.3, 3.4], - [4.5, 5.7, 4.5, 5.7], - ] - -Example 3 (``edge`` mode): - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [0, 2, 0, 0] - - mode = 'edge' - - output = [ - [1.0, 1.0, 1.0, 1.2], - [2.3, 2.3, 2.3, 3.4], - [4.5, 4.5, 4.5, 5.7], - ] - -Example 4 (``wrap`` mode): - -:: - - data = [ - [1.0, 1.2], - [2.3, 3.4], - [4.5, 5.7], - ] - - pads = [2, 1, 1, 1] - - mode = 'wrap' - - output = [ - [3.4, 2.3, 3.4, 2.3], - [5.7, 4.5, 5.7, 4.5], - [1.2, 1.0, 1.2, 1.0], - [3.4, 2.3, 3.4, 2.3], - [5.7, 4.5, 5.7, 4.5], - [1.2, 1.0, 1.2, 1.0], - ] - -Parameters -========== -data - Type T. - Input tensor. -pads - Type tensor(int64). - Tensor of integers indicating the number of padding elements to add or - remove (if negative) at the beginning and end of each axis. For 2D input - tensor, it is the number of pixels. ``pads`` should be a 1D tensor of - shape [2 \* num_axes] where ``num_axes`` refers to the number of - elements in the ``axes`` input or the input rank if ``axes`` are not - provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, - ..., x1_end, x2_end,...], where xi_begin is the number of pad values - added at the beginning of axis ``axes[i]`` and xi_end, the number of pad - values added at the end of axis ``axes[i]``. -constant_value - Type T. - (Optional) A scalar value to be used if the mode chosen is ``constant`` - (by default it is 0, empty string or False). -axes - Type Tind. - 1-D tensor of axes that ``pads`` apply to. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(data). Behavior is undefined if an axis is repeated. If not - provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). -mode - Attribute. - Supported modes: ``constant``\ (default), ``reflect``, ``edge``, - ``wrap`` - -Returns -======= -output : Var - Type T. - Tensor after padding. - -Notes -===== -Signature: ``ai.onnx@21::Pad``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - Tind: `tensor(int32)`, `tensor(int64)` + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + + Example 2 (``reflect`` mode): + + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] + + Example 3 (``edge`` mode): + + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] + + Example 4 (``wrap`` mode): + + :: + + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [2, 1, 1, 1] + + mode = 'wrap' + + output = [ + [3.4, 2.3, 3.4, 2.3], + [5.7, 4.5, 5.7, 4.5], + [1.2, 1.0, 1.2, 1.0], + [3.4, 2.3, 3.4, 2.3], + [5.7, 4.5, 5.7, 4.5], + [1.2, 1.0, 1.2, 1.0], + ] + + Parameters + ========== + data + Type T. + Input tensor. + pads + Type tensor(int64). + Tensor of integers indicating the number of padding elements to add or + remove (if negative) at the beginning and end of each axis. For 2D input + tensor, it is the number of pixels. ``pads`` should be a 1D tensor of + shape [2 \* num_axes] where ``num_axes`` refers to the number of + elements in the ``axes`` input or the input rank if ``axes`` are not + provided explicitly. ``pads`` format should be: [x1_begin, x2_begin, + ..., x1_end, x2_end,...], where xi_begin is the number of pad values + added at the beginning of axis ``axes[i]`` and xi_end, the number of pad + values added at the end of axis ``axes[i]``. + constant_value + Type T. + (Optional) A scalar value to be used if the mode chosen is ``constant`` + (by default it is 0, empty string or False). + axes + Type Tind. + 1-D tensor of axes that ``pads`` apply to. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(data). Behavior is undefined if an axis is repeated. If not + provided, all axes are assumed (``[0, 1, ..., input_rank-1]``). + mode + Attribute. + Supported modes: ``constant``\ (default), ``reflect``, ``edge``, + ``wrap`` + + Returns + ======= + output : Var + Type T. + Tensor after padding. + + Notes + ===== + Signature: ``ai.onnx@21::Pad``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - Tind: `tensor(int32)`, `tensor(int64)` """ - return _Pad( - _Pad.Attributes( - mode=AttrString(mode, name="mode"), - ), _Pad.Inputs( - data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), pads=get_value(pads), constant_value=get_value(constant_value), axes=get_value(axes), ).output + return ( + _Pad( + _Pad.Attributes( + mode=AttrString(mode, name="mode"), + ), + _Pad.Inputs( + data=unwrap_vars(data), + pads=unwrap_vars(pads), + constant_value=unwrap_vars(constant_value), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + pads=get_value(pads), + constant_value=get_value(constant_value), + axes=get_value(axes), + ) + .output + ) -def qlinear_matmul(a: Var, a_scale: Var, a_zero_point: Var, b: Var, b_scale: Var, b_zero_point: Var, y_scale: Var, y_zero_point: Var, ) -> Var: +def qlinear_matmul( + a: Var, + a_scale: Var, + a_zero_point: Var, + b: Var, + b_scale: Var, + b_zero_point: Var, + y_scale: Var, + y_zero_point: Var, +) -> Var: r""" -Matrix product that behaves like numpy.matmul: -https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. -It consumes two quantized input tensors, their scales and zero points, -scale and zero point of output, and computes the quantized output. The -quantization formula is y = saturate((x / y_scale) + y_zero_point). For -(x / y_scale), it is rounding to nearest ties to even. Refer to -https://en.wikipedia.org/wiki/Rounding for details. Scale and zero point -must have same shape. They must be either scalar (per tensor) or N-D -tensor (per row for 'a' and per column for 'b'). Scalar refers to per -tensor quantization whereas N-D refers to per row or per column -quantization. If the input is 2D of shape [M, K] then zero point and -scale tensor may be an M element vector [v_1, v_2, ..., v_M] for per row -quantization and K element vector of shape [v_1, v_2, ..., v_K] for per -column quantization. If the input is N-D tensor with shape [D1, D2, M, -K] then zero point and scale tensor may have shape [D1, D2, M, 1] for -per row quantization and shape [D1, D2, 1, K] for per column -quantization. Production must never overflow, and accumulation may -overflow if and only if in 32 bits. - -Parameters -========== -a - Type T1. - N-dimensional quantized matrix a -a_scale - Type TS. - scale of quantized input a -a_zero_point - Type T1. - zero point of quantized input a -b - Type T2. - N-dimensional quantized matrix b -b_scale - Type TS. - scale of quantized input b -b_zero_point - Type T2. - zero point of quantized input b -y_scale - Type TS. - scale of quantized output y -y_zero_point - Type T3. - zero point of quantized output y - -Returns -======= -y : Var - Type T3. - Quantized matrix multiply results from a \* b - -Notes -===== -Signature: ``ai.onnx@21::QLinearMatMul``. - -Type constraints: - - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` - - TS: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` - - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` - - T3: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + It consumes two quantized input tensors, their scales and zero points, + scale and zero point of output, and computes the quantized output. The + quantization formula is y = saturate((x / y_scale) + y_zero_point). For + (x / y_scale), it is rounding to nearest ties to even. Refer to + https://en.wikipedia.org/wiki/Rounding for details. Scale and zero point + must have same shape. They must be either scalar (per tensor) or N-D + tensor (per row for 'a' and per column for 'b'). Scalar refers to per + tensor quantization whereas N-D refers to per row or per column + quantization. If the input is 2D of shape [M, K] then zero point and + scale tensor may be an M element vector [v_1, v_2, ..., v_M] for per row + quantization and K element vector of shape [v_1, v_2, ..., v_K] for per + column quantization. If the input is N-D tensor with shape [D1, D2, M, + K] then zero point and scale tensor may have shape [D1, D2, M, 1] for + per row quantization and shape [D1, D2, 1, K] for per column + quantization. Production must never overflow, and accumulation may + overflow if and only if in 32 bits. + + Parameters + ========== + a + Type T1. + N-dimensional quantized matrix a + a_scale + Type TS. + scale of quantized input a + a_zero_point + Type T1. + zero point of quantized input a + b + Type T2. + N-dimensional quantized matrix b + b_scale + Type TS. + scale of quantized input b + b_zero_point + Type T2. + zero point of quantized input b + y_scale + Type TS. + scale of quantized output y + y_zero_point + Type T3. + zero point of quantized output y + + Returns + ======= + y : Var + Type T3. + Quantized matrix multiply results from a \* b + + Notes + ===== + Signature: ``ai.onnx@21::QLinearMatMul``. + + Type constraints: + - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` + - TS: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` + - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` + - T3: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - return _QLinearMatMul( - _QLinearMatMul.Attributes( - ), _QLinearMatMul.Inputs( - a=unwrap_vars(a), a_scale=unwrap_vars(a_scale), a_zero_point=unwrap_vars(a_zero_point), b=unwrap_vars(b), b_scale=unwrap_vars(b_scale), b_zero_point=unwrap_vars(b_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( - a=get_value(a), a_scale=get_value(a_scale), a_zero_point=get_value(a_zero_point), b=get_value(b), b_scale=get_value(b_scale), b_zero_point=get_value(b_zero_point), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y + return ( + _QLinearMatMul( + _QLinearMatMul.Attributes(), + _QLinearMatMul.Inputs( + a=unwrap_vars(a), + a_scale=unwrap_vars(a_scale), + a_zero_point=unwrap_vars(a_zero_point), + b=unwrap_vars(b), + b_scale=unwrap_vars(b_scale), + b_zero_point=unwrap_vars(b_zero_point), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + a=get_value(a), + a_scale=get_value(a_scale), + a_zero_point=get_value(a_zero_point), + b=get_value(b), + b_scale=get_value(b_scale), + b_zero_point=get_value(b_zero_point), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) -def quantize_linear(x: Var, y_scale: Var, y_zero_point: Optional[Var] = None, *, axis: int = 1, block_size: int = 0, output_dtype: int = 0, saturate: int = 1, ) -> Var: +def quantize_linear( + x: Var, + y_scale: Var, + y_zero_point: Optional[Var] = None, + *, + axis: int = 1, + block_size: int = 0, + output_dtype: int = 0, + saturate: int = 1, +) -> Var: r""" -The linear quantization operator consumes a high-precision tensor, a -scale, and a zero point to compute the low-precision/quantized tensor. -The scale factor and zero point must have the same shape, determining -the quantization granularity. The quantization formula is -``y = saturate((x / y_scale) + y_zero_point)``. - -Saturation is done according to: - -- uint16: [0, 65535] -- int16: [-32768, 32767] -- uint8: [0, 255] -- int8: [-128, 127] -- uint4: [0, 15] -- int4: [-8, 7] - -For ``(x / y_scale)``, it rounds to the nearest even. Refer to -https://en.wikipedia.org/wiki/Rounding for details. - -``y_zero_point`` and ``y`` must have the same type. ``y_zero_point`` is -usually not used for quantization to float8 types, but the quantization -formula remains the same for consistency, and the type of the attribute -``y_zero_point`` still determines the quantization type. - -There are three supported quantization granularities, determined by the -shape of ``y_scale``. In all cases, ``y_zero_point`` must have the same -shape as ``y_scale``. - -- Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. -- Per-axis quantization: The scale must be a 1-D tensor, with the - length of the quantization axis. For an input shape - ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D - tensor of length ``Di``. -- Blocked quantization: The scale's shape is identical to the input's - shape, except for one dimension, in which blocking is performed. - Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block - size ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. - -Parameters -========== -x - Type T1. - N-D full precision Input tensor to be quantized. -y_scale - Type T1. - Scale for doing quantization to get ``y``. For per-tensor/layer - quantization the scale is a scalar, for per-axis quantization it is a - 1-D Tensor and for blocked quantization it has the same shape as the - input, except for one dimension in which blocking is performed. -y_zero_point - Type T2. - Zero point for doing quantization to get ``y``. Shape must match - ``y_scale``.Default is uint8 with zero point of 0 if it's not specified. -axis - Attribute. - (Optional) The axis of the dequantizing dimension of the input tensor. - Used for per-axis and blocked quantization. Negative value means - counting dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. -block_size - Attribute. - (Optional) The size of the quantization block (number of times every - scale is replicated). Used only for blocked quantization. The block size - is a positive integer. Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, - ``y_scale`` shape ``(S0, ... Si, ...Sn)`` and ``axis=i``, the accepted - range is ``[ceil(Di/Si), ceil(Di/(Si-1))-1]`` -output_dtype - Attribute. - (Optional) The output data type. If not supplied, the output data type - is inferred from ``y_zero_point`` data type (``T2``). If neither - ``output_dtype`` nor ``y_zero_point`` are supplied, output data type is - uint8. If both ``output_dtype`` and ``y_zero_point`` are specified, - ``output_dtype`` must be ``T2``. -saturate - Attribute. - The parameter defines how the conversion behaves if an input value is - out of range of the destination type. It only applies for float 8 - quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). - It is true by default. All cases are fully described in two tables - inserted in the operator description. - -Returns -======= -y : Var - Type T2. - N-D quantized output tensor. It has same shape as input ``x``. - -Notes -===== -Signature: ``ai.onnx@21::QuantizeLinear``. - -Type constraints: - - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` + The linear quantization operator consumes a high-precision tensor, a + scale, and a zero point to compute the low-precision/quantized tensor. + The scale factor and zero point must have the same shape, determining + the quantization granularity. The quantization formula is + ``y = saturate((x / y_scale) + y_zero_point)``. + + Saturation is done according to: + + - uint16: [0, 65535] + - int16: [-32768, 32767] + - uint8: [0, 255] + - int8: [-128, 127] + - uint4: [0, 15] + - int4: [-8, 7] + + For ``(x / y_scale)``, it rounds to the nearest even. Refer to + https://en.wikipedia.org/wiki/Rounding for details. + + ``y_zero_point`` and ``y`` must have the same type. ``y_zero_point`` is + usually not used for quantization to float8 types, but the quantization + formula remains the same for consistency, and the type of the attribute + ``y_zero_point`` still determines the quantization type. + + There are three supported quantization granularities, determined by the + shape of ``y_scale``. In all cases, ``y_zero_point`` must have the same + shape as ``y_scale``. + + - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. + - Per-axis quantization: The scale must be a 1-D tensor, with the + length of the quantization axis. For an input shape + ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D + tensor of length ``Di``. + - Blocked quantization: The scale's shape is identical to the input's + shape, except for one dimension, in which blocking is performed. + Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block + size ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. + + Parameters + ========== + x + Type T1. + N-D full precision Input tensor to be quantized. + y_scale + Type T1. + Scale for doing quantization to get ``y``. For per-tensor/layer + quantization the scale is a scalar, for per-axis quantization it is a + 1-D Tensor and for blocked quantization it has the same shape as the + input, except for one dimension in which blocking is performed. + y_zero_point + Type T2. + Zero point for doing quantization to get ``y``. Shape must match + ``y_scale``.Default is uint8 with zero point of 0 if it's not specified. + axis + Attribute. + (Optional) The axis of the dequantizing dimension of the input tensor. + Used for per-axis and blocked quantization. Negative value means + counting dimensions from the back. Accepted range is ``[-r, r-1]`` where + ``r = rank(input)``. + block_size + Attribute. + (Optional) The size of the quantization block (number of times every + scale is replicated). Used only for blocked quantization. The block size + is a positive integer. Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, + ``y_scale`` shape ``(S0, ... Si, ...Sn)`` and ``axis=i``, the accepted + range is ``[ceil(Di/Si), ceil(Di/(Si-1))-1]`` + output_dtype + Attribute. + (Optional) The output data type. If not supplied, the output data type + is inferred from ``y_zero_point`` data type (``T2``). If neither + ``output_dtype`` nor ``y_zero_point`` are supplied, output data type is + uint8. If both ``output_dtype`` and ``y_zero_point`` are specified, + ``output_dtype`` must be ``T2``. + saturate + Attribute. + The parameter defines how the conversion behaves if an input value is + out of range of the destination type. It only applies for float 8 + quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). + It is true by default. All cases are fully described in two tables + inserted in the operator description. + + Returns + ======= + y : Var + Type T2. + N-D quantized output tensor. It has same shape as input ``x``. + + Notes + ===== + Signature: ``ai.onnx@21::QuantizeLinear``. + + Type constraints: + - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` + - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` """ - return _QuantizeLinear( - _QuantizeLinear.Attributes( - axis=AttrInt64(axis, name="axis"), - block_size=AttrInt64(block_size, name="block_size"), - output_dtype=AttrInt64(output_dtype, name="output_dtype"), - saturate=AttrInt64(saturate, name="saturate"), - ), _QuantizeLinear.Inputs( - x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), ).get_output_vars( - x=get_value(x), y_scale=get_value(y_scale), y_zero_point=get_value(y_zero_point), ).y - - -def reshape(data: Var, shape: Var, *, allowzero: int = 0, ) -> Var: + return ( + _QuantizeLinear( + _QuantizeLinear.Attributes( + axis=AttrInt64(axis, name="axis"), + block_size=AttrInt64(block_size, name="block_size"), + output_dtype=AttrInt64(output_dtype, name="output_dtype"), + saturate=AttrInt64(saturate, name="saturate"), + ), + _QuantizeLinear.Inputs( + x=unwrap_vars(x), + y_scale=unwrap_vars(y_scale), + y_zero_point=unwrap_vars(y_zero_point), + ), + ) + .get_output_vars( + x=get_value(x), + y_scale=get_value(y_scale), + y_zero_point=get_value(y_zero_point), + ) + .y + ) + + +def reshape( + data: Var, + shape: Var, + *, + allowzero: int = 0, +) -> Var: r""" -Reshape the input tensor similar to numpy.reshape. First input is the -data tensor, second input is a shape tensor which specifies the output -shape. It outputs the reshaped tensor. At most one dimension of the new -shape can be -1. In this case, the value is inferred from the size of -the tensor and the remaining dimensions. A dimension could also be 0, in -which case the actual dimension value is unchanged (i.e. taken from the -input tensor). If 'allowzero' is set, and the new shape includes 0, the -dimension will be set explicitly to zero (i.e. not taken from input -tensor). Shape (second input) could be an empty shape, which means -converting to a scalar. The input tensor's shape and the output tensor's -shape are required to have the same number of elements. - -If the attribute 'allowzero' is set, it is invalid for the specified -shape to contain both a zero value and -1, as the value of the dimension -corresponding to -1 cannot be determined uniquely. - -Parameters -========== -data - Type T. - An input tensor. -shape - Type tensor(int64). - Specified shape for output. -allowzero - Attribute. - (Optional) By default, when any value in the 'shape' input is equal to - zero the corresponding dimension value is copied from the input tensor - dynamically. allowzero=1 indicates that if any value in the 'shape' - input is set to zero, the zero value is honored, similar to NumPy. - -Returns -======= -reshaped : Var - Type T. - Reshaped data. - -Notes -===== -Signature: ``ai.onnx@21::Reshape``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Reshape the input tensor similar to numpy.reshape. First input is the + data tensor, second input is a shape tensor which specifies the output + shape. It outputs the reshaped tensor. At most one dimension of the new + shape can be -1. In this case, the value is inferred from the size of + the tensor and the remaining dimensions. A dimension could also be 0, in + which case the actual dimension value is unchanged (i.e. taken from the + input tensor). If 'allowzero' is set, and the new shape includes 0, the + dimension will be set explicitly to zero (i.e. not taken from input + tensor). Shape (second input) could be an empty shape, which means + converting to a scalar. The input tensor's shape and the output tensor's + shape are required to have the same number of elements. + + If the attribute 'allowzero' is set, it is invalid for the specified + shape to contain both a zero value and -1, as the value of the dimension + corresponding to -1 cannot be determined uniquely. + + Parameters + ========== + data + Type T. + An input tensor. + shape + Type tensor(int64). + Specified shape for output. + allowzero + Attribute. + (Optional) By default, when any value in the 'shape' input is equal to + zero the corresponding dimension value is copied from the input tensor + dynamically. allowzero=1 indicates that if any value in the 'shape' + input is set to zero, the zero value is honored, similar to NumPy. + + Returns + ======= + reshaped : Var + Type T. + Reshaped data. + + Notes + ===== + Signature: ``ai.onnx@21::Reshape``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Reshape( - _Reshape.Attributes( - allowzero=AttrInt64(allowzero, name="allowzero"), - ), _Reshape.Inputs( - data=unwrap_vars(data), shape=unwrap_vars(shape), ), ).get_output_vars( - data=get_value(data), shape=get_value(shape), ).reshaped + return ( + _Reshape( + _Reshape.Attributes( + allowzero=AttrInt64(allowzero, name="allowzero"), + ), + _Reshape.Inputs( + data=unwrap_vars(data), + shape=unwrap_vars(shape), + ), + ) + .get_output_vars( + data=get_value(data), + shape=get_value(shape), + ) + .reshaped + ) -def scan(initial_state_and_scan_inputs: Sequence[Var], *, body: Callable[..., Iterable[Var]], num_scan_inputs: int, scan_input_axes: Optional[Iterable[int]] = None, scan_input_directions: Optional[Iterable[int]] = None, scan_output_axes: Optional[Iterable[int]] = None, scan_output_directions: Optional[Iterable[int]] = None, ) -> Sequence[Var]: +def scan( + initial_state_and_scan_inputs: Sequence[Var], + *, + body: Callable[..., Iterable[Var]], + num_scan_inputs: int, + scan_input_axes: Optional[Iterable[int]] = None, + scan_input_directions: Optional[Iterable[int]] = None, + scan_output_axes: Optional[Iterable[int]] = None, + scan_output_directions: Optional[Iterable[int]] = None, +) -> Sequence[Var]: r""" -Scan can be used to iterate over one or more scan_input tensors, -constructing zero or more scan_output tensors. It combines ideas from -general recurrences, functional programming constructs such as scan, -fold, map, and zip, and is intended to enable generalizations of -RNN-like constructs for sequence-to-sequence processing. Other tensors -(referred to as state_variables here) can be used to carry a state when -iterating from one element to another (similar to hidden-state in RNNs, -also referred to as loop-carried dependences in the context of loops). -Many common usages involve a single scan_input tensor (where -functionality similar to scan, fold and map can be obtained). When more -than one scan_input is used, a behavior similar to zip is obtained. - -The attribute body must be a graph, specifying the computation to be -performed in every iteration. It takes as input the current values of -the state_variables and the current iterated element of the scan_inputs. -It must return the (updated) values of the state_variables and zero or -more scan_output_element tensors. The values of the scan_output_element -tensors are concatenated over all the iterations to produce the -scan_output values of the scan construct (similar to the concatenated -intermediate hidden-state values of RNN-like constructs). All the output -tensors (state_variables as well as scan_output_element tensors) are -required to have the same shape in each iteration of the loop (a -restriction imposed to enable efficient memory allocation). - -Note that the iterated element passed to the body subgraph does not have -a sequence axis. It will have a rank one less than the rank of the -corresponding scan_input. - -The scan operation returns the final values of the state_variables as -well as the scan_outputs. - -The optional attribute scan_input_directions specifies the direction -(forward or backward) for each scan input. If this attribute is omitted, -all sequences are scanned in the forward direction. A bidirectional scan -may be performed by specifying the same tensor input twice in the -scan_inputs, once with a forward direction, and once with a backward -direction. - -The scan_output of the operation is produced by concatenating the -scan_output_element values produced by the body in each iteration. The -optional attribute scan_output_directions specifies the direction in -which scan_output is constructed (by appending or prepending the -scan_output_element to scan_output in each iteration) for each -scan_output. If this attribute is omitted, the scan_output_element is -appended to the scan_output in each iteration. - -The optional attribute scan_input_axes specifies the axis to be scanned -for each scan_input. If omitted, every scan_input will be scanned in -axis 0. For example, if axis 0 is the batch axis and axis 1 is the time -axis (to be scanned), specify an axis value of 1. Note that scanning a -non-zero axis may be less efficient than scanning axis zero. - -The optional attribute scan_output_axes specifies the axis along which -the scan_outputs are accumulated for each scan_output. For example, if -axis 1 is the time axis (to be scanned) for both inputs and outputs, -specify a scan_input axis and scan_output axis value of 1. - -Note that because of the ONNX restriction that only the last parameter -of an operator can be variadic, the initial-states and scan-inputs are -listed together as one input parameter. Similarly, the final-states and -scan-outputs are listed together as one output parameter. The attribute -num_scan_inputs indicates the number M of scan-inputs. - -The behavior of - -:: - - Scan < - num_scan_inputs = m, - body = loop-body, - scan_input_axes = [axis_1, ..., axis_m] - > (init_1, ..., init_n, scan_1, ..., scan_m) - -is equivalent to the following pseudo-code: - -:: - - // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i - // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. - sequence_length = scan_1.shape[axis_1]; - - // initialize state-variables - st_1 = init_1; ... st_n = init_n; - // initialize scan-output variables: [] denotes an empty tensor - scan_out_1 = []; ...; scan_out_k = []; - // identify number of iterations: - - // execute loop - for (int t = 0; t < sequence_length; ++t) { - // generate the scan-input elements: the notation T[t] indicates the sub-tensor - // of rank one less than T obtained by indexing T at position t along axis k. - si_1 = scan_1[t]; - ... ; - si_m = scan_m[t]; - // execute loop-body - st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) - // accumulate the scan-output elements - scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); - } - - return st_1, ..., st_n, scan_out_1, ..., scan_out_k; - -*Sample usage: Encoding RNN using a Scan* - -The following example shows how a simple RNN over an input tensor %X, -with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi -and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. -Note that the loop-body is a nested graph, and it directly computes %Wi, -%Ri, %Wbi, and %Rbi (typically constants or initializers in the body -graph). If these values are computed in the outer graph, they need to be -passed in as extra state_variables. - -:: - - graph rnn-encoding { - %H_0 = ... - %X = ... - %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) - return %Y, %Y_h - } - - graph rnn-cell-1 ( - %H_tminus1[FLOAT, tensor] - %X_t[FLOAT, tensor] - ) { - %Wi = ... - %Ri = ... - %Wbi = ... - %Rbi = ... - %t1 = X_t * (Wi^T) - %t2 = H_tminus1*(Ri^T) - %t3 = Add(%t1, %t2) - %t4 = Add(%t3, %Wbi) - %t5 = Add(%t4, %Rbi) - %Ht = Tanh(%t5) - %Accumulate = Identity(%Ht) - return %Ht, %Accumulate - } - -Parameters -========== -initial_state_and_scan_inputs - Type V. - Initial values of the loop's N state variables followed by M scan_inputs -body - Attribute. - The graph run each iteration. It has N+M inputs: (loop state - variables..., scan_input_elts...). It has N+K outputs: (loop state - variables..., scan_output_elts...). Each scan_output is created by - concatenating the value of the specified scan_output_elt value at the - end of each iteration of the loop. It is an error if the dimensions of - these values change across loop iterations. -num_scan_inputs - Attribute. - An attribute specifying the number of scan_inputs M. -scan_input_axes - Attribute. - An optional list of M flags. The i-th element of the list specifies the - axis to be scanned (the sequence axis) for the i-th scan_input. If - omitted, 0 will be used as the scan axis for every scan_input. Negative - value for an axis means counting dimensions from the back. Accepted - range is [-r, r-1] where r = rank(input). -scan_input_directions - Attribute. - An optional list of M flags. The i-th element of the list specifies the - direction to be scanned for the i-th scan_input tensor: 0 indicates - forward direction and 1 indicates reverse direction. If omitted, all - scan_input tensors will be scanned in the forward direction. -scan_output_axes - Attribute. - An optional list of K flags. The i-th element of the list specifies the - axis for the i-th scan_output. The scan outputs are accumulated along - the specified axis. If omitted, 0 will be used as the scan axis for - every scan_output. Negative value for an axis means counting dimensions - from the back. Accepted range is [-r, r-1]. -scan_output_directions - Attribute. - An optional list of K flags, one for each scan_output. The i-th element - of the list specifies whether the i-th scan_output should be constructed - by appending or prepending a new value in each iteration: 0 indicates - appending and 1 indicates prepending. If omitted, all scan_output - tensors will be produced by appending a value in each iteration. - -Returns -======= -final_state_and_scan_outputs : Sequence[Var] - Type V. - Final values of the loop's N state variables followed by K scan_outputs - -Notes -===== -Signature: ``ai.onnx@21::Scan``. - -Type constraints: - - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Scan can be used to iterate over one or more scan_input tensors, + constructing zero or more scan_output tensors. It combines ideas from + general recurrences, functional programming constructs such as scan, + fold, map, and zip, and is intended to enable generalizations of + RNN-like constructs for sequence-to-sequence processing. Other tensors + (referred to as state_variables here) can be used to carry a state when + iterating from one element to another (similar to hidden-state in RNNs, + also referred to as loop-carried dependences in the context of loops). + Many common usages involve a single scan_input tensor (where + functionality similar to scan, fold and map can be obtained). When more + than one scan_input is used, a behavior similar to zip is obtained. + + The attribute body must be a graph, specifying the computation to be + performed in every iteration. It takes as input the current values of + the state_variables and the current iterated element of the scan_inputs. + It must return the (updated) values of the state_variables and zero or + more scan_output_element tensors. The values of the scan_output_element + tensors are concatenated over all the iterations to produce the + scan_output values of the scan construct (similar to the concatenated + intermediate hidden-state values of RNN-like constructs). All the output + tensors (state_variables as well as scan_output_element tensors) are + required to have the same shape in each iteration of the loop (a + restriction imposed to enable efficient memory allocation). + + Note that the iterated element passed to the body subgraph does not have + a sequence axis. It will have a rank one less than the rank of the + corresponding scan_input. + + The scan operation returns the final values of the state_variables as + well as the scan_outputs. + + The optional attribute scan_input_directions specifies the direction + (forward or backward) for each scan input. If this attribute is omitted, + all sequences are scanned in the forward direction. A bidirectional scan + may be performed by specifying the same tensor input twice in the + scan_inputs, once with a forward direction, and once with a backward + direction. + + The scan_output of the operation is produced by concatenating the + scan_output_element values produced by the body in each iteration. The + optional attribute scan_output_directions specifies the direction in + which scan_output is constructed (by appending or prepending the + scan_output_element to scan_output in each iteration) for each + scan_output. If this attribute is omitted, the scan_output_element is + appended to the scan_output in each iteration. + + The optional attribute scan_input_axes specifies the axis to be scanned + for each scan_input. If omitted, every scan_input will be scanned in + axis 0. For example, if axis 0 is the batch axis and axis 1 is the time + axis (to be scanned), specify an axis value of 1. Note that scanning a + non-zero axis may be less efficient than scanning axis zero. + + The optional attribute scan_output_axes specifies the axis along which + the scan_outputs are accumulated for each scan_output. For example, if + axis 1 is the time axis (to be scanned) for both inputs and outputs, + specify a scan_input axis and scan_output axis value of 1. + + Note that because of the ONNX restriction that only the last parameter + of an operator can be variadic, the initial-states and scan-inputs are + listed together as one input parameter. Similarly, the final-states and + scan-outputs are listed together as one output parameter. The attribute + num_scan_inputs indicates the number M of scan-inputs. + + The behavior of + + :: + + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) + + is equivalent to the following pseudo-code: + + :: + + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + + *Sample usage: Encoding RNN using a Scan* + + The following example shows how a simple RNN over an input tensor %X, + with weight tensor %Wi, recurrence weight tensor %Ri, bias tensors %Wbi + and %Rbi, and initial hidden-state %H_0 can be encoded as a ScanLoop. + Note that the loop-body is a nested graph, and it directly computes %Wi, + %Ri, %Wbi, and %Rbi (typically constants or initializers in the body + graph). If these values are computed in the outer graph, they need to be + passed in as extra state_variables. + + :: + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + + Parameters + ========== + initial_state_and_scan_inputs + Type V. + Initial values of the loop's N state variables followed by M scan_inputs + body + Attribute. + The graph run each iteration. It has N+M inputs: (loop state + variables..., scan_input_elts...). It has N+K outputs: (loop state + variables..., scan_output_elts...). Each scan_output is created by + concatenating the value of the specified scan_output_elt value at the + end of each iteration of the loop. It is an error if the dimensions of + these values change across loop iterations. + num_scan_inputs + Attribute. + An attribute specifying the number of scan_inputs M. + scan_input_axes + Attribute. + An optional list of M flags. The i-th element of the list specifies the + axis to be scanned (the sequence axis) for the i-th scan_input. If + omitted, 0 will be used as the scan axis for every scan_input. Negative + value for an axis means counting dimensions from the back. Accepted + range is [-r, r-1] where r = rank(input). + scan_input_directions + Attribute. + An optional list of M flags. The i-th element of the list specifies the + direction to be scanned for the i-th scan_input tensor: 0 indicates + forward direction and 1 indicates reverse direction. If omitted, all + scan_input tensors will be scanned in the forward direction. + scan_output_axes + Attribute. + An optional list of K flags. The i-th element of the list specifies the + axis for the i-th scan_output. The scan outputs are accumulated along + the specified axis. If omitted, 0 will be used as the scan axis for + every scan_output. Negative value for an axis means counting dimensions + from the back. Accepted range is [-r, r-1]. + scan_output_directions + Attribute. + An optional list of K flags, one for each scan_output. The i-th element + of the list specifies whether the i-th scan_output should be constructed + by appending or prepending a new value in each iteration: 0 indicates + appending and 1 indicates prepending. If omitted, all scan_output + tensors will be produced by appending a value in each iteration. + + Returns + ======= + final_state_and_scan_outputs : Sequence[Var] + Type V. + Final values of the loop's N state variables followed by K scan_outputs + + Notes + ===== + Signature: ``ai.onnx@21::Scan``. + + Type constraints: + - V: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ _body_subgraph: Graph = subgraph( - [Tensor(var.unwrap_tensor().dtype, (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape)) for var in initial_state_and_scan_inputs[:num_scan_inputs]] + [Tensor(var.unwrap_tensor().dtype) for var in initial_state_and_scan_inputs[num_scan_inputs:]], - body + [ + Tensor( + var.unwrap_tensor().dtype, + (lambda x: x[1:] if x is not None else None)(var.unwrap_tensor().shape), + ) + for var in initial_state_and_scan_inputs[:num_scan_inputs] + ] + + [ + Tensor(var.unwrap_tensor().dtype) + for var in initial_state_and_scan_inputs[num_scan_inputs:] + ], + body, + ) + return ( + _Scan( + _Scan.Attributes( + body=AttrGraph(_body_subgraph, name="body"), + num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), + scan_input_axes=AttrInt64s.maybe( + scan_input_axes, name="scan_input_axes" + ), + scan_input_directions=AttrInt64s.maybe( + scan_input_directions, name="scan_input_directions" + ), + scan_output_axes=AttrInt64s.maybe( + scan_output_axes, name="scan_output_axes" + ), + scan_output_directions=AttrInt64s.maybe( + scan_output_directions, name="scan_output_directions" + ), + ), + _Scan.Inputs( + initial_state_and_scan_inputs=unwrap_vars( + initial_state_and_scan_inputs + ), + ), + out_variadic=len(_body_subgraph.requested_results), + ) + .get_output_vars( + initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + ) + .final_state_and_scan_outputs ) - return _Scan( - _Scan.Attributes( - body=AttrGraph(_body_subgraph, name="body"), - num_scan_inputs=AttrInt64(num_scan_inputs, name="num_scan_inputs"), - scan_input_axes=AttrInt64s.maybe(scan_input_axes, name="scan_input_axes"), - scan_input_directions=AttrInt64s.maybe(scan_input_directions, name="scan_input_directions"), - scan_output_axes=AttrInt64s.maybe(scan_output_axes, name="scan_output_axes"), - scan_output_directions=AttrInt64s.maybe(scan_output_directions, name="scan_output_directions"), - ), _Scan.Inputs( - initial_state_and_scan_inputs=unwrap_vars(initial_state_and_scan_inputs), ), out_variadic=len(_body_subgraph.requested_results), ).get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), ).final_state_and_scan_outputs - - -def shape(data: Var, *, end: Optional[int] = None, start: int = 0, ) -> Var: + + +def shape( + data: Var, + *, + end: Optional[int] = None, + start: int = 0, +) -> Var: r""" -Takes a tensor as input and outputs an 1D int64 tensor containing the -shape of the input tensor. Optional attributes start and end can be used -to compute a slice of the input tensor's shape. If start axis is -omitted, the slice starts from axis 0. The end axis, if specified, is -exclusive (and the returned value will not include the size of that -axis). If the end axis is omitted, the axes upto the last one will be -included. Negative axes indicate counting back from the last axis. Note -that axes will be clamped to the range [0, r-1], where r is the rank of -the input tensor if they are out-of-range (after adding r in the case of -negative axis). Thus, specifying any end value > r is equivalent to -specifying an end value of r, and specifying any start value < -r is -equivalent to specifying a start value of 0. - -Examples: - -:: - - Input tensor with shape: [2, 3, 4] - No attributes specified. - Output: [2, 3, 4] - -:: - - Input tensor with shape: [2, 3, 4] - start: -1 - Output: [4] - -:: - - Input tensor with shape: [2, 3, 4] - end: -1 - Output: [2, 3] - -:: - - Input tensor with shape: [2, 3, 4] - start: 1 - end: 2 - Output: [3] - -Parameters -========== -data - Type T. - An input tensor. -end - Attribute. - (Optional) Ending axis for slicing the shape. Negative value means - counting dimensions from the back. If omitted, sizes of all axes upto - (including) the last one will be included. -start - Attribute. - (Optional) Starting axis for slicing the shape. Default value is - 0.Negative value means counting dimensions from the back. - -Returns -======= -shape : Var - Type T1. - Shape of the input tensor - -Notes -===== -Signature: ``ai.onnx@21::Shape``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` + Takes a tensor as input and outputs an 1D int64 tensor containing the + shape of the input tensor. Optional attributes start and end can be used + to compute a slice of the input tensor's shape. If start axis is + omitted, the slice starts from axis 0. The end axis, if specified, is + exclusive (and the returned value will not include the size of that + axis). If the end axis is omitted, the axes upto the last one will be + included. Negative axes indicate counting back from the last axis. Note + that axes will be clamped to the range [0, r-1], where r is the rank of + the input tensor if they are out-of-range (after adding r in the case of + negative axis). Thus, specifying any end value > r is equivalent to + specifying an end value of r, and specifying any start value < -r is + equivalent to specifying a start value of 0. + + Examples: + + :: + + Input tensor with shape: [2, 3, 4] + No attributes specified. + Output: [2, 3, 4] + + :: + + Input tensor with shape: [2, 3, 4] + start: -1 + Output: [4] + + :: + + Input tensor with shape: [2, 3, 4] + end: -1 + Output: [2, 3] + + :: + + Input tensor with shape: [2, 3, 4] + start: 1 + end: 2 + Output: [3] + + Parameters + ========== + data + Type T. + An input tensor. + end + Attribute. + (Optional) Ending axis for slicing the shape. Negative value means + counting dimensions from the back. If omitted, sizes of all axes upto + (including) the last one will be included. + start + Attribute. + (Optional) Starting axis for slicing the shape. Default value is + 0.Negative value means counting dimensions from the back. + + Returns + ======= + shape : Var + Type T1. + Shape of the input tensor + + Notes + ===== + Signature: ``ai.onnx@21::Shape``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` """ - return _Shape( - _Shape.Attributes( - end=AttrInt64.maybe(end, name="end"), - start=AttrInt64(start, name="start"), - ), _Shape.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).shape + return ( + _Shape( + _Shape.Attributes( + end=AttrInt64.maybe(end, name="end"), + start=AttrInt64(start, name="start"), + ), + _Shape.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .shape + ) -def size(data: Var, ) -> Var: +def size( + data: Var, +) -> Var: r""" -Takes a tensor as input and outputs a int64 scalar that equals to the -total number of elements of the input tensor. - -Parameters -========== -data - Type T. - An input tensor. - -Returns -======= -size : Var - Type T1. - Total number of elements of the input tensor - -Notes -===== -Signature: ``ai.onnx@21::Size``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - - T1: `tensor(int64)` + Takes a tensor as input and outputs a int64 scalar that equals to the + total number of elements of the input tensor. + + Parameters + ========== + data + Type T. + An input tensor. + + Returns + ======= + size : Var + Type T1. + Total number of elements of the input tensor + + Notes + ===== + Signature: ``ai.onnx@21::Size``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + - T1: `tensor(int64)` """ - return _Size( - _Size.Attributes( - ), _Size.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).size + return ( + _Size( + _Size.Attributes(), + _Size.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .size + ) -def squeeze(data: Var, axes: Optional[Var] = None, ) -> Var: +def squeeze( + data: Var, + axes: Optional[Var] = None, +) -> Var: r""" -Remove single-dimensional entries from the shape of a tensor. Takes an -input ``axes`` with a list of axes to squeeze. If ``axes`` is not -provided, all the single dimensions will be removed from the shape. If -an axis is selected with shape entry not equal to one, an error is -raised. - -Parameters -========== -data - Type T. - Tensors with at least max(dims) dimensions. -axes - Type tensor(int64). - List of integers indicating the dimensions to squeeze. Negative value - means counting dimensions from the back. Accepted range is [-r, r-1] - where r = rank(data). - -Returns -======= -squeezed : Var - Type T. - Reshaped tensor with same data as input. - -Notes -===== -Signature: ``ai.onnx@21::Squeeze``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Remove single-dimensional entries from the shape of a tensor. Takes an + input ``axes`` with a list of axes to squeeze. If ``axes`` is not + provided, all the single dimensions will be removed from the shape. If + an axis is selected with shape entry not equal to one, an error is + raised. + + Parameters + ========== + data + Type T. + Tensors with at least max(dims) dimensions. + axes + Type tensor(int64). + List of integers indicating the dimensions to squeeze. Negative value + means counting dimensions from the back. Accepted range is [-r, r-1] + where r = rank(data). + + Returns + ======= + squeezed : Var + Type T. + Reshaped tensor with same data as input. + + Notes + ===== + Signature: ``ai.onnx@21::Squeeze``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Squeeze( - _Squeeze.Attributes( - ), _Squeeze.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).squeezed + return ( + _Squeeze( + _Squeeze.Attributes(), + _Squeeze.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .squeezed + ) -def transpose(data: Var, *, perm: Optional[Iterable[int]] = None, ) -> Var: +def transpose( + data: Var, + *, + perm: Optional[Iterable[int]] = None, +) -> Var: r""" -Transpose the input tensor similar to numpy.transpose. For example, when -perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output -shape will be (2, 1, 3). - -Parameters -========== -data - Type T. - An input tensor. -perm - Attribute. - A list of integers. By default, reverse the dimensions, otherwise - permute the axes according to the values given. Its length must be equal - to the rank of the input. - -Returns -======= -transposed : Var - Type T. - Transposed output. - -Notes -===== -Signature: ``ai.onnx@21::Transpose``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Transpose the input tensor similar to numpy.transpose. For example, when + perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output + shape will be (2, 1, 3). + + Parameters + ========== + data + Type T. + An input tensor. + perm + Attribute. + A list of integers. By default, reverse the dimensions, otherwise + permute the axes according to the values given. Its length must be equal + to the rank of the input. + + Returns + ======= + transposed : Var + Type T. + Transposed output. + + Notes + ===== + Signature: ``ai.onnx@21::Transpose``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Transpose( - _Transpose.Attributes( - perm=AttrInt64s.maybe(perm, name="perm"), - ), _Transpose.Inputs( - data=unwrap_vars(data), ), ).get_output_vars( - data=get_value(data), ).transposed + return ( + _Transpose( + _Transpose.Attributes( + perm=AttrInt64s.maybe(perm, name="perm"), + ), + _Transpose.Inputs( + data=unwrap_vars(data), + ), + ) + .get_output_vars( + data=get_value(data), + ) + .transposed + ) -def unsqueeze(data: Var, axes: Var, ) -> Var: +def unsqueeze( + data: Var, + axes: Var, +) -> Var: r""" -Insert single-dimensional entries to the shape of an input tensor -(``data``). Takes one required input ``axes`` - which contains a list of -dimension indices and this operator will insert a dimension of value -``1`` into the corresponding index of the output tensor (``expanded``). - -For example, given an input tensor (``data``) of shape [3, 4, 5], then -Unsqueeze(data, axes=[0, 4]) outputs a tensor (``expanded``) containing -same data as ``data`` but with shape [1, 3, 4, 5, 1]. - -The input ``axes`` should not contain any duplicate entries. It is an -error if it contains duplicates. The rank of the output tensor -(``output_rank``) is the rank of the input tensor (``data``) plus the -number of values in ``axes``. Each value in ``axes`` should be within -the (inclusive) range [-output_rank , output_rank - 1]. The order of -values in ``axes`` does not matter and can come in any order. - -Parameters -========== -data - Type T. - Original tensor -axes - Type tensor(int64). - List of integers indicating the dimensions to be inserted. Negative - value means counting dimensions from the back. Accepted range is [-r, - r-1] where r = rank(expanded). - -Returns -======= -expanded : Var - Type T. - Reshaped tensor with same data as input. - -Notes -===== -Signature: ``ai.onnx@21::Unsqueeze``. - -Type constraints: - - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` + Insert single-dimensional entries to the shape of an input tensor + (``data``). Takes one required input ``axes`` - which contains a list of + dimension indices and this operator will insert a dimension of value + ``1`` into the corresponding index of the output tensor (``expanded``). + + For example, given an input tensor (``data``) of shape [3, 4, 5], then + Unsqueeze(data, axes=[0, 4]) outputs a tensor (``expanded``) containing + same data as ``data`` but with shape [1, 3, 4, 5, 1]. + + The input ``axes`` should not contain any duplicate entries. It is an + error if it contains duplicates. The rank of the output tensor + (``output_rank``) is the rank of the input tensor (``data``) plus the + number of values in ``axes``. Each value in ``axes`` should be within + the (inclusive) range [-output_rank , output_rank - 1]. The order of + values in ``axes`` does not matter and can come in any order. + + Parameters + ========== + data + Type T. + Original tensor + axes + Type tensor(int64). + List of integers indicating the dimensions to be inserted. Negative + value means counting dimensions from the back. Accepted range is [-r, + r-1] where r = rank(expanded). + + Returns + ======= + expanded : Var + Type T. + Reshaped tensor with same data as input. + + Notes + ===== + Signature: ``ai.onnx@21::Unsqueeze``. + + Type constraints: + - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - return _Unsqueeze( - _Unsqueeze.Attributes( - ), _Unsqueeze.Inputs( - data=unwrap_vars(data), axes=unwrap_vars(axes), ), ).get_output_vars( - data=get_value(data), axes=get_value(axes), ).expanded + return ( + _Unsqueeze( + _Unsqueeze.Attributes(), + _Unsqueeze.Inputs( + data=unwrap_vars(data), + axes=unwrap_vars(axes), + ), + ) + .get_output_vars( + data=get_value(data), + axes=get_value(axes), + ) + .expanded + ) def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: @@ -2635,4 +3154,4 @@ def const(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: "Xor": xor, } -__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] +__all__ = [fun.__name__ for fun in _CONSTRUCTORS.values()] + ["const"] From 50e828b93504c41dd7366c5f8120002ee04c307a Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 6 Nov 2024 01:02:09 +0200 Subject: [PATCH 11/29] Minor fixes and linter --- src/spox/_adapt.py | 6 ++---- src/spox/_fields.py | 6 +++--- src/spox/_function.py | 6 +++--- src/spox/_inline.py | 4 ++-- src/spox/_node.py | 10 +++++----- src/spox/_public.py | 13 ++++++++++++- src/spox/_scope.py | 2 +- src/spox/_standard.py | 15 ++++++++------- src/spox/_var.py | 2 +- src/spox/opset/ai/onnx/v17.py | 9 ++------- tests/test_constructors.py | 5 ++++- tools/generate_opset.py | 2 +- tools/templates/type_inference/loop16-fix.jinja2 | 2 +- 13 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/spox/_adapt.py b/src/spox/_adapt.py index e15ad1c1..8c95b2dc 100644 --- a/src/spox/_adapt.py +++ b/src/spox/_adapt.py @@ -33,15 +33,14 @@ def adapt_node( var_names[var]: var.unwrap_type()._to_onnx_value_info( var_names[var], _traceback_name=f"adapt-input {key}" ) - for key, var in node.inputs.get_vars().items() + for key, var in node.inputs.get_var_infos().items() } output_info = [ var.unwrap_type()._to_onnx_value_info( var_names[var], _traceback_name=f"adapt-output {key}" ) - for key, var in node.outputs.get_vars().items() + for key, var in node.outputs.get_var_infos().items() ] - initializers = [] except ValueError: return None @@ -51,7 +50,6 @@ def adapt_node( "spox__singleton_adapter_graph", list(input_info.values()), output_info, - initializers, ), opset_imports=[onnx.helper.make_operatorsetid("", source_version)], ) diff --git a/src/spox/_fields.py b/src/spox/_fields.py index e350f965..70245e53 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -47,7 +47,7 @@ def _flatten(self) -> Iterable[tuple[str, Optional[Var]]]: else: yield from ((f"{key}_{i}", v) for i, v in enumerate(value)) - def get_vars(self) -> dict[str, Var]: + def get_var_infos(self) -> dict[str, Var]: """Return a flat mapping by name of all the VarInfos in this object.""" return {key: var for key, var in self._flatten() if var is not None} @@ -136,7 +136,7 @@ def __len__(self) -> int: """Count the number of fields in this object (should be same as declared in the class).""" return sum(1 for _ in self) - def get_vars(self) -> dict[str, VarInfo]: + def get_var_infos(self) -> dict[str, VarInfo]: """Return a flat mapping by name of all the VarInfos in this object.""" return {key: var for key, var in self._flatten() if var is not None} @@ -153,7 +153,7 @@ def fully_typed(self) -> bool: """Check if all stored variables have a concrete type.""" return all( var.type is not None and var.type._is_concrete - for var in self.get_vars().values() + for var in self.get_var_infos().values() ) diff --git a/src/spox/_function.py b/src/spox/_function.py index 57c18f7d..65a8ac4f 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -65,7 +65,7 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: from . import _graph func_args_var = _graph.arguments_dict( - **{name: var.type for name, var in self.inputs.get_vars().items()} + **{name: var.type for name, var in self.inputs.get_var_infos().items()} ) self.func_args = unwrap_vars(func_args_var) @@ -81,12 +81,12 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: self.func_inputs = self.Inputs(**self.func_args) # type: ignore self.func_outputs = self.constructor(self.func_attrs, self.func_inputs) self.func_graph = _graph.results( - **self.func_outputs._propagate_vars(initializers).get_vars() + **self.func_outputs._propagate_vars(initializers).get_var_infos() ).with_arguments(*func_args_var.values()) return { name: var.type - for name, var in self.func_outputs.get_vars().items() + for name, var in self.func_outputs.get_var_infos().items() if var.type } diff --git a/src/spox/_inline.py b/src/spox/_inline.py index 6c0356f3..cec08a10 100644 --- a/src/spox/_inline.py +++ b/src/spox/_inline.py @@ -129,8 +129,8 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: def propagate_values(self, initializers) -> dict[str, _value_prop.PropValueType]: if any( - var_info.type is None or initializers.get(name) is None - for name, var_info in self.inputs.get_vars().items() + var_info.type is None or initializers.get(var_info.name) is None + for var_info in self.model.graph.input ): return {} wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() diff --git a/src/spox/_node.py b/src/spox/_node.py index 06c3a323..071013cc 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -184,7 +184,7 @@ def fmt_input(key, var): return f"{key}: {var.type}" sign = ", ".join( - fmt_input(key, var) for key, var in self.inputs.get_vars().items() + fmt_input(key, var) for key, var in self.inputs.get_var_infos().items() ) sign = f"inputs [{sign}]" shown_attrs = { @@ -230,7 +230,7 @@ def inference(self, infer_types: bool = True, initializers={}): self.infer_output_types(initializers=initializers) if infer_types else {} ) - for key, var in self.outputs.get_vars().items(): + for key, var in self.outputs.get_var_infos().items(): if var.type is None: # If no existing type from init_output_vars # Attempt to use the ones from kwargs, if none then what type inference gave var.type = out_types.get(key) @@ -281,7 +281,7 @@ def _check_concrete_type(self, value_type: Type) -> Optional[str]: return None def _list_types(self, source): - return ((key, var.type) for key, var in source.get_vars().items()) + return ((key, var.type) for key, var in source.get_var_infos().items()) def _init_output_vars(self) -> BaseOutputs: """ @@ -311,12 +311,12 @@ def _init_output_vars(self) -> BaseOutputs: @property def dependencies(self) -> Iterable[VarInfo]: """List of input VarInfos into this Node.""" - return (var for var in self.inputs.get_vars().values()) + return (var for var in self.inputs.get_var_infos().values()) @property def dependents(self) -> Iterable[VarInfo]: """List of output VarInfos from this Node.""" - return (var for var in self.outputs.get_vars().values()) + return (var for var in self.outputs.get_var_infos().values()) @property def incident(self) -> Iterable[VarInfo]: diff --git a/src/spox/_public.py b/src/spox/_public.py index a3b77dab..f29f09b9 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -307,7 +307,18 @@ def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: model=model, ) - return dict(zip(out_names, node.get_output_vars().get_vars().values())) + prop_values = { + name: kwargs[name]._value + for i, name in enumerate(in_names) + if kwargs[name]._value is not None + } + + return dict( + zip( + out_names, + node.get_output_vars(**prop_values).get_var_infos().values(), + ) + ) return inline_inner diff --git a/src/spox/_scope.py b/src/spox/_scope.py index eec96386..c7c9ff53 100644 --- a/src/spox/_scope.py +++ b/src/spox/_scope.py @@ -210,7 +210,7 @@ def update(self, node: Node, prefix: str = "", force: bool = True): """ if force or node not in self.node: self.node[node] = self.node.enum(prefix + node.op_type.identifier) - for field, arr in node.outputs.get_vars().items(): + for field, arr in node.outputs.get_var_infos().items(): if arr._name is None: base = f"{self.node[node]}_{field}" name = self.var.maybe_enum(base) diff --git a/src/spox/_standard.py b/src/spox/_standard.py index 37affd3b..68908050 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -64,10 +64,10 @@ def to_singleton_onnx_model( # Prepare names for the values in scope of the node scope = Scope() scope.node[self] = "_this_" - for key, var in self.inputs.get_vars().items(): + for key, var in self.inputs.get_var_infos().items(): if var not in scope.var: scope.var[var] = key - for key, var in self.outputs.get_vars().items(): + for key, var in self.outputs.get_var_infos().items(): if var not in scope.var: scope.var[var] = key # We inject the evaluated attribute values here and then substitute back @@ -89,7 +89,7 @@ def to_singleton_onnx_model( # Input types input_info = [ var.unwrap_type()._to_onnx_value_info(key) - for key, var in self.inputs.get_vars().items() + for key, var in self.inputs.get_var_infos().items() ] # Output types with placeholder empty TypeProto (or actual type if not using dummies) @@ -99,7 +99,8 @@ def out_value_info(curr_key, curr_var): return curr_var.unwrap_type()._to_onnx_value_info(curr_key) output_info = [ - out_value_info(key, var) for key, var in self.outputs.get_vars().items() + out_value_info(key, var) + for key, var in self.outputs.get_var_infos().items() ] # Initializers, passed in to allow partial data propagation # - used so that operators like Reshape are aware of constant shapes @@ -145,7 +146,7 @@ def out_value_info(curr_key, curr_var): def infer_output_types_onnx(self, initializers={}) -> dict[str, Type]: """Execute type & shape inference with ``onnx.shape_inference.infer_node_outputs``.""" # Check that all (specified) inputs have known types, as otherwise we fail - if any(var.type is None for var in self.inputs.get_vars().values()): + if any(var.type is None for var in self.inputs.get_var_infos().values()): return {} model, _ = self.to_singleton_onnx_model(prop_values=initializers) @@ -180,7 +181,7 @@ def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: # Cannot do propagation when some inputs were not propagated/inferred if any( var_info.type is None or initializers.get(name, None) is None - for name, var_info in self.inputs.get_vars().items() + for name, var_info in self.inputs.get_var_infos().items() ): return {} if next(iter(self.subgraphs), None) is not None: @@ -192,7 +193,7 @@ def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() input_feed = { scope.var[var_info]: wrap_feed(initializers[name]) - for name, var_info in self.inputs.get_vars().items() + for name, var_info in self.inputs.get_var_infos().items() if initializers[name] } diff --git a/src/spox/_var.py b/src/spox/_var.py index cb418d97..fcba2158 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -74,7 +74,7 @@ def _which_output(self) -> Optional[str]: """Return the name of the output field that this var is stored in under ``self._op``.""" if self._op is None: return None - op_outs = self._op.outputs.get_vars() + op_outs = self._op.outputs.get_var_infos() candidates = [key for key, var in op_outs.items() if var is self] return candidates[0] if candidates else None diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index a9b3146b..d3ce4d22 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -1775,12 +1775,12 @@ class Outputs(BaseOutputs): v_final_and_scan_outputs: Sequence[VarInfo] def infer_output_types(self, initializers={}) -> dict[str, Type]: - output_types = super().infer_output_types(initializers) + output_types = super().infer_output_types() body = self.attrs.body.value n = len(body.requested_arguments) - 2 - carried_names = list(self.outputs.get_vars())[:n] + carried_names = list(self.outputs.get_var_infos())[:n] carried_types = [v.type for v in list(body.requested_results.values())[1:][:n]] for name, typ in zip(carried_names, carried_types): @@ -9524,11 +9524,6 @@ def loop( v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, - initializers={ - "M": get_value(M), - "cond": get_value(cond), - "v_initial": get_value(v_initial), - }, ) .get_output_vars( M=get_value(M), diff --git a/tests/test_constructors.py b/tests/test_constructors.py index c36394ae..55f0de1f 100644 --- a/tests/test_constructors.py +++ b/tests/test_constructors.py @@ -34,7 +34,10 @@ def test_variadic_no_input_list_mutation(onnx_helper): ins = [a, b] concat = op.concat(ins, axis=0) ins[1] = b - assert list(concat._op.inputs.get_vars()) == [a, b] + assert list(concat._op.inputs.get_var_infos().values()) == [ + a._var_info, + b._var_info, + ] def test_variadic_no_attr_mutation_array(onnx_helper): diff --git a/tools/generate_opset.py b/tools/generate_opset.py index 7d1a9e95..399a311f 100644 --- a/tools/generate_opset.py +++ b/tools/generate_opset.py @@ -647,7 +647,7 @@ def main( if pre_commit_hooks: print("Running pre-commit hooks to format & verify...") - if False and run_pre_commit_hooks(str(path)).returncode: + if run_pre_commit_hooks(str(path)).returncode: print("Running second pass of pre-commit hooks...") if run_pre_commit_hooks(str(path)).returncode: raise RuntimeError( diff --git a/tools/templates/type_inference/loop16-fix.jinja2 b/tools/templates/type_inference/loop16-fix.jinja2 index 775e9d57..712a7258 100644 --- a/tools/templates/type_inference/loop16-fix.jinja2 +++ b/tools/templates/type_inference/loop16-fix.jinja2 @@ -3,7 +3,7 @@ output_types = super().infer_output_types() body = self.attrs.body.value n = len(body.requested_arguments) - 2 -carried_names = list(self.outputs.get_vars())[:n] +carried_names = list(self.outputs.get_var_infos())[:n] carried_types = [v.type for v in list(body.requested_results.values())[1:][:n]] for name, typ in zip(carried_names, carried_types): From d6b59cad68f5708ee3a6d66918a2e07722c1eb34 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 6 Nov 2024 17:35:11 +0200 Subject: [PATCH 12/29] Change initializers name to input_prop_values --- src/spox/_function.py | 4 +- src/spox/_inline.py | 11 +- src/spox/_internal_op.py | 8 +- src/spox/_node.py | 18 +- src/spox/_public.py | 2 +- src/spox/_standard.py | 22 +- src/spox/opset/ai/onnx/ml/v3.py | 94 ++- src/spox/opset/ai/onnx/ml/v4.py | 4 +- src/spox/opset/ai/onnx/ml/v5.py | 4 +- src/spox/opset/ai/onnx/v17.py | 988 +++++++++++++++++++++---------- src/spox/opset/ai/onnx/v18.py | 156 +++-- src/spox/opset/ai/onnx/v19.py | 108 ++-- src/spox/opset/ai/onnx/v20.py | 66 ++- src/spox/opset/ai/onnx/v21.py | 126 ++-- tests/test_custom_operator.py | 2 +- tests/test_function.py | 2 +- tools/generate_opset.py | 2 +- tools/templates/class.jinja2 | 4 +- tools/templates/construct.jinja2 | 6 +- 19 files changed, 1084 insertions(+), 543 deletions(-) diff --git a/src/spox/_function.py b/src/spox/_function.py index 65a8ac4f..ffc2a1c3 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -61,7 +61,7 @@ def constructor(self, attrs, inputs): f"Function {type(self).__name__} does not implement a constructor." ) - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: from . import _graph func_args_var = _graph.arguments_dict( @@ -81,7 +81,7 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: self.func_inputs = self.Inputs(**self.func_args) # type: ignore self.func_outputs = self.constructor(self.func_attrs, self.func_inputs) self.func_graph = _graph.results( - **self.func_outputs._propagate_vars(initializers).get_var_infos() + **self.func_outputs._propagate_vars(input_prop_values).get_var_infos() ).with_arguments(*func_args_var.values()) return { diff --git a/src/spox/_inline.py b/src/spox/_inline.py index cec08a10..4dd8e7a8 100644 --- a/src/spox/_inline.py +++ b/src/spox/_inline.py @@ -111,7 +111,7 @@ def opset_req(self) -> set[tuple[str, int]]: ("", INTERNAL_MIN_OPSET) } - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: # First, type check that we match the ModelProto type requirements for i, var in zip(self.graph.input, self.inputs.inputs): if var.type is not None and not ( @@ -127,15 +127,18 @@ def infer_output_types(self, initializers={}) -> dict[str, Type]: for k, o in enumerate(self.graph.output) } - def propagate_values(self, initializers) -> dict[str, _value_prop.PropValueType]: + def propagate_values( + self, input_prop_values={} + ) -> dict[str, _value_prop.PropValueType]: if any( - var_info.type is None or initializers.get(var_info.name) is None + var_info.type is None or input_prop_values.get(var_info.name) is None for var_info in self.model.graph.input ): return {} wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() input_feed = { - i.name: wrap_feed(initializers.get(i.name)) for i in self.model.graph.input + i.name: wrap_feed(input_prop_values.get(i.name)) + for i in self.model.graph.input } output_feed = run(self.model, input_feed) return { diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index cc3bc7a8..b7b68009 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -88,7 +88,7 @@ def post_init(self, **kwargs): if self.attrs.name is not None: self.outputs.arg._rename(self.attrs.name.value) - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: # Output type is based on the value of the type attribute return {"arg": self.attrs.type.value} @@ -121,12 +121,12 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: # Output type is based on the value of the type attribute arr = self.attrs.value.value return {"arg": Tensor(arr.dtype, arr.shape)} - def propagate_values(self, initializers) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: return {"arg": self.attrs.value.value} def update_metadata(self, opset_req, initializers, functions): @@ -161,7 +161,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: return { f"outputs_{i}": arr.type for i, arr in enumerate(self.inputs.inputs) diff --git a/src/spox/_node.py b/src/spox/_node.py index 071013cc..3b821b05 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -95,7 +95,7 @@ def __init__( out_variadic: Optional[int] = None, infer_types: bool = True, validate: bool = True, - initializers={}, + input_prop_values={}, **kwargs, ): """ @@ -127,7 +127,7 @@ def __init__( # As inference functions may access which output vars we initialized (e.g. variadics) # we inject uninitialized vars first self.outputs = self._init_output_vars() - self.inference(infer_types, initializers) + self.inference(infer_types, input_prop_values) else: self.outputs = outputs @@ -207,7 +207,7 @@ def pre_init(self, **kwargs): def post_init(self, **kwargs): """Post-initialization hook. Called at the end of ``__init__`` after other default fields are set.""" - def propagate_values(self, initializers) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: """ Propagate values from inputs, and, if possible, compute values for outputs as well. This method is used to implement ONNX partial data propagation - for example so that @@ -215,7 +215,7 @@ def propagate_values(self, initializers) -> dict[str, PropValueType]: """ return {} - def infer_output_types(self, initializers) -> dict[str, Type]: + def infer_output_types(self, input_prop_values) -> dict[str, Type]: """ Inference routine for output types. Often overriden by inheriting Node types. @@ -223,11 +223,13 @@ def infer_output_types(self, initializers) -> dict[str, Type]: """ return {} - def inference(self, infer_types: bool = True, initializers={}): + def inference(self, infer_types: bool = True, input_prop_values={}): # Type inference routine - call infer_output_types if required # and check if it provides the expected outputs. out_types = ( - self.infer_output_types(initializers=initializers) if infer_types else {} + self.infer_output_types(input_prop_values=input_prop_values) + if infer_types + else {} ) for key, var in self.outputs.get_var_infos().items(): @@ -235,9 +237,9 @@ def inference(self, infer_types: bool = True, initializers={}): # Attempt to use the ones from kwargs, if none then what type inference gave var.type = out_types.get(key) - def get_output_vars(self, flatten_variadic=False, **initializers): + def get_output_vars(self, flatten_variadic=False, input_prop_values={}): # After typing everything, try to get values for outputs - out_values = self.propagate_values(initializers) + out_values = self.propagate_values(input_prop_values) return self.outputs._propagate_vars( out_values, flatten_variadic=flatten_variadic ) diff --git a/src/spox/_public.py b/src/spox/_public.py index f29f09b9..4dfce42a 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -316,7 +316,7 @@ def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: return dict( zip( out_names, - node.get_output_vars(**prop_values).get_var_infos().values(), + node.get_output_vars(prop_values).get_var_infos().values(), ) ) diff --git a/src/spox/_standard.py b/src/spox/_standard.py index 68908050..15ed0bb6 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -143,13 +143,13 @@ def out_value_info(curr_key, curr_var): ) return model, scope - def infer_output_types_onnx(self, initializers={}) -> dict[str, Type]: + def infer_output_types_onnx(self, input_prop_values={}) -> dict[str, Type]: """Execute type & shape inference with ``onnx.shape_inference.infer_node_outputs``.""" # Check that all (specified) inputs have known types, as otherwise we fail if any(var.type is None for var in self.inputs.get_var_infos().values()): return {} - model, _ = self.to_singleton_onnx_model(prop_values=initializers) + model, _ = self.to_singleton_onnx_model(prop_values=input_prop_values) # Attempt to do shape inference - if an error is caught, we extend the traceback a bit try: @@ -173,14 +173,14 @@ def infer_output_types_onnx(self, initializers={}) -> dict[str, Type]: for key, type_ in results.items() } - def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: + def propagate_values_onnx(self, input_prop_values) -> dict[str, PropValueType]: """Perform value propagation by evaluating singleton model. The backend used for the propagation can be configured with the `spox._standard.ValuePropBackend` variable. """ # Cannot do propagation when some inputs were not propagated/inferred if any( - var_info.type is None or initializers.get(name, None) is None + var_info.type is None or input_prop_values.get(name, None) is None for name, var_info in self.inputs.get_var_infos().items() ): return {} @@ -188,13 +188,13 @@ def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: # Cannot do propagation with subgraphs implicitly for performance - should be reimplemented return {} model, scope = self.to_singleton_onnx_model( - with_dummy_subgraphs=False, prop_values=initializers + with_dummy_subgraphs=False, prop_values=input_prop_values ) wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() input_feed = { - scope.var[var_info]: wrap_feed(initializers[name]) + scope.var[var_info]: wrap_feed(input_prop_values[name]) for name, var_info in self.inputs.get_var_infos().items() - if initializers[name] + if input_prop_values[name] } output_feed = run(model, input_feed) @@ -207,12 +207,12 @@ def propagate_values_onnx(self, initializers) -> dict[str, PropValueType]: } return {k: v for k, v in results.items() if k is not None} - def infer_output_types(self, initializers={}) -> dict[str, Type]: - return self.infer_output_types_onnx(initializers) + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + return self.infer_output_types_onnx(input_prop_values) - def propagate_values(self, initializers) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: if _value_prop._VALUE_PROP_BACKEND != _value_prop.ValuePropBackend.NONE: - return self.propagate_values_onnx(initializers) + return self.propagate_values_onnx(input_prop_values) return {} diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index 536abd53..929971d0 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -40,7 +40,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Z: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} xt, yt = self.inputs.X.unwrap_tensor(), self.inputs.Y.unwrap_tensor() @@ -75,7 +75,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {} op_type = OpType("Binarizer", "ai.onnx.ml", 1) @@ -123,7 +123,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} cats1, cats2 = self.attrs.cats_int64s, self.attrs.cats_strings @@ -199,7 +199,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} t = self.inputs.X.unwrap_tensor() @@ -311,7 +311,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} sim = self.inputs.X.unwrap_tensor().shape @@ -345,7 +345,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: if self.attrs.norm.value not in ("MAX", "L1", "L2"): raise InferenceError( f"Unknown normalisation method `{self.attrs.norm.value}`" @@ -374,7 +374,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: if not self.inputs.fully_typed: return {} if self.attrs.cats_int64s: @@ -467,7 +467,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: if self.inputs.X.type is None: return {} sc, off = self.attrs.scale, self.attrs.offset @@ -527,7 +527,7 @@ class Outputs(BaseOutputs): Y: VarInfo Z: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: e = ( len(self.attrs.class_ids.value) if self.attrs.class_ids is not None @@ -591,7 +591,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: if self.inputs.fully_typed: shape = self.inputs.X.unwrap_tensor().shape assert shape is not None # already checked with fully_typed @@ -671,8 +671,10 @@ def array_feature_extractor( ), ) .get_output_vars( - X=get_value(X), - Y=get_value(Y), + input_prop_values={ + "X": get_value(X), + "Y": get_value(Y), + } ) .Z ) @@ -719,7 +721,9 @@ def binarizer( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -784,7 +788,9 @@ def cast_map( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -858,7 +864,9 @@ def category_mapper( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -929,7 +937,9 @@ def dict_vectorizer( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -981,7 +991,9 @@ def feature_vectorizer( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1063,7 +1075,9 @@ def imputer( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1167,7 +1181,9 @@ def label_encoder( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1249,7 +1265,9 @@ def linear_classifier( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) ._unpack_to_any() ) @@ -1317,7 +1335,9 @@ def linear_regressor( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1369,7 +1389,9 @@ def normalizer( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1436,7 +1458,9 @@ def one_hot_encoder( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1552,7 +1576,9 @@ def svmclassifier( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) ._unpack_to_any() ) @@ -1638,7 +1664,9 @@ def svmregressor( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1694,7 +1722,9 @@ def scaler( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1887,7 +1917,9 @@ def tree_ensemble_classifier( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) ._unpack_to_any() ) @@ -2078,7 +2110,9 @@ def tree_ensemble_regressor( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -2139,7 +2173,9 @@ def zip_map( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Z ) diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index 2e4871c8..e0dd5a1b 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -212,7 +212,9 @@ def label_encoder( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index c35f6c9a..7eab3ef1 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -260,7 +260,9 @@ def tree_ensemble( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index d3ce4d22..15a1ac90 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -494,7 +494,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): output: VarInfo - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: self.infer_output_types_onnx() inp, cond = ( self.inputs.input.unwrap_tensor(), @@ -585,7 +585,7 @@ class Attributes(BaseAttributes): class Outputs(BaseOutputs): output: VarInfo - def propagate_values(self, initializers) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -1774,7 +1774,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): v_final_and_scan_outputs: Sequence[VarInfo] - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: output_types = super().infer_output_types() body = self.attrs.body.value @@ -3966,7 +3966,9 @@ def abs( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -4006,7 +4008,9 @@ def acos( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -4047,7 +4051,9 @@ def acosh( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -4099,8 +4105,10 @@ def add( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -4151,8 +4159,10 @@ def and_( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -4220,7 +4230,9 @@ def arg_max( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -4288,7 +4300,9 @@ def arg_min( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -4328,7 +4342,9 @@ def asin( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -4368,7 +4384,9 @@ def asinh( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -4408,7 +4426,9 @@ def atan( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -4449,7 +4469,9 @@ def atanh( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -4593,7 +4615,9 @@ def average_pool( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -4735,11 +4759,13 @@ def batch_normalization( ), ) .get_output_vars( - X=get_value(X), - scale=get_value(scale), - B=get_value(B), - input_mean=get_value(input_mean), - input_var=get_value(input_var), + input_prop_values={ + "X": get_value(X), + "scale": get_value(scale), + "B": get_value(B), + "input_mean": get_value(input_mean), + "input_var": get_value(input_var), + } ) ._unpack_to_any() ) @@ -4801,7 +4827,9 @@ def bernoulli( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -4868,8 +4896,10 @@ def bit_shift( ), ) .get_output_vars( - X=get_value(X), - Y=get_value(Y), + input_prop_values={ + "X": get_value(X), + "Y": get_value(Y), + } ) .Z ) @@ -4927,7 +4957,9 @@ def blackman_window( ), ) .get_output_vars( - size=get_value(size), + input_prop_values={ + "size": get_value(size), + } ) .output ) @@ -5025,7 +5057,9 @@ def cast( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -5074,8 +5108,10 @@ def cast_like( ), ) .get_output_vars( - input=get_value(input), - target_type=get_value(target_type), + input_prop_values={ + "input": get_value(input), + "target_type": get_value(target_type), + } ) .output ) @@ -5117,7 +5153,9 @@ def ceil( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -5169,7 +5207,9 @@ def celu( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -5222,9 +5262,11 @@ def clip( ), ) .get_output_vars( - input=get_value(input), - min=get_value(min), - max=get_value(max), + input_prop_values={ + "input": get_value(input), + "min": get_value(min), + "max": get_value(max), + } ) .output ) @@ -5287,8 +5329,10 @@ def compress( ), ) .get_output_vars( - input=get_value(input), - condition=get_value(condition), + input_prop_values={ + "input": get_value(input), + "condition": get_value(condition), + } ) .output ) @@ -5337,7 +5381,9 @@ def concat( ), ) .get_output_vars( - inputs=get_value(inputs), + input_prop_values={ + "inputs": get_value(inputs), + } ) .concat_result ) @@ -5396,7 +5442,9 @@ def concat_from_sequence( ), ) .get_output_vars( - input_sequence=get_value(input_sequence), + input_prop_values={ + "input_sequence": get_value(input_sequence), + } ) .concat_result ) @@ -5470,7 +5518,7 @@ def constant( ), _Constant.Inputs(), ) - .get_output_vars() + .get_output_vars(input_prop_values={}) .output ) @@ -5522,7 +5570,9 @@ def constant_of_shape( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -5642,9 +5692,11 @@ def conv( ), ) .get_output_vars( - X=get_value(X), - W=get_value(W), - B=get_value(B), + input_prop_values={ + "X": get_value(X), + "W": get_value(W), + "B": get_value(B), + } ) .Y ) @@ -5776,10 +5828,12 @@ def conv_integer( ), ) .get_output_vars( - x=get_value(x), - w=get_value(w), - x_zero_point=get_value(x_zero_point), - w_zero_point=get_value(w_zero_point), + input_prop_values={ + "x": get_value(x), + "w": get_value(w), + "x_zero_point": get_value(x_zero_point), + "w_zero_point": get_value(w_zero_point), + } ) .y ) @@ -5932,9 +5986,11 @@ def conv_transpose( ), ) .get_output_vars( - X=get_value(X), - W=get_value(W), - B=get_value(B), + input_prop_values={ + "X": get_value(X), + "W": get_value(W), + "B": get_value(B), + } ) .Y ) @@ -5973,7 +6029,9 @@ def cos( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -6012,7 +6070,9 @@ def cosh( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -6095,8 +6155,10 @@ def cumsum( ), ) .get_output_vars( - x=get_value(x), - axis=get_value(axis), + input_prop_values={ + "x": get_value(x), + "axis": get_value(axis), + } ) .y ) @@ -6188,8 +6250,10 @@ def dft( ), ) .get_output_vars( - input=get_value(input), - dft_length=get_value(dft_length), + input_prop_values={ + "input": get_value(input), + "dft_length": get_value(dft_length), + } ) .output ) @@ -6268,7 +6332,9 @@ def depth_to_space( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -6336,9 +6402,11 @@ def dequantize_linear( ), ) .get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), + input_prop_values={ + "x": get_value(x), + "x_scale": get_value(x_scale), + "x_zero_point": get_value(x_zero_point), + } ) .y ) @@ -6382,7 +6450,9 @@ def det( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -6434,8 +6504,10 @@ def div( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -6529,9 +6601,11 @@ def dropout( ), ) .get_output_vars( - data=get_value(data), - ratio=get_value(ratio), - training_mode=get_value(training_mode), + input_prop_values={ + "data": get_value(data), + "ratio": get_value(ratio), + "training_mode": get_value(training_mode), + } ) ._unpack_to_any() ) @@ -6612,7 +6686,9 @@ def dynamic_quantize_linear( ), ) .get_output_vars( - x=get_value(x), + input_prop_values={ + "x": get_value(x), + } ) ._unpack_to_any() ) @@ -6690,7 +6766,9 @@ def einsum( ), ) .get_output_vars( - Inputs=get_value(Inputs), + input_prop_values={ + "Inputs": get_value(Inputs), + } ) .Output ) @@ -6739,7 +6817,9 @@ def elu( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -6790,8 +6870,10 @@ def equal( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -6831,7 +6913,9 @@ def erf( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -6870,7 +6954,9 @@ def exp( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -6923,8 +7009,10 @@ def expand( ), ) .get_output_vars( - input=get_value(input), - shape=get_value(shape), + input_prop_values={ + "input": get_value(input), + "shape": get_value(shape), + } ) .output ) @@ -6989,7 +7077,9 @@ def eye_like( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -7044,7 +7134,9 @@ def flatten( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -7086,7 +7178,9 @@ def floor( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -7292,12 +7386,14 @@ def gru( ), ) .get_output_vars( - X=get_value(X), - W=get_value(W), - R=get_value(R), - B=get_value(B), - sequence_lens=get_value(sequence_lens), - initial_h=get_value(initial_h), + input_prop_values={ + "X": get_value(X), + "W": get_value(W), + "R": get_value(R), + "B": get_value(B), + "sequence_lens": get_value(sequence_lens), + "initial_h": get_value(initial_h), + } ) ._unpack_to_any() ) @@ -7400,8 +7496,10 @@ def gather( ), ) .get_output_vars( - data=get_value(data), - indices=get_value(indices), + input_prop_values={ + "data": get_value(data), + "indices": get_value(indices), + } ) .output ) @@ -7512,8 +7610,10 @@ def gather_elements( ), ) .get_output_vars( - data=get_value(data), - indices=get_value(indices), + input_prop_values={ + "data": get_value(data), + "indices": get_value(indices), + } ) .output ) @@ -7669,8 +7769,10 @@ def gather_nd( ), ) .get_output_vars( - data=get_value(data), - indices=get_value(indices), + input_prop_values={ + "data": get_value(data), + "indices": get_value(indices), + } ) .output ) @@ -7764,9 +7866,11 @@ def gemm( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), - C=get_value(C), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + "C": get_value(C), + } ) .Y ) @@ -7814,7 +7918,9 @@ def global_average_pool( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -7869,7 +7975,9 @@ def global_lp_pool( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -7917,7 +8025,9 @@ def global_max_pool( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -7968,8 +8078,10 @@ def greater( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -8020,8 +8132,10 @@ def greater_or_equal( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -8122,8 +8236,10 @@ def grid_sample( ), ) .get_output_vars( - X=get_value(X), - grid=get_value(grid), + input_prop_values={ + "X": get_value(X), + "grid": get_value(grid), + } ) .Y ) @@ -8181,7 +8297,9 @@ def hamming_window( ), ) .get_output_vars( - size=get_value(size), + input_prop_values={ + "size": get_value(size), + } ) .output ) @@ -8239,7 +8357,9 @@ def hann_window( ), ) .get_output_vars( - size=get_value(size), + input_prop_values={ + "size": get_value(size), + } ) .output ) @@ -8292,7 +8412,9 @@ def hard_sigmoid( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -8334,7 +8456,9 @@ def hard_swish( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -8389,7 +8513,9 @@ def hardmax( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -8428,7 +8554,9 @@ def identity( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -8500,7 +8628,9 @@ def if_( out_variadic=len(_else_branch_subgraph.requested_results), ) .get_output_vars( - cond=get_value(cond), + input_prop_values={ + "cond": get_value(cond), + } ) .outputs ) @@ -8564,9 +8694,11 @@ def instance_normalization( ), ) .get_output_vars( - input=get_value(input), - scale=get_value(scale), - B=get_value(B), + input_prop_values={ + "input": get_value(input), + "scale": get_value(scale), + "B": get_value(B), + } ) .output ) @@ -8622,7 +8754,9 @@ def isinf( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -8662,7 +8796,9 @@ def isnan( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -8740,7 +8876,9 @@ def lrn( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -8968,14 +9106,16 @@ def lstm( ), ) .get_output_vars( - X=get_value(X), - W=get_value(W), - R=get_value(R), - B=get_value(B), - sequence_lens=get_value(sequence_lens), - initial_h=get_value(initial_h), - initial_c=get_value(initial_c), - P=get_value(P), + input_prop_values={ + "X": get_value(X), + "W": get_value(W), + "R": get_value(R), + "B": get_value(B), + "sequence_lens": get_value(sequence_lens), + "initial_h": get_value(initial_h), + "initial_c": get_value(initial_c), + "P": get_value(P), + } ) ._unpack_to_any() ) @@ -9078,9 +9218,11 @@ def layer_normalization( ), ) .get_output_vars( - X=get_value(X), - Scale=get_value(Scale), - B=get_value(B), + input_prop_values={ + "X": get_value(X), + "Scale": get_value(Scale), + "B": get_value(B), + } ) ._unpack_to_any() ) @@ -9129,7 +9271,9 @@ def leaky_relu( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -9180,8 +9324,10 @@ def less( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -9232,8 +9378,10 @@ def less_or_equal( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -9272,7 +9420,9 @@ def log( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -9326,7 +9476,9 @@ def log_softmax( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -9526,9 +9678,11 @@ def loop( out_variadic=len(_body_subgraph.requested_results) - 1, ) .get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), + input_prop_values={ + "M": get_value(M), + "cond": get_value(cond), + "v_initial": get_value(v_initial), + } ) .v_final_and_scan_outputs ) @@ -9579,7 +9733,9 @@ def lp_normalization( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -9670,7 +9826,9 @@ def lp_pool( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -9715,8 +9873,10 @@ def matmul( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .Y ) @@ -9785,10 +9945,12 @@ def matmul_integer( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), - a_zero_point=get_value(a_zero_point), - b_zero_point=get_value(b_zero_point), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + "a_zero_point": get_value(a_zero_point), + "b_zero_point": get_value(b_zero_point), + } ) .Y ) @@ -9831,7 +9993,9 @@ def max( ), ) .get_output_vars( - data_0=get_value(data_0), + input_prop_values={ + "data_0": get_value(data_0), + } ) .max ) @@ -9990,7 +10154,9 @@ def max_pool( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) ._unpack_to_any() ) @@ -10053,8 +10219,10 @@ def max_roi_pool( ), ) .get_output_vars( - X=get_value(X), - rois=get_value(rois), + input_prop_values={ + "X": get_value(X), + "rois": get_value(rois), + } ) .Y ) @@ -10170,9 +10338,11 @@ def max_unpool( ), ) .get_output_vars( - X=get_value(X), - I=get_value(I), - output_shape=get_value(output_shape), + input_prop_values={ + "X": get_value(X), + "I": get_value(I), + "output_shape": get_value(output_shape), + } ) .output ) @@ -10215,7 +10385,9 @@ def mean( ), ) .get_output_vars( - data_0=get_value(data_0), + input_prop_values={ + "data_0": get_value(data_0), + } ) .mean ) @@ -10266,7 +10438,9 @@ def mean_variance_normalization( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -10360,11 +10534,13 @@ def mel_weight_matrix( ), ) .get_output_vars( - num_mel_bins=get_value(num_mel_bins), - dft_length=get_value(dft_length), - sample_rate=get_value(sample_rate), - lower_edge_hertz=get_value(lower_edge_hertz), - upper_edge_hertz=get_value(upper_edge_hertz), + input_prop_values={ + "num_mel_bins": get_value(num_mel_bins), + "dft_length": get_value(dft_length), + "sample_rate": get_value(sample_rate), + "lower_edge_hertz": get_value(lower_edge_hertz), + "upper_edge_hertz": get_value(upper_edge_hertz), + } ) .output ) @@ -10407,7 +10583,9 @@ def min( ), ) .get_output_vars( - data_0=get_value(data_0), + input_prop_values={ + "data_0": get_value(data_0), + } ) .min ) @@ -10476,8 +10654,10 @@ def mod( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -10529,8 +10709,10 @@ def mul( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -10595,7 +10777,9 @@ def multinomial( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -10636,7 +10820,9 @@ def neg( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -10812,9 +10998,11 @@ def negative_log_likelihood_loss( ), ) .get_output_vars( - input=get_value(input), - target=get_value(target), - weight=get_value(weight), + input_prop_values={ + "input": get_value(input), + "target": get_value(target), + "weight": get_value(weight), + } ) .loss ) @@ -10900,11 +11088,13 @@ def non_max_suppression( ), ) .get_output_vars( - boxes=get_value(boxes), - scores=get_value(scores), - max_output_boxes_per_class=get_value(max_output_boxes_per_class), - iou_threshold=get_value(iou_threshold), - score_threshold=get_value(score_threshold), + input_prop_values={ + "boxes": get_value(boxes), + "scores": get_value(scores), + "max_output_boxes_per_class": get_value(max_output_boxes_per_class), + "iou_threshold": get_value(iou_threshold), + "score_threshold": get_value(score_threshold), + } ) .selected_indices ) @@ -10947,7 +11137,9 @@ def non_zero( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -10986,7 +11178,9 @@ def not_( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -11085,9 +11279,11 @@ def one_hot( ), ) .get_output_vars( - indices=get_value(indices), - depth=get_value(depth), - values=get_value(values), + input_prop_values={ + "indices": get_value(indices), + "depth": get_value(depth), + "values": get_value(values), + } ) .output ) @@ -11136,7 +11332,9 @@ def optional( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -11178,7 +11376,9 @@ def optional_get_element( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -11220,7 +11420,9 @@ def optional_has_element( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -11271,8 +11473,10 @@ def or_( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -11323,8 +11527,10 @@ def prelu( ), ) .get_output_vars( - X=get_value(X), - slope=get_value(slope), + input_prop_values={ + "X": get_value(X), + "slope": get_value(slope), + } ) .Y ) @@ -11436,9 +11642,11 @@ def pad( ), ) .get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), + input_prop_values={ + "data": get_value(data), + "pads": get_value(pads), + "constant_value": get_value(constant_value), + } ) .output ) @@ -11488,8 +11696,10 @@ def pow( ), ) .get_output_vars( - X=get_value(X), - Y=get_value(Y), + input_prop_values={ + "X": get_value(X), + "Y": get_value(Y), + } ) .Z ) @@ -11658,15 +11868,17 @@ def qlinear_conv( ), ) .get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), - w=get_value(w), - w_scale=get_value(w_scale), - w_zero_point=get_value(w_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), - B=get_value(B), + input_prop_values={ + "x": get_value(x), + "x_scale": get_value(x_scale), + "x_zero_point": get_value(x_zero_point), + "w": get_value(w), + "w_scale": get_value(w_scale), + "w_zero_point": get_value(w_zero_point), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + "B": get_value(B), + } ) .y ) @@ -11759,14 +11971,16 @@ def qlinear_matmul( ), ) .get_output_vars( - a=get_value(a), - a_scale=get_value(a_scale), - a_zero_point=get_value(a_zero_point), - b=get_value(b), - b_scale=get_value(b_scale), - b_zero_point=get_value(b_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), + input_prop_values={ + "a": get_value(a), + "a_scale": get_value(a_scale), + "a_zero_point": get_value(a_zero_point), + "b": get_value(b), + "b_scale": get_value(b_scale), + "b_zero_point": get_value(b_zero_point), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } ) .y ) @@ -11838,9 +12052,11 @@ def quantize_linear( ), ) .get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), + input_prop_values={ + "x": get_value(x), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } ) .y ) @@ -12023,12 +12239,14 @@ def rnn( ), ) .get_output_vars( - X=get_value(X), - W=get_value(W), - R=get_value(R), - B=get_value(B), - sequence_lens=get_value(sequence_lens), - initial_h=get_value(initial_h), + input_prop_values={ + "X": get_value(X), + "W": get_value(W), + "R": get_value(R), + "B": get_value(B), + "sequence_lens": get_value(sequence_lens), + "initial_h": get_value(initial_h), + } ) ._unpack_to_any() ) @@ -12096,7 +12314,7 @@ def random_normal( ), _RandomNormal.Inputs(), ) - .get_output_vars() + .get_output_vars(input_prop_values={}) .output ) @@ -12167,7 +12385,9 @@ def random_normal_like( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -12234,7 +12454,7 @@ def random_uniform( ), _RandomUniform.Inputs(), ) - .get_output_vars() + .get_output_vars(input_prop_values={}) .output ) @@ -12305,7 +12525,9 @@ def random_uniform_like( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -12385,9 +12607,11 @@ def range( ), ) .get_output_vars( - start=get_value(start), - limit=get_value(limit), - delta=get_value(delta), + input_prop_values={ + "start": get_value(start), + "limit": get_value(limit), + "delta": get_value(delta), + } ) .output ) @@ -12428,7 +12652,9 @@ def reciprocal( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -12489,7 +12715,9 @@ def reduce_l1( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -12550,7 +12778,9 @@ def reduce_l2( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -12612,7 +12842,9 @@ def reduce_log_sum( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -12674,7 +12906,9 @@ def reduce_log_sum_exp( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -12737,7 +12971,9 @@ def reduce_max( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -12798,7 +13034,9 @@ def reduce_mean( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -12860,7 +13098,9 @@ def reduce_min( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -12921,7 +13161,9 @@ def reduce_prod( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -12994,8 +13236,10 @@ def reduce_sum( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -13056,7 +13300,9 @@ def reduce_sum_square( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .reduced ) @@ -13097,7 +13343,9 @@ def relu( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -13165,8 +13413,10 @@ def reshape( ), ) .get_output_vars( - data=get_value(data), - shape=get_value(shape), + input_prop_values={ + "data": get_value(data), + "shape": get_value(shape), + } ) .reshaped ) @@ -13314,10 +13564,12 @@ def resize( ), ) .get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), + input_prop_values={ + "X": get_value(X), + "roi": get_value(roi), + "scales": get_value(scales), + "sizes": get_value(sizes), + } ) .Y ) @@ -13397,8 +13649,10 @@ def reverse_sequence( ), ) .get_output_vars( - input=get_value(input), - sequence_lens=get_value(sequence_lens), + input_prop_values={ + "input": get_value(input), + "sequence_lens": get_value(sequence_lens), + } ) .Y ) @@ -13511,9 +13765,11 @@ def roi_align( ), ) .get_output_vars( - X=get_value(X), - rois=get_value(rois), - batch_indices=get_value(batch_indices), + input_prop_values={ + "X": get_value(X), + "rois": get_value(rois), + "batch_indices": get_value(batch_indices), + } ) .Y ) @@ -13566,7 +13822,9 @@ def round( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -13646,10 +13904,12 @@ def stft( ), ) .get_output_vars( - signal=get_value(signal), - frame_step=get_value(frame_step), - window=get_value(window), - frame_length=get_value(frame_length), + input_prop_values={ + "signal": get_value(signal), + "frame_step": get_value(frame_step), + "window": get_value(window), + "frame_length": get_value(frame_length), + } ) .output ) @@ -13902,7 +14162,11 @@ def scan( out_variadic=len(_body_subgraph.requested_results), ) .get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + input_prop_values={ + "initial_state_and_scan_inputs": get_value( + initial_state_and_scan_inputs + ), + } ) .final_state_and_scan_outputs ) @@ -14041,9 +14305,11 @@ def scatter_elements( ), ) .get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), + input_prop_values={ + "data": get_value(data), + "indices": get_value(indices), + "updates": get_value(updates), + } ) .output ) @@ -14170,9 +14436,11 @@ def scatter_nd( ), ) .get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), + input_prop_values={ + "data": get_value(data), + "indices": get_value(indices), + "updates": get_value(updates), + } ) .output ) @@ -14228,7 +14496,9 @@ def selu( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -14281,8 +14551,10 @@ def sequence_at( ), ) .get_output_vars( - input_sequence=get_value(input_sequence), - position=get_value(position), + input_prop_values={ + "input_sequence": get_value(input_sequence), + "position": get_value(position), + } ) .tensor ) @@ -14323,7 +14595,9 @@ def sequence_construct( ), ) .get_output_vars( - inputs=get_value(inputs), + input_prop_values={ + "inputs": get_value(inputs), + } ) .output_sequence ) @@ -14363,7 +14637,7 @@ def sequence_empty( ), _SequenceEmpty.Inputs(), ) - .get_output_vars() + .get_output_vars(input_prop_values={}) .output ) @@ -14415,8 +14689,10 @@ def sequence_erase( ), ) .get_output_vars( - input_sequence=get_value(input_sequence), - position=get_value(position), + input_prop_values={ + "input_sequence": get_value(input_sequence), + "position": get_value(position), + } ) .output_sequence ) @@ -14477,9 +14753,11 @@ def sequence_insert( ), ) .get_output_vars( - input_sequence=get_value(input_sequence), - tensor=get_value(tensor), - position=get_value(position), + input_prop_values={ + "input_sequence": get_value(input_sequence), + "tensor": get_value(tensor), + "position": get_value(position), + } ) .output_sequence ) @@ -14520,7 +14798,9 @@ def sequence_length( ), ) .get_output_vars( - input_sequence=get_value(input_sequence), + input_prop_values={ + "input_sequence": get_value(input_sequence), + } ) .length ) @@ -14598,8 +14878,10 @@ def sequence_map( out_variadic=len(_body_subgraph.requested_results), ) .get_output_vars( - input_sequence=get_value(input_sequence), - additional_inputs=get_value(additional_inputs), + input_prop_values={ + "input_sequence": get_value(input_sequence), + "additional_inputs": get_value(additional_inputs), + } ) .out_sequence ) @@ -14692,7 +14974,9 @@ def shape( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .shape ) @@ -14746,7 +15030,9 @@ def shrink( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -14787,7 +15073,9 @@ def sigmoid( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -14828,7 +15116,9 @@ def sign( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -14867,7 +15157,9 @@ def sin( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -14906,7 +15198,9 @@ def sinh( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -14947,7 +15241,9 @@ def size( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .size ) @@ -15078,11 +15374,13 @@ def slice( ), ) .get_output_vars( - data=get_value(data), - starts=get_value(starts), - ends=get_value(ends), - axes=get_value(axes), - steps=get_value(steps), + input_prop_values={ + "data": get_value(data), + "starts": get_value(starts), + "ends": get_value(ends), + "axes": get_value(axes), + "steps": get_value(steps), + } ) .output ) @@ -15138,7 +15436,9 @@ def softmax( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -15266,9 +15566,11 @@ def softmax_cross_entropy_loss( ), ) .get_output_vars( - scores=get_value(scores), - labels=get_value(labels), - weights=get_value(weights), + input_prop_values={ + "scores": get_value(scores), + "labels": get_value(labels), + "weights": get_value(weights), + } ) ._unpack_to_any() ) @@ -15309,7 +15611,9 @@ def softplus( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -15350,7 +15654,9 @@ def softsign( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -15400,7 +15706,9 @@ def space_to_depth( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -15460,8 +15768,10 @@ def split( out_variadic=outputs_count, ) .get_output_vars( - input=get_value(input), - split=get_value(split), + input_prop_values={ + "input": get_value(input), + "split": get_value(split), + } ) .outputs ) @@ -15534,8 +15844,10 @@ def split_to_sequence( ), ) .get_output_vars( - input=get_value(input), - split=get_value(split), + input_prop_values={ + "input": get_value(input), + "split": get_value(split), + } ) .output_sequence ) @@ -15576,7 +15888,9 @@ def sqrt( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -15626,8 +15940,10 @@ def squeeze( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .squeezed ) @@ -15702,7 +16018,9 @@ def string_normalizer( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -15754,8 +16072,10 @@ def sub( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -15798,7 +16118,9 @@ def sum( ), ) .get_output_vars( - data_0=get_value(data_0), + input_prop_values={ + "data_0": get_value(data_0), + } ) .sum ) @@ -15837,7 +16159,9 @@ def tan( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -15877,7 +16201,9 @@ def tanh( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -16030,7 +16356,9 @@ def tf_idf_vectorizer( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -16078,7 +16406,9 @@ def thresholded_relu( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -16127,8 +16457,10 @@ def tile( ), ) .get_output_vars( - input=get_value(input), - repeats=get_value(repeats), + input_prop_values={ + "input": get_value(input), + "repeats": get_value(repeats), + } ) .output ) @@ -16222,8 +16554,10 @@ def top_k( ), ) .get_output_vars( - X=get_value(X), - K=get_value(K), + input_prop_values={ + "X": get_value(X), + "K": get_value(K), + } ) ._unpack_to_any() ) @@ -16272,7 +16606,9 @@ def transpose( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .transposed ) @@ -16342,8 +16678,10 @@ def trilu( ), ) .get_output_vars( - input=get_value(input), - k=get_value(k), + input_prop_values={ + "input": get_value(input), + "k": get_value(k), + } ) .output ) @@ -16529,7 +16867,9 @@ def unique( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) ._unpack_to_any() ) @@ -16589,8 +16929,10 @@ def unsqueeze( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .expanded ) @@ -16647,9 +16989,11 @@ def where( ), ) .get_output_vars( - condition=get_value(condition), - X=get_value(X), - Y=get_value(Y), + input_prop_values={ + "condition": get_value(condition), + "X": get_value(X), + "Y": get_value(Y), + } ) .output ) @@ -16700,8 +17044,10 @@ def xor( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index f8de6f33..045748dd 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -943,8 +943,10 @@ def bitwise_and( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -983,7 +985,9 @@ def bitwise_not( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1033,8 +1037,10 @@ def bitwise_or( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -1084,8 +1090,10 @@ def bitwise_xor( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -1149,8 +1157,10 @@ def center_crop_pad( ), ) .get_output_vars( - input_data=get_value(input_data), - shape=get_value(shape), + input_prop_values={ + "input_data": get_value(input_data), + "shape": get_value(shape), + } ) .output_data ) @@ -1250,9 +1260,11 @@ def col2_im( ), ) .get_output_vars( - input=get_value(input), - image_shape=get_value(image_shape), - block_shape=get_value(block_shape), + input_prop_values={ + "input": get_value(input), + "image_shape": get_value(image_shape), + "block_shape": get_value(block_shape), + } ) .output ) @@ -1336,9 +1348,11 @@ def group_normalization( ), ) .get_output_vars( - X=get_value(X), - scale=get_value(scale), - bias=get_value(bias), + input_prop_values={ + "X": get_value(X), + "scale": get_value(scale), + "bias": get_value(bias), + } ) .Y ) @@ -1468,7 +1482,9 @@ def lp_pool( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1514,7 +1530,9 @@ def mish( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1557,7 +1575,9 @@ def optional_get_element( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -1600,7 +1620,9 @@ def optional_has_element( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -1753,10 +1775,12 @@ def pad( ), ) .get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "pads": get_value(pads), + "constant_value": get_value(constant_value), + "axes": get_value(axes), + } ) .output ) @@ -1829,8 +1853,10 @@ def reduce_l1( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -1903,8 +1929,10 @@ def reduce_l2( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -1978,8 +2006,10 @@ def reduce_log_sum( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -2053,8 +2083,10 @@ def reduce_log_sum_exp( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -2129,8 +2161,10 @@ def reduce_max( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -2203,8 +2237,10 @@ def reduce_mean( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -2278,8 +2314,10 @@ def reduce_min( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -2352,8 +2390,10 @@ def reduce_prod( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -2426,8 +2466,10 @@ def reduce_sum_square( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -2631,10 +2673,12 @@ def resize( ), ) .get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), + input_prop_values={ + "X": get_value(X), + "roi": get_value(roi), + "scales": get_value(scales), + "sizes": get_value(sizes), + } ) .Y ) @@ -2776,9 +2820,11 @@ def scatter_elements( ), ) .get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), + input_prop_values={ + "data": get_value(data), + "indices": get_value(indices), + "updates": get_value(updates), + } ) .output ) @@ -2921,9 +2967,11 @@ def scatter_nd( ), ) .get_output_vars( - data=get_value(data), - indices=get_value(indices), - updates=get_value(updates), + input_prop_values={ + "data": get_value(data), + "indices": get_value(indices), + "updates": get_value(updates), + } ) .output ) @@ -2989,8 +3037,10 @@ def split( out_variadic=num_outputs, ) .get_output_vars( - input=get_value(input), - split=get_value(split), + input_prop_values={ + "input": get_value(input), + "split": get_value(split), + } ) .outputs ) diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 8fc23f65..1a04da8e 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -456,7 +456,7 @@ class Attributes(BaseAttributes): class Outputs(BaseOutputs): output: VarInfo - def propagate_values(self, initializers) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -934,7 +934,9 @@ def average_pool( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1072,7 +1074,9 @@ def cast( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -1132,8 +1136,10 @@ def cast_like( ), ) .get_output_vars( - input=get_value(input), - target_type=get_value(target_type), + input_prop_values={ + "input": get_value(input), + "target_type": get_value(target_type), + } ) .output ) @@ -1207,7 +1213,7 @@ def constant( ), _Constant.Inputs(), ) - .get_output_vars() + .get_output_vars(input_prop_values={}) .output ) @@ -1327,11 +1333,13 @@ def deform_conv( ), ) .get_output_vars( - X=get_value(X), - W=get_value(W), - offset=get_value(offset), - B=get_value(B), - mask=get_value(mask), + input_prop_values={ + "X": get_value(X), + "W": get_value(W), + "offset": get_value(offset), + "B": get_value(B), + "mask": get_value(mask), + } ) .Y ) @@ -1404,9 +1412,11 @@ def dequantize_linear( ), ) .get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), + input_prop_values={ + "x": get_value(x), + "x_scale": get_value(x_scale), + "x_zero_point": get_value(x_zero_point), + } ) .y ) @@ -1457,8 +1467,10 @@ def equal( ), ) .get_output_vars( - A=get_value(A), - B=get_value(B), + input_prop_values={ + "A": get_value(A), + "B": get_value(B), + } ) .C ) @@ -1497,7 +1509,9 @@ def identity( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -1569,7 +1583,9 @@ def if_( out_variadic=len(_else_branch_subgraph.requested_results), ) .get_output_vars( - cond=get_value(cond), + input_prop_values={ + "cond": get_value(cond), + } ) .outputs ) @@ -1769,9 +1785,11 @@ def loop( out_variadic=len(_body_subgraph.requested_results) - 1, ) .get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), + input_prop_values={ + "M": get_value(M), + "cond": get_value(cond), + "v_initial": get_value(v_initial), + } ) .v_final_and_scan_outputs ) @@ -1950,10 +1968,12 @@ def pad( ), ) .get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "pads": get_value(pads), + "constant_value": get_value(constant_value), + "axes": get_value(axes), + } ) .output ) @@ -2038,9 +2058,11 @@ def quantize_linear( ), ) .get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), + input_prop_values={ + "x": get_value(x), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } ) .y ) @@ -2108,8 +2130,10 @@ def reshape( ), ) .get_output_vars( - data=get_value(data), - shape=get_value(shape), + input_prop_values={ + "data": get_value(data), + "shape": get_value(shape), + } ) .reshaped ) @@ -2351,10 +2375,12 @@ def resize( ), ) .get_output_vars( - X=get_value(X), - roi=get_value(roi), - scales=get_value(scales), - sizes=get_value(sizes), + input_prop_values={ + "X": get_value(X), + "roi": get_value(roi), + "scales": get_value(scales), + "sizes": get_value(sizes), + } ) .Y ) @@ -2607,7 +2633,11 @@ def scan( out_variadic=len(_body_subgraph.requested_results), ) .get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + input_prop_values={ + "initial_state_and_scan_inputs": get_value( + initial_state_and_scan_inputs + ), + } ) .final_state_and_scan_outputs ) @@ -2700,7 +2730,9 @@ def shape( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .shape ) @@ -2741,7 +2773,9 @@ def size( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .size ) diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 0e1d406a..c25ec41c 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -744,8 +744,10 @@ def affine_grid( ), ) .get_output_vars( - theta=get_value(theta), - size=get_value(size), + input_prop_values={ + "theta": get_value(theta), + "size": get_value(size), + } ) .grid ) @@ -798,7 +800,9 @@ def constant_of_shape( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -907,9 +911,11 @@ def dft( ), ) .get_output_vars( - input=get_value(input), - dft_length=get_value(dft_length), - axis=get_value(axis), + input_prop_values={ + "input": get_value(input), + "dft_length": get_value(dft_length), + "axis": get_value(axis), + } ) .output ) @@ -963,7 +969,9 @@ def gelu( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1084,8 +1092,10 @@ def grid_sample( ), ) .get_output_vars( - X=get_value(X), - grid=get_value(grid), + input_prop_values={ + "X": get_value(X), + "grid": get_value(grid), + } ) .Y ) @@ -1159,7 +1169,9 @@ def image_decoder( ), ) .get_output_vars( - encoded_stream=get_value(encoded_stream), + input_prop_values={ + "encoded_stream": get_value(encoded_stream), + } ) .image ) @@ -1215,7 +1227,9 @@ def isinf( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1255,7 +1269,9 @@ def isnan( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1333,8 +1349,10 @@ def reduce_max( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -1411,8 +1429,10 @@ def reduce_min( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .reduced ) @@ -1464,7 +1484,9 @@ def regex_full_match( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) .Y ) @@ -1509,8 +1531,10 @@ def string_concat( ), ) .get_output_vars( - X=get_value(X), - Y=get_value(Y), + input_prop_values={ + "X": get_value(X), + "Y": get_value(Y), + } ) .Z ) @@ -1596,7 +1620,9 @@ def string_split( ), ) .get_output_vars( - X=get_value(X), + input_prop_values={ + "X": get_value(X), + } ) ._unpack_to_any() ) diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 52e3027a..6867ef46 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -436,7 +436,7 @@ class Attributes(BaseAttributes): class Outputs(BaseOutputs): output: VarInfo - def propagate_values(self, initializers) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -975,7 +975,9 @@ def cast( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -1035,8 +1037,10 @@ def cast_like( ), ) .get_output_vars( - input=get_value(input), - target_type=get_value(target_type), + input_prop_values={ + "input": get_value(input), + "target_type": get_value(target_type), + } ) .output ) @@ -1110,7 +1114,7 @@ def constant( ), _Constant.Inputs(), ) - .get_output_vars() + .get_output_vars(input_prop_values={}) .output ) @@ -1162,7 +1166,9 @@ def constant_of_shape( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -1249,9 +1255,11 @@ def dequantize_linear( ), ) .get_output_vars( - x=get_value(x), - x_scale=get_value(x_scale), - x_zero_point=get_value(x_zero_point), + input_prop_values={ + "x": get_value(x), + "x_scale": get_value(x_scale), + "x_zero_point": get_value(x_zero_point), + } ) .y ) @@ -1306,7 +1314,9 @@ def flatten( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -1405,9 +1415,11 @@ def group_normalization( ), ) .get_output_vars( - X=get_value(X), - scale=get_value(scale), - bias=get_value(bias), + input_prop_values={ + "X": get_value(X), + "scale": get_value(scale), + "bias": get_value(bias), + } ) .Y ) @@ -1446,7 +1458,9 @@ def identity( ), ) .get_output_vars( - input=get_value(input), + input_prop_values={ + "input": get_value(input), + } ) .output ) @@ -1518,7 +1532,9 @@ def if_( out_variadic=len(_else_branch_subgraph.requested_results), ) .get_output_vars( - cond=get_value(cond), + input_prop_values={ + "cond": get_value(cond), + } ) .outputs ) @@ -1718,9 +1734,11 @@ def loop( out_variadic=len(_body_subgraph.requested_results) - 1, ) .get_output_vars( - M=get_value(M), - cond=get_value(cond), - v_initial=get_value(v_initial), + input_prop_values={ + "M": get_value(M), + "cond": get_value(cond), + "v_initial": get_value(v_initial), + } ) .v_final_and_scan_outputs ) @@ -1899,10 +1917,12 @@ def pad( ), ) .get_output_vars( - data=get_value(data), - pads=get_value(pads), - constant_value=get_value(constant_value), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "pads": get_value(pads), + "constant_value": get_value(constant_value), + "axes": get_value(axes), + } ) .output ) @@ -1996,14 +2016,16 @@ def qlinear_matmul( ), ) .get_output_vars( - a=get_value(a), - a_scale=get_value(a_scale), - a_zero_point=get_value(a_zero_point), - b=get_value(b), - b_scale=get_value(b_scale), - b_zero_point=get_value(b_zero_point), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), + input_prop_values={ + "a": get_value(a), + "a_scale": get_value(a_scale), + "a_zero_point": get_value(a_zero_point), + "b": get_value(b), + "b_scale": get_value(b_scale), + "b_zero_point": get_value(b_zero_point), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } ) .y ) @@ -2129,9 +2151,11 @@ def quantize_linear( ), ) .get_output_vars( - x=get_value(x), - y_scale=get_value(y_scale), - y_zero_point=get_value(y_zero_point), + input_prop_values={ + "x": get_value(x), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } ) .y ) @@ -2199,8 +2223,10 @@ def reshape( ), ) .get_output_vars( - data=get_value(data), - shape=get_value(shape), + input_prop_values={ + "data": get_value(data), + "shape": get_value(shape), + } ) .reshaped ) @@ -2453,7 +2479,11 @@ def scan( out_variadic=len(_body_subgraph.requested_results), ) .get_output_vars( - initial_state_and_scan_inputs=get_value(initial_state_and_scan_inputs), + input_prop_values={ + "initial_state_and_scan_inputs": get_value( + initial_state_and_scan_inputs + ), + } ) .final_state_and_scan_outputs ) @@ -2546,7 +2576,9 @@ def shape( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .shape ) @@ -2587,7 +2619,9 @@ def size( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .size ) @@ -2637,8 +2671,10 @@ def squeeze( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .squeezed ) @@ -2688,7 +2724,9 @@ def transpose( ), ) .get_output_vars( - data=get_value(data), + input_prop_values={ + "data": get_value(data), + } ) .transposed ) @@ -2748,8 +2786,10 @@ def unsqueeze( ), ) .get_output_vars( - data=get_value(data), - axes=get_value(axes), + input_prop_values={ + "data": get_value(data), + "axes": get_value(axes), + } ) .expanded ) diff --git a/tests/test_custom_operator.py b/tests/test_custom_operator.py index ae149742..f06b1b56 100644 --- a/tests/test_custom_operator.py +++ b/tests/test_custom_operator.py @@ -44,7 +44,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: # This is technically optional, but using an operator without type inference may be inconvenient. if self.inputs.X.type is None: return {} diff --git a/tests/test_function.py b/tests/test_function.py index 7405ede7..aa37790c 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -119,7 +119,7 @@ def linear_inner( ), LinearFunction2.Inputs(x._var_info), ) - .get_output_vars(X=x._value) + .get_output_vars({"X": x._value}) .Y ) diff --git a/tools/generate_opset.py b/tools/generate_opset.py index 399a311f..7d1a9e95 100644 --- a/tools/generate_opset.py +++ b/tools/generate_opset.py @@ -647,7 +647,7 @@ def main( if pre_commit_hooks: print("Running pre-commit hooks to format & verify...") - if run_pre_commit_hooks(str(path)).returncode: + if False and run_pre_commit_hooks(str(path)).returncode: print("Running second pass of pre-commit hooks...") if run_pre_commit_hooks(str(path)).returncode: raise RuntimeError( diff --git a/tools/templates/class.jinja2 b/tools/templates/class.jinja2 index b362e963..7698fd43 100644 --- a/tools/templates/class.jinja2 +++ b/tools/templates/class.jinja2 @@ -47,14 +47,14 @@ class _{{ schema.name }}(StandardNode): {% endif %} {% if type_inference %} - def infer_output_types(self, initializers={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: {% filter indent(width=8) %} {%+ include type_inference %} {% endfilter %} {% endif %} {% if value_propagation %} - def propagate_values(self, initializers) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: {% filter indent(width=8) %} {%+ include value_propagation %} {% endfilter %} diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index e57f6c54..d3cfcb92 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -36,11 +36,11 @@ endfor %} ), {% if schema.outputs and is_variadic(schema.outputs[-1]) %}out_variadic={{ out_variadic_solution if out_variadic_solution else "{}_count".format(schema.outputs[-1].name) }}, {% -endif %}).get_output_vars( +endif %}).get_output_vars(input_prop_values={ {% for param in schema.inputs - %}{{param.name}}=get_value({{param.name}}), {% + %}"{{param.name}}":get_value({{param.name}}), {% endfor %} - ){% + }){% if schema.outputs | length <= 1 %}.{{ schema.outputs[0].name }}{% else %}._unpack_to_any(){% From 340d4c2de607d69fd872d5879a6102198aba9e92 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 6 Nov 2024 17:55:57 +0200 Subject: [PATCH 13/29] Make tests passing --- src/spox/_fields.py | 4 - src/spox/_node.py | 6 +- src/spox/opset/ai/onnx/ml/v3.py | 182 +-- src/spox/opset/ai/onnx/ml/v4.py | 10 +- src/spox/opset/ai/onnx/ml/v5.py | 10 +- src/spox/opset/ai/onnx/v17.py | 2022 +++++++++++++++--------------- src/spox/opset/ai/onnx/v18.py | 306 ++--- src/spox/opset/ai/onnx/v19.py | 204 +-- src/spox/opset/ai/onnx/v20.py | 144 +-- src/spox/opset/ai/onnx/v21.py | 240 ++-- tests/test_custom_operator.py | 2 +- tests/test_function.py | 2 +- tools/generate_opset.py | 2 +- tools/templates/construct.jinja2 | 13 +- 14 files changed, 1575 insertions(+), 1572 deletions(-) diff --git a/src/spox/_fields.py b/src/spox/_fields.py index 70245e53..18e97bc0 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -203,7 +203,6 @@ class Vars(BaseVars): def _propagate_vars( self, prop_values={}, - flatten_variadic=False, ) -> TypeBaseVars: def _create_var(key, var_info): ret = Var(var_info, None) @@ -229,9 +228,6 @@ def _create_var(key, var_info): for key, var_info in self.__dict__.items(): if var_info is None or isinstance(var_info, VarInfo): ret_dict[key] = _create_var(key, var_info) - elif flatten_variadic: - for i, v in enumerate(var_info): - ret_dict[f"{key}_{i}"] = _create_var(f"{key}_{i}", v) else: ret_dict[key] = [ _create_var(f"{key}_{i}", v) for i, v in enumerate(var_info) diff --git a/src/spox/_node.py b/src/spox/_node.py index 3b821b05..96d899ed 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -237,12 +237,10 @@ def inference(self, infer_types: bool = True, input_prop_values={}): # Attempt to use the ones from kwargs, if none then what type inference gave var.type = out_types.get(key) - def get_output_vars(self, flatten_variadic=False, input_prop_values={}): + def get_output_vars(self, input_prop_values={}): # After typing everything, try to get values for outputs out_values = self.propagate_values(input_prop_values) - return self.outputs._propagate_vars( - out_values, flatten_variadic=flatten_variadic - ) + return self.outputs._propagate_vars(out_values) def validate_types(self) -> None: """Validation of types, ran at the end of Node creation.""" diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index 929971d0..161ac890 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -662,6 +662,10 @@ def array_feature_extractor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + "Y": get_value(Y), + } return ( _ArrayFeatureExtractor( _ArrayFeatureExtractor.Attributes(), @@ -669,13 +673,9 @@ def array_feature_extractor( X=unwrap_vars(X), Y=unwrap_vars(Y), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "Y": get_value(Y), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Z ) @@ -711,6 +711,9 @@ def binarizer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Binarizer( _Binarizer.Attributes( @@ -719,12 +722,9 @@ def binarizer( _Binarizer.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -776,6 +776,9 @@ def cast_map( - T1: `map(int64,tensor(float))`, `map(int64,tensor(string))` - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _CastMap( _CastMap.Attributes( @@ -786,12 +789,9 @@ def cast_map( _CastMap.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -851,6 +851,9 @@ def category_mapper( - T1: `tensor(int64)`, `tensor(string)` - T2: `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _CategoryMapper( _CategoryMapper.Attributes( @@ -862,12 +865,9 @@ def category_mapper( _CategoryMapper.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -922,6 +922,9 @@ def dict_vectorizer( - T1: `map(int64,tensor(double))`, `map(int64,tensor(float))`, `map(int64,tensor(string))`, `map(string,tensor(double))`, `map(string,tensor(float))`, `map(string,tensor(int64))` - T2: `tensor(double)`, `tensor(float)`, `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _DictVectorizer( _DictVectorizer.Attributes( @@ -935,12 +938,9 @@ def dict_vectorizer( _DictVectorizer.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -979,6 +979,9 @@ def feature_vectorizer( Type constraints: - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _FeatureVectorizer( _FeatureVectorizer.Attributes( @@ -989,12 +992,9 @@ def feature_vectorizer( _FeatureVectorizer.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1054,6 +1054,9 @@ def imputer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Imputer( _Imputer.Attributes( @@ -1073,12 +1076,9 @@ def imputer( _Imputer.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1163,6 +1163,9 @@ def label_encoder( - T1: `tensor(float)`, `tensor(int64)`, `tensor(string)` - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _LabelEncoder( _LabelEncoder.Attributes( @@ -1179,12 +1182,9 @@ def label_encoder( _LabelEncoder.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1246,6 +1246,9 @@ def linear_classifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _LinearClassifier( _LinearClassifier.Attributes( @@ -1263,12 +1266,9 @@ def linear_classifier( _LinearClassifier.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -1322,6 +1322,9 @@ def linear_regressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _LinearRegressor( _LinearRegressor.Attributes( @@ -1333,12 +1336,9 @@ def linear_regressor( _LinearRegressor.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1379,6 +1379,9 @@ def normalizer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Normalizer( _Normalizer.Attributes( @@ -1387,12 +1390,9 @@ def normalizer( _Normalizer.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1446,6 +1446,9 @@ def one_hot_encoder( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _OneHotEncoder( _OneHotEncoder.Attributes( @@ -1456,12 +1459,9 @@ def one_hot_encoder( _OneHotEncoder.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1548,6 +1548,9 @@ def svmclassifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _SVMClassifier( _SVMClassifier.Attributes( @@ -1574,12 +1577,9 @@ def svmclassifier( _SVMClassifier.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -1645,6 +1645,9 @@ def svmregressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _SVMRegressor( _SVMRegressor.Attributes( @@ -1662,12 +1665,9 @@ def svmregressor( _SVMRegressor.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1711,6 +1711,9 @@ def scaler( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Scaler( _Scaler.Attributes( @@ -1720,12 +1723,9 @@ def scaler( _Scaler.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1864,6 +1864,9 @@ def tree_ensemble_classifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _TreeEnsembleClassifier( _TreeEnsembleClassifier.Attributes( @@ -1915,12 +1918,9 @@ def tree_ensemble_classifier( _TreeEnsembleClassifier.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -2057,6 +2057,9 @@ def tree_ensemble_regressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _TreeEnsembleRegressor( _TreeEnsembleRegressor.Attributes( @@ -2108,12 +2111,9 @@ def tree_ensemble_regressor( _TreeEnsembleRegressor.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -2158,6 +2158,9 @@ def zip_map( Type constraints: - T: `seq(map(int64,tensor(float)))`, `seq(map(string,tensor(float)))` """ + input_prop_values = { + "X": get_value(X), + } return ( _ZipMap( _ZipMap.Attributes( @@ -2171,12 +2174,9 @@ def zip_map( _ZipMap.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Z ) diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index e0dd5a1b..a4f6dec9 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -191,6 +191,9 @@ def label_encoder( - T1: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` - T2: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + } return ( _LabelEncoder( _LabelEncoder.Attributes( @@ -210,12 +213,9 @@ def label_encoder( _LabelEncoder.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index 7eab3ef1..529b2a10 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -224,6 +224,9 @@ def tree_ensemble( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _TreeEnsemble( _TreeEnsemble.Attributes( @@ -258,12 +261,9 @@ def tree_ensemble( _TreeEnsemble.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 15a1ac90..40244e54 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -3958,18 +3958,18 @@ def abs( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Abs( _Abs.Attributes(), _Abs.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -4000,18 +4000,18 @@ def acos( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Acos( _Acos.Attributes(), _Acos.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -4043,18 +4043,18 @@ def acosh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Acosh( _Acosh.Attributes(), _Acosh.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -4096,6 +4096,10 @@ def add( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Add( _Add.Attributes(), @@ -4103,13 +4107,9 @@ def add( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -4150,6 +4150,10 @@ def and_( - T: `tensor(bool)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _And( _And.Attributes(), @@ -4157,13 +4161,9 @@ def and_( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -4216,6 +4216,9 @@ def arg_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ArgMax( _ArgMax.Attributes( @@ -4228,12 +4231,9 @@ def arg_max( _ArgMax.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -4286,6 +4286,9 @@ def arg_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ArgMin( _ArgMin.Attributes( @@ -4298,12 +4301,9 @@ def arg_min( _ArgMin.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -4334,18 +4334,18 @@ def asin( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Asin( _Asin.Attributes(), _Asin.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -4376,18 +4376,18 @@ def asinh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Asinh( _Asinh.Attributes(), _Asinh.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -4418,18 +4418,18 @@ def atan( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Atan( _Atan.Attributes(), _Atan.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -4461,18 +4461,18 @@ def atanh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Atanh( _Atanh.Attributes(), _Atanh.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -4598,6 +4598,9 @@ def average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _AveragePool( _AveragePool.Attributes( @@ -4613,12 +4616,9 @@ def average_pool( _AveragePool.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -4743,6 +4743,13 @@ def batch_normalization( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "scale": get_value(scale), + "B": get_value(B), + "input_mean": get_value(input_mean), + "input_var": get_value(input_var), + } return ( _BatchNormalization( _BatchNormalization.Attributes( @@ -4757,16 +4764,9 @@ def batch_normalization( input_mean=unwrap_vars(input_mean), input_var=unwrap_vars(input_var), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "scale": get_value(scale), - "B": get_value(B), - "input_mean": get_value(input_mean), - "input_var": get_value(input_var), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -4816,6 +4816,9 @@ def bernoulli( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Bernoulli( _Bernoulli.Attributes( @@ -4825,12 +4828,9 @@ def bernoulli( _Bernoulli.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -4885,6 +4885,10 @@ def bit_shift( Type constraints: - T: `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "X": get_value(X), + "Y": get_value(Y), + } return ( _BitShift( _BitShift.Attributes( @@ -4894,13 +4898,9 @@ def bit_shift( X=unwrap_vars(X), Y=unwrap_vars(Y), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "Y": get_value(Y), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Z ) @@ -4946,6 +4946,9 @@ def blackman_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "size": get_value(size), + } return ( _BlackmanWindow( _BlackmanWindow.Attributes( @@ -4955,12 +4958,9 @@ def blackman_window( _BlackmanWindow.Inputs( size=unwrap_vars(size), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "size": get_value(size), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -5047,6 +5047,9 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Cast( _Cast.Attributes( @@ -5055,12 +5058,9 @@ def cast( _Cast.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -5099,6 +5099,10 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "target_type": get_value(target_type), + } return ( _CastLike( _CastLike.Attributes(), @@ -5106,13 +5110,9 @@ def cast_like( input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "target_type": get_value(target_type), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -5145,18 +5145,18 @@ def ceil( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Ceil( _Ceil.Attributes(), _Ceil.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -5197,6 +5197,9 @@ def celu( Type constraints: - T: `tensor(float)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Celu( _Celu.Attributes( @@ -5205,12 +5208,9 @@ def celu( _Celu.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -5252,6 +5252,11 @@ def clip( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "min": get_value(min), + "max": get_value(max), + } return ( _Clip( _Clip.Attributes(), @@ -5260,14 +5265,9 @@ def clip( min=unwrap_vars(min), max=unwrap_vars(max), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "min": get_value(min), - "max": get_value(max), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -5318,6 +5318,10 @@ def compress( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ + input_prop_values = { + "input": get_value(input), + "condition": get_value(condition), + } return ( _Compress( _Compress.Attributes( @@ -5327,13 +5331,9 @@ def compress( input=unwrap_vars(input), condition=unwrap_vars(condition), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "condition": get_value(condition), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -5371,6 +5371,9 @@ def concat( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "inputs": get_value(inputs), + } return ( _Concat( _Concat.Attributes( @@ -5379,12 +5382,9 @@ def concat( _Concat.Inputs( inputs=unwrap_vars(inputs), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "inputs": get_value(inputs), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .concat_result ) @@ -5431,6 +5431,9 @@ def concat_from_sequence( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input_sequence": get_value(input_sequence), + } return ( _ConcatFromSequence( _ConcatFromSequence.Attributes( @@ -5440,12 +5443,9 @@ def concat_from_sequence( _ConcatFromSequence.Inputs( input_sequence=unwrap_vars(input_sequence), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input_sequence": get_value(input_sequence), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .concat_result ) @@ -5505,6 +5505,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = {} return ( _Constant( _Constant.Attributes( @@ -5517,8 +5518,9 @@ def constant( value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), _Constant.Inputs(), + input_prop_values=input_prop_values, ) - .get_output_vars(input_prop_values={}) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -5560,6 +5562,9 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _ConstantOfShape( _ConstantOfShape.Attributes( @@ -5568,12 +5573,9 @@ def constant_of_shape( _ConstantOfShape.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -5675,6 +5677,11 @@ def conv( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "W": get_value(W), + "B": get_value(B), + } return ( _Conv( _Conv.Attributes( @@ -5690,14 +5697,9 @@ def conv( W=unwrap_vars(W), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "W": get_value(W), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -5810,6 +5812,12 @@ def conv_integer( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int32)` """ + input_prop_values = { + "x": get_value(x), + "w": get_value(w), + "x_zero_point": get_value(x_zero_point), + "w_zero_point": get_value(w_zero_point), + } return ( _ConvInteger( _ConvInteger.Attributes( @@ -5826,15 +5834,9 @@ def conv_integer( x_zero_point=unwrap_vars(x_zero_point), w_zero_point=unwrap_vars(w_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "w": get_value(w), - "x_zero_point": get_value(x_zero_point), - "w_zero_point": get_value(w_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -5967,6 +5969,11 @@ def conv_transpose( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "W": get_value(W), + "B": get_value(B), + } return ( _ConvTranspose( _ConvTranspose.Attributes( @@ -5984,14 +5991,9 @@ def conv_transpose( W=unwrap_vars(W), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "W": get_value(W), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -6021,18 +6023,18 @@ def cos( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Cos( _Cos.Attributes(), _Cos.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -6062,18 +6064,18 @@ def cosh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Cosh( _Cosh.Attributes(), _Cosh.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -6143,6 +6145,10 @@ def cumsum( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - T2: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "x": get_value(x), + "axis": get_value(axis), + } return ( _CumSum( _CumSum.Attributes( @@ -6153,13 +6159,9 @@ def cumsum( x=unwrap_vars(x), axis=unwrap_vars(axis), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "axis": get_value(axis), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -6237,6 +6239,10 @@ def dft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "input": get_value(input), + "dft_length": get_value(dft_length), + } return ( _DFT( _DFT.Attributes( @@ -6248,13 +6254,9 @@ def dft( input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "dft_length": get_value(dft_length), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -6321,6 +6323,9 @@ def depth_to_space( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _DepthToSpace( _DepthToSpace.Attributes( @@ -6330,12 +6335,9 @@ def depth_to_space( _DepthToSpace.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -6390,6 +6392,11 @@ def dequantize_linear( Type constraints: - T: `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` """ + input_prop_values = { + "x": get_value(x), + "x_scale": get_value(x_scale), + "x_zero_point": get_value(x_zero_point), + } return ( _DequantizeLinear( _DequantizeLinear.Attributes( @@ -6400,14 +6407,9 @@ def dequantize_linear( x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "x_scale": get_value(x_scale), - "x_zero_point": get_value(x_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -6442,18 +6444,18 @@ def det( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Det( _Det.Attributes(), _Det.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -6495,6 +6497,10 @@ def div( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Div( _Div.Attributes(), @@ -6502,13 +6508,9 @@ def div( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -6589,6 +6591,11 @@ def dropout( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bool)` """ + input_prop_values = { + "data": get_value(data), + "ratio": get_value(ratio), + "training_mode": get_value(training_mode), + } return ( _Dropout( _Dropout.Attributes( @@ -6599,14 +6606,9 @@ def dropout( ratio=unwrap_vars(ratio), training_mode=unwrap_vars(training_mode), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "ratio": get_value(ratio), - "training_mode": get_value(training_mode), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -6678,18 +6680,18 @@ def dynamic_quantize_linear( - T1: `tensor(float)` - T2: `tensor(uint8)` """ + input_prop_values = { + "x": get_value(x), + } return ( _DynamicQuantizeLinear( _DynamicQuantizeLinear.Attributes(), _DynamicQuantizeLinear.Inputs( x=unwrap_vars(x), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -6756,6 +6758,9 @@ def einsum( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "Inputs": get_value(Inputs), + } return ( _Einsum( _Einsum.Attributes( @@ -6764,12 +6769,9 @@ def einsum( _Einsum.Inputs( Inputs=unwrap_vars(Inputs), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "Inputs": get_value(Inputs), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Output ) @@ -6807,6 +6809,9 @@ def elu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Elu( _Elu.Attributes( @@ -6815,12 +6820,9 @@ def elu( _Elu.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -6861,6 +6863,10 @@ def equal( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Equal( _Equal.Attributes(), @@ -6868,13 +6874,9 @@ def equal( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -6905,18 +6907,18 @@ def erf( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Erf( _Erf.Attributes(), _Erf.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -6946,18 +6948,18 @@ def exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Exp( _Exp.Attributes(), _Exp.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -7000,6 +7002,10 @@ def expand( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "shape": get_value(shape), + } return ( _Expand( _Expand.Attributes(), @@ -7007,13 +7013,9 @@ def expand( input=unwrap_vars(input), shape=unwrap_vars(shape), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "shape": get_value(shape), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -7066,6 +7068,9 @@ def eye_like( - T1: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _EyeLike( _EyeLike.Attributes( @@ -7075,12 +7080,9 @@ def eye_like( _EyeLike.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -7124,6 +7126,9 @@ def flatten( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Flatten( _Flatten.Attributes( @@ -7132,12 +7137,9 @@ def flatten( _Flatten.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -7170,18 +7172,18 @@ def floor( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Floor( _Floor.Attributes(), _Floor.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -7358,6 +7360,14 @@ def gru( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ + input_prop_values = { + "X": get_value(X), + "W": get_value(W), + "R": get_value(R), + "B": get_value(B), + "sequence_lens": get_value(sequence_lens), + "initial_h": get_value(initial_h), + } return ( _GRU( _GRU.Attributes( @@ -7384,17 +7394,9 @@ def gru( sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "W": get_value(W), - "R": get_value(R), - "B": get_value(B), - "sequence_lens": get_value(sequence_lens), - "initial_h": get_value(initial_h), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -7485,6 +7487,10 @@ def gather( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + "indices": get_value(indices), + } return ( _Gather( _Gather.Attributes( @@ -7494,13 +7500,9 @@ def gather( data=unwrap_vars(data), indices=unwrap_vars(indices), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "indices": get_value(indices), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -7599,6 +7601,10 @@ def gather_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + "indices": get_value(indices), + } return ( _GatherElements( _GatherElements.Attributes( @@ -7608,13 +7614,9 @@ def gather_elements( data=unwrap_vars(data), indices=unwrap_vars(indices), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "indices": get_value(indices), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -7758,6 +7760,10 @@ def gather_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "indices": get_value(indices), + } return ( _GatherND( _GatherND.Attributes( @@ -7767,13 +7773,9 @@ def gather_nd( data=unwrap_vars(data), indices=unwrap_vars(indices), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "indices": get_value(indices), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -7851,6 +7853,11 @@ def gemm( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + "C": get_value(C), + } return ( _Gemm( _Gemm.Attributes( @@ -7864,14 +7871,9 @@ def gemm( B=unwrap_vars(B), C=unwrap_vars(C), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - "C": get_value(C), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -7910,18 +7912,18 @@ def global_average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _GlobalAveragePool( _GlobalAveragePool.Attributes(), _GlobalAveragePool.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -7965,6 +7967,9 @@ def global_lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _GlobalLpPool( _GlobalLpPool.Attributes( @@ -7973,12 +7978,9 @@ def global_lp_pool( _GlobalLpPool.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -8017,18 +8019,18 @@ def global_max_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _GlobalMaxPool( _GlobalMaxPool.Attributes(), _GlobalMaxPool.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -8069,6 +8071,10 @@ def greater( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Greater( _Greater.Attributes(), @@ -8076,13 +8082,9 @@ def greater( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -8123,6 +8125,10 @@ def greater_or_equal( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _GreaterOrEqual( _GreaterOrEqual.Attributes(), @@ -8130,13 +8136,9 @@ def greater_or_equal( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -8223,6 +8225,10 @@ def grid_sample( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "grid": get_value(grid), + } return ( _GridSample( _GridSample.Attributes( @@ -8234,13 +8240,9 @@ def grid_sample( X=unwrap_vars(X), grid=unwrap_vars(grid), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "grid": get_value(grid), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -8286,6 +8288,9 @@ def hamming_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "size": get_value(size), + } return ( _HammingWindow( _HammingWindow.Attributes( @@ -8295,12 +8300,9 @@ def hamming_window( _HammingWindow.Inputs( size=unwrap_vars(size), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "size": get_value(size), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -8346,6 +8348,9 @@ def hann_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "size": get_value(size), + } return ( _HannWindow( _HannWindow.Attributes( @@ -8355,12 +8360,9 @@ def hann_window( _HannWindow.Inputs( size=unwrap_vars(size), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "size": get_value(size), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -8401,6 +8403,9 @@ def hard_sigmoid( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _HardSigmoid( _HardSigmoid.Attributes( @@ -8410,12 +8415,9 @@ def hard_sigmoid( _HardSigmoid.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -8448,18 +8450,18 @@ def hard_swish( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _HardSwish( _HardSwish.Attributes(), _HardSwish.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -8503,6 +8505,9 @@ def hardmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Hardmax( _Hardmax.Attributes( @@ -8511,12 +8516,9 @@ def hardmax( _Hardmax.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -8546,18 +8548,18 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -8616,6 +8618,9 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) + input_prop_values = { + "cond": get_value(cond), + } return ( _If( _If.Attributes( @@ -8626,12 +8631,9 @@ def if_( cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "cond": get_value(cond), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .outputs ) @@ -8682,6 +8684,11 @@ def instance_normalization( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + "scale": get_value(scale), + "B": get_value(B), + } return ( _InstanceNormalization( _InstanceNormalization.Attributes( @@ -8692,14 +8699,9 @@ def instance_normalization( scale=unwrap_vars(scale), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "scale": get_value(scale), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -8743,6 +8745,9 @@ def isinf( - T1: `tensor(double)`, `tensor(float)` - T2: `tensor(bool)` """ + input_prop_values = { + "X": get_value(X), + } return ( _IsInf( _IsInf.Attributes( @@ -8752,12 +8757,9 @@ def isinf( _IsInf.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -8788,18 +8790,18 @@ def isnan( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bool)` """ + input_prop_values = { + "X": get_value(X), + } return ( _IsNaN( _IsNaN.Attributes(), _IsNaN.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -8863,6 +8865,9 @@ def lrn( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _LRN( _LRN.Attributes( @@ -8874,12 +8879,9 @@ def lrn( _LRN.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -9078,6 +9080,16 @@ def lstm( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ + input_prop_values = { + "X": get_value(X), + "W": get_value(W), + "R": get_value(R), + "B": get_value(B), + "sequence_lens": get_value(sequence_lens), + "initial_h": get_value(initial_h), + "initial_c": get_value(initial_c), + "P": get_value(P), + } return ( _LSTM( _LSTM.Attributes( @@ -9104,19 +9116,9 @@ def lstm( initial_c=unwrap_vars(initial_c), P=unwrap_vars(P), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "W": get_value(W), - "R": get_value(R), - "B": get_value(B), - "sequence_lens": get_value(sequence_lens), - "initial_h": get_value(initial_h), - "initial_c": get_value(initial_c), - "P": get_value(P), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -9204,6 +9206,11 @@ def layer_normalization( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - U: `tensor(bfloat16)`, `tensor(float)` """ + input_prop_values = { + "X": get_value(X), + "Scale": get_value(Scale), + "B": get_value(B), + } return ( _LayerNormalization( _LayerNormalization.Attributes( @@ -9216,14 +9223,9 @@ def layer_normalization( Scale=unwrap_vars(Scale), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "Scale": get_value(Scale), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -9261,6 +9263,9 @@ def leaky_relu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _LeakyRelu( _LeakyRelu.Attributes( @@ -9269,12 +9274,9 @@ def leaky_relu( _LeakyRelu.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -9315,6 +9317,10 @@ def less( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Less( _Less.Attributes(), @@ -9322,13 +9328,9 @@ def less( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -9369,6 +9371,10 @@ def less_or_equal( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _LessOrEqual( _LessOrEqual.Attributes(), @@ -9376,13 +9382,9 @@ def less_or_equal( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -9412,18 +9414,18 @@ def log( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Log( _Log.Attributes(), _Log.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -9466,6 +9468,9 @@ def log_softmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _LogSoftmax( _LogSoftmax.Attributes( @@ -9474,12 +9479,9 @@ def log_softmax( _LogSoftmax.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -9665,6 +9667,11 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) + input_prop_values = { + "M": get_value(M), + "cond": get_value(cond), + "v_initial": get_value(v_initial), + } return ( _Loop( _Loop.Attributes( @@ -9676,14 +9683,9 @@ def loop( v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "M": get_value(M), - "cond": get_value(cond), - "v_initial": get_value(v_initial), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs ) @@ -9722,6 +9724,9 @@ def lp_normalization( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _LpNormalization( _LpNormalization.Attributes( @@ -9731,12 +9736,9 @@ def lp_normalization( _LpNormalization.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -9812,6 +9814,9 @@ def lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _LpPool( _LpPool.Attributes( @@ -9824,12 +9829,9 @@ def lp_pool( _LpPool.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -9864,6 +9866,10 @@ def matmul( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _MatMul( _MatMul.Attributes(), @@ -9871,13 +9877,9 @@ def matmul( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -9934,6 +9936,12 @@ def matmul_integer( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int32)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + "a_zero_point": get_value(a_zero_point), + "b_zero_point": get_value(b_zero_point), + } return ( _MatMulInteger( _MatMulInteger.Attributes(), @@ -9943,15 +9951,9 @@ def matmul_integer( a_zero_point=unwrap_vars(a_zero_point), b_zero_point=unwrap_vars(b_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - "a_zero_point": get_value(a_zero_point), - "b_zero_point": get_value(b_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -9985,18 +9987,18 @@ def max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data_0": get_value(data_0), + } return ( _Max( _Max.Attributes(), _Max.Inputs( data_0=unwrap_vars(data_0), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data_0": get_value(data_0), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .max ) @@ -10138,6 +10140,9 @@ def max_pool( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int8)`, `tensor(uint8)` - I: `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _MaxPool( _MaxPool.Attributes( @@ -10152,12 +10157,9 @@ def max_pool( _MaxPool.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -10207,6 +10209,10 @@ def max_roi_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "rois": get_value(rois), + } return ( _MaxRoiPool( _MaxRoiPool.Attributes( @@ -10217,13 +10223,9 @@ def max_roi_pool( X=unwrap_vars(X), rois=unwrap_vars(rois), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "rois": get_value(rois), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -10324,6 +10326,11 @@ def max_unpool( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + "I": get_value(I), + "output_shape": get_value(output_shape), + } return ( _MaxUnpool( _MaxUnpool.Attributes( @@ -10336,14 +10343,9 @@ def max_unpool( I=unwrap_vars(I), output_shape=unwrap_vars(output_shape), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "I": get_value(I), - "output_shape": get_value(output_shape), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -10377,18 +10379,18 @@ def mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "data_0": get_value(data_0), + } return ( _Mean( _Mean.Attributes(), _Mean.Inputs( data_0=unwrap_vars(data_0), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data_0": get_value(data_0), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .mean ) @@ -10428,6 +10430,9 @@ def mean_variance_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _MeanVarianceNormalization( _MeanVarianceNormalization.Attributes( @@ -10436,12 +10441,9 @@ def mean_variance_normalization( _MeanVarianceNormalization.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -10520,6 +10522,13 @@ def mel_weight_matrix( - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T3: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "num_mel_bins": get_value(num_mel_bins), + "dft_length": get_value(dft_length), + "sample_rate": get_value(sample_rate), + "lower_edge_hertz": get_value(lower_edge_hertz), + "upper_edge_hertz": get_value(upper_edge_hertz), + } return ( _MelWeightMatrix( _MelWeightMatrix.Attributes( @@ -10532,16 +10541,9 @@ def mel_weight_matrix( lower_edge_hertz=unwrap_vars(lower_edge_hertz), upper_edge_hertz=unwrap_vars(upper_edge_hertz), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "num_mel_bins": get_value(num_mel_bins), - "dft_length": get_value(dft_length), - "sample_rate": get_value(sample_rate), - "lower_edge_hertz": get_value(lower_edge_hertz), - "upper_edge_hertz": get_value(upper_edge_hertz), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -10575,18 +10577,18 @@ def min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data_0": get_value(data_0), + } return ( _Min( _Min.Attributes(), _Min.Inputs( data_0=unwrap_vars(data_0), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data_0": get_value(data_0), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .min ) @@ -10643,6 +10645,10 @@ def mod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Mod( _Mod.Attributes( @@ -10652,13 +10658,9 @@ def mod( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -10700,6 +10702,10 @@ def mul( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Mul( _Mul.Attributes(), @@ -10707,13 +10713,9 @@ def mul( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -10765,6 +10767,9 @@ def multinomial( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Multinomial( _Multinomial.Attributes( @@ -10775,12 +10780,9 @@ def multinomial( _Multinomial.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -10812,18 +10814,18 @@ def neg( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Neg( _Neg.Attributes(), _Neg.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -10985,6 +10987,11 @@ def negative_log_likelihood_loss( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "input": get_value(input), + "target": get_value(target), + "weight": get_value(weight), + } return ( _NegativeLogLikelihoodLoss( _NegativeLogLikelihoodLoss.Attributes( @@ -10996,14 +11003,9 @@ def negative_log_likelihood_loss( target=unwrap_vars(target), weight=unwrap_vars(weight), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "target": get_value(target), - "weight": get_value(weight), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .loss ) @@ -11074,6 +11076,13 @@ def non_max_suppression( Signature: ``ai.onnx@11::NonMaxSuppression``. """ + input_prop_values = { + "boxes": get_value(boxes), + "scores": get_value(scores), + "max_output_boxes_per_class": get_value(max_output_boxes_per_class), + "iou_threshold": get_value(iou_threshold), + "score_threshold": get_value(score_threshold), + } return ( _NonMaxSuppression( _NonMaxSuppression.Attributes( @@ -11086,16 +11095,9 @@ def non_max_suppression( iou_threshold=unwrap_vars(iou_threshold), score_threshold=unwrap_vars(score_threshold), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "boxes": get_value(boxes), - "scores": get_value(scores), - "max_output_boxes_per_class": get_value(max_output_boxes_per_class), - "iou_threshold": get_value(iou_threshold), - "score_threshold": get_value(score_threshold), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .selected_indices ) @@ -11129,18 +11131,18 @@ def non_zero( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "X": get_value(X), + } return ( _NonZero( _NonZero.Attributes(), _NonZero.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -11170,18 +11172,18 @@ def not_( Type constraints: - T: `tensor(bool)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Not( _Not.Attributes(), _Not.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -11267,6 +11269,11 @@ def one_hot( - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T3: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "indices": get_value(indices), + "depth": get_value(depth), + "values": get_value(values), + } return ( _OneHot( _OneHot.Attributes( @@ -11277,14 +11284,9 @@ def one_hot( depth=unwrap_vars(depth), values=unwrap_vars(values), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "indices": get_value(indices), - "depth": get_value(depth), - "values": get_value(values), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -11322,6 +11324,9 @@ def optional( - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` """ + input_prop_values = { + "input": get_value(input), + } return ( _Optional( _Optional.Attributes( @@ -11330,12 +11335,9 @@ def optional( _Optional.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -11368,18 +11370,18 @@ def optional_get_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _OptionalGetElement( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -11412,18 +11414,18 @@ def optional_has_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - B: `tensor(bool)` """ + input_prop_values = { + "input": get_value(input), + } return ( _OptionalHasElement( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -11464,6 +11466,10 @@ def or_( - T: `tensor(bool)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Or( _Or.Attributes(), @@ -11471,13 +11477,9 @@ def or_( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -11518,6 +11520,10 @@ def prelu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "X": get_value(X), + "slope": get_value(slope), + } return ( _PRelu( _PRelu.Attributes(), @@ -11525,13 +11531,9 @@ def prelu( X=unwrap_vars(X), slope=unwrap_vars(slope), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "slope": get_value(slope), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -11630,6 +11632,11 @@ def pad( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "pads": get_value(pads), + "constant_value": get_value(constant_value), + } return ( _Pad( _Pad.Attributes( @@ -11640,14 +11647,9 @@ def pad( pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "pads": get_value(pads), - "constant_value": get_value(constant_value), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -11687,6 +11689,10 @@ def pow( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)` - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "X": get_value(X), + "Y": get_value(Y), + } return ( _Pow( _Pow.Attributes(), @@ -11694,13 +11700,9 @@ def pow( X=unwrap_vars(X), Y=unwrap_vars(Y), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "Y": get_value(Y), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Z ) @@ -11845,6 +11847,17 @@ def qlinear_conv( - T3: `tensor(int8)`, `tensor(uint8)` - T4: `tensor(int32)` """ + input_prop_values = { + "x": get_value(x), + "x_scale": get_value(x_scale), + "x_zero_point": get_value(x_zero_point), + "w": get_value(w), + "w_scale": get_value(w_scale), + "w_zero_point": get_value(w_zero_point), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + "B": get_value(B), + } return ( _QLinearConv( _QLinearConv.Attributes( @@ -11866,20 +11879,9 @@ def qlinear_conv( y_zero_point=unwrap_vars(y_zero_point), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "x_scale": get_value(x_scale), - "x_zero_point": get_value(x_zero_point), - "w": get_value(w), - "w_scale": get_value(w_scale), - "w_zero_point": get_value(w_zero_point), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -11956,6 +11958,16 @@ def qlinear_matmul( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int8)`, `tensor(uint8)` """ + input_prop_values = { + "a": get_value(a), + "a_scale": get_value(a_scale), + "a_zero_point": get_value(a_zero_point), + "b": get_value(b), + "b_scale": get_value(b_scale), + "b_zero_point": get_value(b_zero_point), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } return ( _QLinearMatMul( _QLinearMatMul.Attributes(), @@ -11969,19 +11981,9 @@ def qlinear_matmul( y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "a": get_value(a), - "a_scale": get_value(a_scale), - "a_zero_point": get_value(a_zero_point), - "b": get_value(b), - "b_scale": get_value(b_scale), - "b_zero_point": get_value(b_zero_point), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -12040,6 +12042,11 @@ def quantize_linear( - T1: `tensor(float)`, `tensor(int32)` - T2: `tensor(int8)`, `tensor(uint8)` """ + input_prop_values = { + "x": get_value(x), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } return ( _QuantizeLinear( _QuantizeLinear.Attributes( @@ -12050,14 +12057,9 @@ def quantize_linear( y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -12214,6 +12216,14 @@ def rnn( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ + input_prop_values = { + "X": get_value(X), + "W": get_value(W), + "R": get_value(R), + "B": get_value(B), + "sequence_lens": get_value(sequence_lens), + "initial_h": get_value(initial_h), + } return ( _RNN( _RNN.Attributes( @@ -12237,17 +12247,9 @@ def rnn( sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "W": get_value(W), - "R": get_value(R), - "B": get_value(B), - "sequence_lens": get_value(sequence_lens), - "initial_h": get_value(initial_h), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -12303,6 +12305,7 @@ def random_normal( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = {} return ( _RandomNormal( _RandomNormal.Attributes( @@ -12313,8 +12316,9 @@ def random_normal( shape=AttrInt64s(shape, name="shape"), ), _RandomNormal.Inputs(), + input_prop_values=input_prop_values, ) - .get_output_vars(input_prop_values={}) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -12372,6 +12376,9 @@ def random_normal_like( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _RandomNormalLike( _RandomNormalLike.Attributes( @@ -12383,12 +12390,9 @@ def random_normal_like( _RandomNormalLike.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -12443,6 +12447,7 @@ def random_uniform( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = {} return ( _RandomUniform( _RandomUniform.Attributes( @@ -12453,8 +12458,9 @@ def random_uniform( shape=AttrInt64s(shape, name="shape"), ), _RandomUniform.Inputs(), + input_prop_values=input_prop_values, ) - .get_output_vars(input_prop_values={}) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -12512,6 +12518,9 @@ def random_uniform_like( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _RandomUniformLike( _RandomUniformLike.Attributes( @@ -12523,12 +12532,9 @@ def random_uniform_like( _RandomUniformLike.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -12597,6 +12603,11 @@ def range( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "start": get_value(start), + "limit": get_value(limit), + "delta": get_value(delta), + } return ( _Range( _Range.Attributes(), @@ -12605,14 +12616,9 @@ def range( limit=unwrap_vars(limit), delta=unwrap_vars(delta), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "start": get_value(start), - "limit": get_value(limit), - "delta": get_value(delta), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -12644,18 +12650,18 @@ def reciprocal( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Reciprocal( _Reciprocal.Attributes(), _Reciprocal.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -12704,6 +12710,9 @@ def reduce_l1( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceL1( _ReduceL1.Attributes( @@ -12713,12 +12722,9 @@ def reduce_l1( _ReduceL1.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -12767,6 +12773,9 @@ def reduce_l2( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceL2( _ReduceL2.Attributes( @@ -12776,12 +12785,9 @@ def reduce_l2( _ReduceL2.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -12831,6 +12837,9 @@ def reduce_log_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceLogSum( _ReduceLogSum.Attributes( @@ -12840,12 +12849,9 @@ def reduce_log_sum( _ReduceLogSum.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -12895,6 +12901,9 @@ def reduce_log_sum_exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceLogSumExp( _ReduceLogSumExp.Attributes( @@ -12904,12 +12913,9 @@ def reduce_log_sum_exp( _ReduceLogSumExp.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -12960,6 +12966,9 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceMax( _ReduceMax.Attributes( @@ -12969,12 +12978,9 @@ def reduce_max( _ReduceMax.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -13023,6 +13029,9 @@ def reduce_mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceMean( _ReduceMean.Attributes( @@ -13032,12 +13041,9 @@ def reduce_mean( _ReduceMean.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -13087,6 +13093,9 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceMin( _ReduceMin.Attributes( @@ -13096,12 +13105,9 @@ def reduce_min( _ReduceMin.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -13150,6 +13156,9 @@ def reduce_prod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceProd( _ReduceProd.Attributes( @@ -13159,12 +13168,9 @@ def reduce_prod( _ReduceProd.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -13222,6 +13228,10 @@ def reduce_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceSum( _ReduceSum.Attributes( @@ -13234,13 +13244,9 @@ def reduce_sum( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -13289,6 +13295,9 @@ def reduce_sum_square( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _ReduceSumSquare( _ReduceSumSquare.Attributes( @@ -13298,12 +13307,9 @@ def reduce_sum_square( _ReduceSumSquare.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -13335,18 +13341,18 @@ def relu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Relu( _Relu.Attributes(), _Relu.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -13402,6 +13408,10 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "shape": get_value(shape), + } return ( _Reshape( _Reshape.Attributes( @@ -13411,13 +13421,9 @@ def reshape( data=unwrap_vars(data), shape=unwrap_vars(shape), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "shape": get_value(shape), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reshaped ) @@ -13541,6 +13547,12 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "roi": get_value(roi), + "scales": get_value(scales), + "sizes": get_value(sizes), + } return ( _Resize( _Resize.Attributes( @@ -13562,15 +13574,9 @@ def resize( scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "roi": get_value(roi), - "scales": get_value(scales), - "sizes": get_value(sizes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -13637,6 +13643,10 @@ def reverse_sequence( Type constraints: - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "sequence_lens": get_value(sequence_lens), + } return ( _ReverseSequence( _ReverseSequence.Attributes( @@ -13647,13 +13657,9 @@ def reverse_sequence( input=unwrap_vars(input), sequence_lens=unwrap_vars(sequence_lens), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "sequence_lens": get_value(sequence_lens), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -13745,6 +13751,11 @@ def roi_align( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + "rois": get_value(rois), + "batch_indices": get_value(batch_indices), + } return ( _RoiAlign( _RoiAlign.Attributes( @@ -13763,14 +13774,9 @@ def roi_align( rois=unwrap_vars(rois), batch_indices=unwrap_vars(batch_indices), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "rois": get_value(rois), - "batch_indices": get_value(batch_indices), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -13814,18 +13820,18 @@ def round( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Round( _Round.Attributes(), _Round.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -13891,6 +13897,12 @@ def stft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "signal": get_value(signal), + "frame_step": get_value(frame_step), + "window": get_value(window), + "frame_length": get_value(frame_length), + } return ( _STFT( _STFT.Attributes( @@ -13902,15 +13914,9 @@ def stft( window=unwrap_vars(window), frame_length=unwrap_vars(frame_length), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "signal": get_value(signal), - "frame_step": get_value(frame_step), - "window": get_value(window), - "frame_length": get_value(frame_length), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -14136,6 +14142,9 @@ def scan( ], body, ) + input_prop_values = { + "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), + } return ( _Scan( _Scan.Attributes( @@ -14160,14 +14169,9 @@ def scan( ), ), out_variadic=len(_body_subgraph.requested_results), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "initial_state_and_scan_inputs": get_value( - initial_state_and_scan_inputs - ), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs ) @@ -14292,6 +14296,11 @@ def scatter_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + "indices": get_value(indices), + "updates": get_value(updates), + } return ( _ScatterElements( _ScatterElements.Attributes( @@ -14303,14 +14312,9 @@ def scatter_elements( indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "indices": get_value(indices), - "updates": get_value(updates), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -14424,6 +14428,11 @@ def scatter_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "indices": get_value(indices), + "updates": get_value(updates), + } return ( _ScatterND( _ScatterND.Attributes( @@ -14434,14 +14443,9 @@ def scatter_nd( indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "indices": get_value(indices), - "updates": get_value(updates), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -14485,6 +14489,9 @@ def selu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Selu( _Selu.Attributes( @@ -14494,12 +14501,9 @@ def selu( _Selu.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -14542,6 +14546,10 @@ def sequence_at( - I: `tensor(int32)`, `tensor(int64)` - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input_sequence": get_value(input_sequence), + "position": get_value(position), + } return ( _SequenceAt( _SequenceAt.Attributes(), @@ -14549,13 +14557,9 @@ def sequence_at( input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input_sequence": get_value(input_sequence), - "position": get_value(position), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .tensor ) @@ -14587,18 +14591,18 @@ def sequence_construct( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ + input_prop_values = { + "inputs": get_value(inputs), + } return ( _SequenceConstruct( _SequenceConstruct.Attributes(), _SequenceConstruct.Inputs( inputs=unwrap_vars(inputs), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "inputs": get_value(inputs), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output_sequence ) @@ -14630,14 +14634,16 @@ def sequence_empty( Type constraints: - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ + input_prop_values = {} return ( _SequenceEmpty( _SequenceEmpty.Attributes( dtype=AttrDtype.maybe(dtype, name="dtype"), ), _SequenceEmpty.Inputs(), + input_prop_values=input_prop_values, ) - .get_output_vars(input_prop_values={}) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -14680,6 +14686,10 @@ def sequence_erase( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - I: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "input_sequence": get_value(input_sequence), + "position": get_value(position), + } return ( _SequenceErase( _SequenceErase.Attributes(), @@ -14687,13 +14697,9 @@ def sequence_erase( input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input_sequence": get_value(input_sequence), - "position": get_value(position), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output_sequence ) @@ -14743,6 +14749,11 @@ def sequence_insert( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - I: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "input_sequence": get_value(input_sequence), + "tensor": get_value(tensor), + "position": get_value(position), + } return ( _SequenceInsert( _SequenceInsert.Attributes(), @@ -14751,14 +14762,9 @@ def sequence_insert( tensor=unwrap_vars(tensor), position=unwrap_vars(position), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input_sequence": get_value(input_sequence), - "tensor": get_value(tensor), - "position": get_value(position), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output_sequence ) @@ -14790,18 +14796,18 @@ def sequence_length( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - I: `tensor(int64)` """ + input_prop_values = { + "input_sequence": get_value(input_sequence), + } return ( _SequenceLength( _SequenceLength.Attributes(), _SequenceLength.Inputs( input_sequence=unwrap_vars(input_sequence), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input_sequence": get_value(input_sequence), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .length ) @@ -14866,6 +14872,10 @@ def sequence_map( ], body, ) + input_prop_values = { + "input_sequence": get_value(input_sequence), + "additional_inputs": get_value(additional_inputs), + } return ( _SequenceMap( _SequenceMap.Attributes( @@ -14876,13 +14886,9 @@ def sequence_map( additional_inputs=unwrap_vars(additional_inputs), ), out_variadic=len(_body_subgraph.requested_results), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input_sequence": get_value(input_sequence), - "additional_inputs": get_value(additional_inputs), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .out_sequence ) @@ -14963,6 +14969,9 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _Shape( _Shape.Attributes( @@ -14972,12 +14981,9 @@ def shape( _Shape.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .shape ) @@ -15019,6 +15025,9 @@ def shrink( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Shrink( _Shrink.Attributes( @@ -15028,12 +15037,9 @@ def shrink( _Shrink.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -15065,18 +15071,18 @@ def sigmoid( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Sigmoid( _Sigmoid.Attributes(), _Sigmoid.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -15108,18 +15114,18 @@ def sign( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Sign( _Sign.Attributes(), _Sign.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -15149,18 +15155,18 @@ def sin( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Sin( _Sin.Attributes(), _Sin.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -15190,18 +15196,18 @@ def sinh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Sinh( _Sinh.Attributes(), _Sinh.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -15233,18 +15239,18 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _Size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .size ) @@ -15362,6 +15368,13 @@ def slice( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + "starts": get_value(starts), + "ends": get_value(ends), + "axes": get_value(axes), + "steps": get_value(steps), + } return ( _Slice( _Slice.Attributes(), @@ -15372,16 +15385,9 @@ def slice( axes=unwrap_vars(axes), steps=unwrap_vars(steps), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "starts": get_value(starts), - "ends": get_value(ends), - "axes": get_value(axes), - "steps": get_value(steps), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -15426,6 +15432,9 @@ def softmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Softmax( _Softmax.Attributes( @@ -15434,12 +15443,9 @@ def softmax( _Softmax.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -15553,6 +15559,11 @@ def softmax_cross_entropy_loss( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "scores": get_value(scores), + "labels": get_value(labels), + "weights": get_value(weights), + } return ( _SoftmaxCrossEntropyLoss( _SoftmaxCrossEntropyLoss.Attributes( @@ -15564,14 +15575,9 @@ def softmax_cross_entropy_loss( labels=unwrap_vars(labels), weights=unwrap_vars(weights), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "scores": get_value(scores), - "labels": get_value(labels), - "weights": get_value(weights), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -15603,18 +15609,18 @@ def softplus( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Softplus( _Softplus.Attributes(), _Softplus.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -15646,18 +15652,18 @@ def softsign( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Softsign( _Softsign.Attributes(), _Softsign.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -15696,6 +15702,9 @@ def space_to_depth( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _SpaceToDepth( _SpaceToDepth.Attributes( @@ -15704,12 +15713,9 @@ def space_to_depth( _SpaceToDepth.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -15756,6 +15762,10 @@ def split( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "split": get_value(split), + } return ( _Split( _Split.Attributes( @@ -15766,13 +15776,9 @@ def split( split=unwrap_vars(split), ), out_variadic=outputs_count, + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "split": get_value(split), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .outputs ) @@ -15832,6 +15838,10 @@ def split_to_sequence( - I: `tensor(int32)`, `tensor(int64)` - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ + input_prop_values = { + "input": get_value(input), + "split": get_value(split), + } return ( _SplitToSequence( _SplitToSequence.Attributes( @@ -15842,13 +15852,9 @@ def split_to_sequence( input=unwrap_vars(input), split=unwrap_vars(split), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "split": get_value(split), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output_sequence ) @@ -15880,18 +15886,18 @@ def sqrt( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Sqrt( _Sqrt.Attributes(), _Sqrt.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -15931,6 +15937,10 @@ def squeeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _Squeeze( _Squeeze.Attributes(), @@ -15938,13 +15948,9 @@ def squeeze( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .squeezed ) @@ -16001,6 +16007,9 @@ def string_normalizer( Signature: ``ai.onnx@10::StringNormalizer``. """ + input_prop_values = { + "X": get_value(X), + } return ( _StringNormalizer( _StringNormalizer.Attributes( @@ -16016,12 +16025,9 @@ def string_normalizer( _StringNormalizer.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -16063,6 +16069,10 @@ def sub( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Sub( _Sub.Attributes(), @@ -16070,13 +16080,9 @@ def sub( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -16110,18 +16116,18 @@ def sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "data_0": get_value(data_0), + } return ( _Sum( _Sum.Attributes(), _Sum.Inputs( data_0=unwrap_vars(data_0), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data_0": get_value(data_0), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .sum ) @@ -16151,18 +16157,18 @@ def tan( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Tan( _Tan.Attributes(), _Tan.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -16193,18 +16199,18 @@ def tanh( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Tanh( _Tanh.Attributes(), _Tanh.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -16338,6 +16344,9 @@ def tf_idf_vectorizer( - T: `tensor(int32)`, `tensor(int64)`, `tensor(string)` - T1: `tensor(float)` """ + input_prop_values = { + "X": get_value(X), + } return ( _TfIdfVectorizer( _TfIdfVectorizer.Attributes( @@ -16354,12 +16363,9 @@ def tf_idf_vectorizer( _TfIdfVectorizer.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -16396,6 +16402,9 @@ def thresholded_relu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _ThresholdedRelu( _ThresholdedRelu.Attributes( @@ -16404,12 +16413,9 @@ def thresholded_relu( _ThresholdedRelu.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -16448,6 +16454,10 @@ def tile( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ + input_prop_values = { + "input": get_value(input), + "repeats": get_value(repeats), + } return ( _Tile( _Tile.Attributes(), @@ -16455,13 +16465,9 @@ def tile( input=unwrap_vars(input), repeats=unwrap_vars(repeats), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "repeats": get_value(repeats), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -16541,6 +16547,10 @@ def top_k( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - I: `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + "K": get_value(K), + } return ( _TopK( _TopK.Attributes( @@ -16552,13 +16562,9 @@ def top_k( X=unwrap_vars(X), K=unwrap_vars(K), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "K": get_value(K), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -16596,6 +16602,9 @@ def transpose( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + } return ( _Transpose( _Transpose.Attributes( @@ -16604,12 +16613,9 @@ def transpose( _Transpose.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .transposed ) @@ -16667,6 +16673,10 @@ def trilu( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "k": get_value(k), + } return ( _Trilu( _Trilu.Attributes( @@ -16676,13 +16686,9 @@ def trilu( input=unwrap_vars(input), k=unwrap_vars(k), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "k": get_value(k), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -16856,6 +16862,9 @@ def unique( Type constraints: - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Unique( _Unique.Attributes( @@ -16865,12 +16874,9 @@ def unique( _Unique.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) @@ -16920,6 +16926,10 @@ def unsqueeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _Unsqueeze( _Unsqueeze.Attributes(), @@ -16927,13 +16937,9 @@ def unsqueeze( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .expanded ) @@ -16979,6 +16985,11 @@ def where( - B: `tensor(bool)` - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "condition": get_value(condition), + "X": get_value(X), + "Y": get_value(Y), + } return ( _Where( _Where.Attributes(), @@ -16987,14 +16998,9 @@ def where( X=unwrap_vars(X), Y=unwrap_vars(Y), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "condition": get_value(condition), - "X": get_value(X), - "Y": get_value(Y), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -17035,6 +17041,10 @@ def xor( - T: `tensor(bool)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Xor( _Xor.Attributes(), @@ -17042,13 +17052,9 @@ def xor( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index 045748dd..1b44f18b 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -934,6 +934,10 @@ def bitwise_and( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _BitwiseAnd( _BitwiseAnd.Attributes(), @@ -941,13 +945,9 @@ def bitwise_and( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -977,18 +977,18 @@ def bitwise_not( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "X": get_value(X), + } return ( _BitwiseNot( _BitwiseNot.Attributes(), _BitwiseNot.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1028,6 +1028,10 @@ def bitwise_or( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _BitwiseOr( _BitwiseOr.Attributes(), @@ -1035,13 +1039,9 @@ def bitwise_or( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -1081,6 +1081,10 @@ def bitwise_xor( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _BitwiseXor( _BitwiseXor.Attributes(), @@ -1088,13 +1092,9 @@ def bitwise_xor( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -1146,6 +1146,10 @@ def center_crop_pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "input_data": get_value(input_data), + "shape": get_value(shape), + } return ( _CenterCropPad( _CenterCropPad.Attributes( @@ -1155,13 +1159,9 @@ def center_crop_pad( input_data=unwrap_vars(input_data), shape=unwrap_vars(shape), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input_data": get_value(input_data), - "shape": get_value(shape), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output_data ) @@ -1246,6 +1246,11 @@ def col2_im( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "image_shape": get_value(image_shape), + "block_shape": get_value(block_shape), + } return ( _Col2Im( _Col2Im.Attributes( @@ -1258,14 +1263,9 @@ def col2_im( image_shape=unwrap_vars(image_shape), block_shape=unwrap_vars(block_shape), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "image_shape": get_value(image_shape), - "block_shape": get_value(block_shape), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1335,6 +1335,11 @@ def group_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "scale": get_value(scale), + "bias": get_value(bias), + } return ( _GroupNormalization( _GroupNormalization.Attributes( @@ -1346,14 +1351,9 @@ def group_normalization( scale=unwrap_vars(scale), bias=unwrap_vars(bias), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "scale": get_value(scale), - "bias": get_value(bias), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1466,6 +1466,9 @@ def lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _LpPool( _LpPool.Attributes( @@ -1480,12 +1483,9 @@ def lp_pool( _LpPool.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1522,18 +1522,18 @@ def mish( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Mish( _Mish.Attributes(), _Mish.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1567,18 +1567,18 @@ def optional_get_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _OptionalGetElement( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1612,18 +1612,18 @@ def optional_has_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - B: `tensor(bool)` """ + input_prop_values = { + "input": get_value(input), + } return ( _OptionalHasElement( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1762,6 +1762,12 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + "pads": get_value(pads), + "constant_value": get_value(constant_value), + "axes": get_value(axes), + } return ( _Pad( _Pad.Attributes( @@ -1773,15 +1779,9 @@ def pad( constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "pads": get_value(pads), - "constant_value": get_value(constant_value), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1839,6 +1839,10 @@ def reduce_l1( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceL1( _ReduceL1.Attributes( @@ -1851,13 +1855,9 @@ def reduce_l1( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -1915,6 +1915,10 @@ def reduce_l2( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceL2( _ReduceL2.Attributes( @@ -1927,13 +1931,9 @@ def reduce_l2( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -1992,6 +1992,10 @@ def reduce_log_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceLogSum( _ReduceLogSum.Attributes( @@ -2004,13 +2008,9 @@ def reduce_log_sum( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -2069,6 +2069,10 @@ def reduce_log_sum_exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceLogSumExp( _ReduceLogSumExp.Attributes( @@ -2081,13 +2085,9 @@ def reduce_log_sum_exp( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -2147,6 +2147,10 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceMax( _ReduceMax.Attributes( @@ -2159,13 +2163,9 @@ def reduce_max( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -2223,6 +2223,10 @@ def reduce_mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceMean( _ReduceMean.Attributes( @@ -2235,13 +2239,9 @@ def reduce_mean( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -2300,6 +2300,10 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceMin( _ReduceMin.Attributes( @@ -2312,13 +2316,9 @@ def reduce_min( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -2376,6 +2376,10 @@ def reduce_prod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceProd( _ReduceProd.Attributes( @@ -2388,13 +2392,9 @@ def reduce_prod( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -2452,6 +2452,10 @@ def reduce_sum_square( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceSumSquare( _ReduceSumSquare.Attributes( @@ -2464,13 +2468,9 @@ def reduce_sum_square( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -2645,6 +2645,12 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "roi": get_value(roi), + "scales": get_value(scales), + "sizes": get_value(sizes), + } return ( _Resize( _Resize.Attributes( @@ -2671,15 +2677,9 @@ def resize( scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "roi": get_value(roi), - "scales": get_value(scales), - "sizes": get_value(sizes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -2807,6 +2807,11 @@ def scatter_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + "indices": get_value(indices), + "updates": get_value(updates), + } return ( _ScatterElements( _ScatterElements.Attributes( @@ -2818,14 +2823,9 @@ def scatter_elements( indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "indices": get_value(indices), - "updates": get_value(updates), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -2955,6 +2955,11 @@ def scatter_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "indices": get_value(indices), + "updates": get_value(updates), + } return ( _ScatterND( _ScatterND.Attributes( @@ -2965,14 +2970,9 @@ def scatter_nd( indices=unwrap_vars(indices), updates=unwrap_vars(updates), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "indices": get_value(indices), - "updates": get_value(updates), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -3024,6 +3024,10 @@ def split( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "split": get_value(split), + } return ( _Split( _Split.Attributes( @@ -3035,13 +3039,9 @@ def split( split=unwrap_vars(split), ), out_variadic=num_outputs, + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "split": get_value(split), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .outputs ) diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 1a04da8e..b3ed6c88 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -916,6 +916,9 @@ def average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _AveragePool( _AveragePool.Attributes( @@ -932,12 +935,9 @@ def average_pool( _AveragePool.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1063,6 +1063,9 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Cast( _Cast.Attributes( @@ -1072,12 +1075,9 @@ def cast( _Cast.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1125,6 +1125,10 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "target_type": get_value(target_type), + } return ( _CastLike( _CastLike.Attributes( @@ -1134,13 +1138,9 @@ def cast_like( input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "target_type": get_value(target_type), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1200,6 +1200,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = {} return ( _Constant( _Constant.Attributes( @@ -1212,8 +1213,9 @@ def constant( value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), _Constant.Inputs(), + input_prop_values=input_prop_values, ) - .get_output_vars(input_prop_values={}) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1314,6 +1316,13 @@ def deform_conv( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "W": get_value(W), + "offset": get_value(offset), + "B": get_value(B), + "mask": get_value(mask), + } return ( _DeformConv( _DeformConv.Attributes( @@ -1331,16 +1340,9 @@ def deform_conv( B=unwrap_vars(B), mask=unwrap_vars(mask), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "W": get_value(W), - "offset": get_value(offset), - "B": get_value(B), - "mask": get_value(mask), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1400,6 +1402,11 @@ def dequantize_linear( - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "x": get_value(x), + "x_scale": get_value(x_scale), + "x_zero_point": get_value(x_zero_point), + } return ( _DequantizeLinear( _DequantizeLinear.Attributes( @@ -1410,14 +1417,9 @@ def dequantize_linear( x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "x_scale": get_value(x_scale), - "x_zero_point": get_value(x_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -1458,6 +1460,10 @@ def equal( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ + input_prop_values = { + "A": get_value(A), + "B": get_value(B), + } return ( _Equal( _Equal.Attributes(), @@ -1465,13 +1471,9 @@ def equal( A=unwrap_vars(A), B=unwrap_vars(B), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "A": get_value(A), - "B": get_value(B), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .C ) @@ -1501,18 +1503,18 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1571,6 +1573,9 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) + input_prop_values = { + "cond": get_value(cond), + } return ( _If( _If.Attributes( @@ -1581,12 +1586,9 @@ def if_( cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "cond": get_value(cond), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .outputs ) @@ -1772,6 +1774,11 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) + input_prop_values = { + "M": get_value(M), + "cond": get_value(cond), + "v_initial": get_value(v_initial), + } return ( _Loop( _Loop.Attributes( @@ -1783,14 +1790,9 @@ def loop( v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "M": get_value(M), - "cond": get_value(cond), - "v_initial": get_value(v_initial), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs ) @@ -1955,6 +1957,12 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + "pads": get_value(pads), + "constant_value": get_value(constant_value), + "axes": get_value(axes), + } return ( _Pad( _Pad.Attributes( @@ -1966,15 +1974,9 @@ def pad( constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "pads": get_value(pads), - "constant_value": get_value(constant_value), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -2045,6 +2047,11 @@ def quantize_linear( - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ + input_prop_values = { + "x": get_value(x), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } return ( _QuantizeLinear( _QuantizeLinear.Attributes( @@ -2056,14 +2063,9 @@ def quantize_linear( y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -2119,6 +2121,10 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "shape": get_value(shape), + } return ( _Reshape( _Reshape.Attributes( @@ -2128,13 +2134,9 @@ def reshape( data=unwrap_vars(data), shape=unwrap_vars(shape), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "shape": get_value(shape), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reshaped ) @@ -2347,6 +2349,12 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "roi": get_value(roi), + "scales": get_value(scales), + "sizes": get_value(sizes), + } return ( _Resize( _Resize.Attributes( @@ -2373,15 +2381,9 @@ def resize( scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "roi": get_value(roi), - "scales": get_value(scales), - "sizes": get_value(sizes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -2607,6 +2609,9 @@ def scan( ], body, ) + input_prop_values = { + "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), + } return ( _Scan( _Scan.Attributes( @@ -2631,14 +2636,9 @@ def scan( ), ), out_variadic=len(_body_subgraph.requested_results), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "initial_state_and_scan_inputs": get_value( - initial_state_and_scan_inputs - ), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs ) @@ -2719,6 +2719,9 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _Shape( _Shape.Attributes( @@ -2728,12 +2731,9 @@ def shape( _Shape.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .shape ) @@ -2765,18 +2765,18 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _Size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .size ) diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index c25ec41c..45531a05 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -733,6 +733,10 @@ def affine_grid( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ + input_prop_values = { + "theta": get_value(theta), + "size": get_value(size), + } return ( _AffineGrid( _AffineGrid.Attributes( @@ -742,13 +746,9 @@ def affine_grid( theta=unwrap_vars(theta), size=unwrap_vars(size), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "theta": get_value(theta), - "size": get_value(size), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .grid ) @@ -790,6 +790,9 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _ConstantOfShape( _ConstantOfShape.Attributes( @@ -798,12 +801,9 @@ def constant_of_shape( _ConstantOfShape.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -898,6 +898,11 @@ def dft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "input": get_value(input), + "dft_length": get_value(dft_length), + "axis": get_value(axis), + } return ( _DFT( _DFT.Attributes( @@ -909,14 +914,9 @@ def dft( dft_length=unwrap_vars(dft_length), axis=unwrap_vars(axis), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "dft_length": get_value(dft_length), - "axis": get_value(axis), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -959,6 +959,9 @@ def gelu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + } return ( _Gelu( _Gelu.Attributes( @@ -967,12 +970,9 @@ def gelu( _Gelu.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1079,6 +1079,10 @@ def grid_sample( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "grid": get_value(grid), + } return ( _GridSample( _GridSample.Attributes( @@ -1090,13 +1094,9 @@ def grid_sample( X=unwrap_vars(X), grid=unwrap_vars(grid), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "grid": get_value(grid), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1159,6 +1159,9 @@ def image_decoder( - T1: `tensor(uint8)` - T2: `tensor(uint8)` """ + input_prop_values = { + "encoded_stream": get_value(encoded_stream), + } return ( _ImageDecoder( _ImageDecoder.Attributes( @@ -1167,12 +1170,9 @@ def image_decoder( _ImageDecoder.Inputs( encoded_stream=unwrap_vars(encoded_stream), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "encoded_stream": get_value(encoded_stream), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .image ) @@ -1216,6 +1216,9 @@ def isinf( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - T2: `tensor(bool)` """ + input_prop_values = { + "X": get_value(X), + } return ( _IsInf( _IsInf.Attributes( @@ -1225,12 +1228,9 @@ def isinf( _IsInf.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1261,18 +1261,18 @@ def isnan( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - T2: `tensor(bool)` """ + input_prop_values = { + "X": get_value(X), + } return ( _IsNaN( _IsNaN.Attributes(), _IsNaN.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1335,6 +1335,10 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceMax( _ReduceMax.Attributes( @@ -1347,13 +1351,9 @@ def reduce_max( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -1415,6 +1415,10 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _ReduceMin( _ReduceMin.Attributes( @@ -1427,13 +1431,9 @@ def reduce_min( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reduced ) @@ -1474,6 +1474,9 @@ def regex_full_match( - T1: `tensor(string)` - T2: `tensor(bool)` """ + input_prop_values = { + "X": get_value(X), + } return ( _RegexFullMatch( _RegexFullMatch.Attributes( @@ -1482,12 +1485,9 @@ def regex_full_match( _RegexFullMatch.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1522,6 +1522,10 @@ def string_concat( Type constraints: - T: `tensor(string)` """ + input_prop_values = { + "X": get_value(X), + "Y": get_value(Y), + } return ( _StringConcat( _StringConcat.Attributes(), @@ -1529,13 +1533,9 @@ def string_concat( X=unwrap_vars(X), Y=unwrap_vars(Y), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "Y": get_value(Y), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Z ) @@ -1609,6 +1609,9 @@ def string_split( - T2: `tensor(string)` - T3: `tensor(int64)` """ + input_prop_values = { + "X": get_value(X), + } return ( _StringSplit( _StringSplit.Attributes( @@ -1618,12 +1621,9 @@ def string_split( _StringSplit.Inputs( X=unwrap_vars(X), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - } - ) + .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() ) diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 6867ef46..08242da7 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -964,6 +964,9 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Cast( _Cast.Attributes( @@ -973,12 +976,9 @@ def cast( _Cast.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1026,6 +1026,10 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + "target_type": get_value(target_type), + } return ( _CastLike( _CastLike.Attributes( @@ -1035,13 +1039,9 @@ def cast_like( input=unwrap_vars(input), target_type=unwrap_vars(target_type), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - "target_type": get_value(target_type), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1101,6 +1101,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = {} return ( _Constant( _Constant.Attributes( @@ -1113,8 +1114,9 @@ def constant( value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), _Constant.Inputs(), + input_prop_values=input_prop_values, ) - .get_output_vars(input_prop_values={}) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1156,6 +1158,9 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _ConstantOfShape( _ConstantOfShape.Attributes( @@ -1164,12 +1169,9 @@ def constant_of_shape( _ConstantOfShape.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1242,6 +1244,11 @@ def dequantize_linear( - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "x": get_value(x), + "x_scale": get_value(x_scale), + "x_zero_point": get_value(x_zero_point), + } return ( _DequantizeLinear( _DequantizeLinear.Attributes( @@ -1253,14 +1260,9 @@ def dequantize_linear( x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "x_scale": get_value(x_scale), - "x_zero_point": get_value(x_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -1304,6 +1306,9 @@ def flatten( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Flatten( _Flatten.Attributes( @@ -1312,12 +1317,9 @@ def flatten( _Flatten.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1401,6 +1403,11 @@ def group_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ + input_prop_values = { + "X": get_value(X), + "scale": get_value(scale), + "bias": get_value(bias), + } return ( _GroupNormalization( _GroupNormalization.Attributes( @@ -1413,14 +1420,9 @@ def group_normalization( scale=unwrap_vars(scale), bias=unwrap_vars(bias), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "X": get_value(X), - "scale": get_value(scale), - "bias": get_value(bias), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .Y ) @@ -1450,18 +1452,18 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "input": get_value(input), + } return ( _Identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "input": get_value(input), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -1520,6 +1522,9 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) + input_prop_values = { + "cond": get_value(cond), + } return ( _If( _If.Attributes( @@ -1530,12 +1535,9 @@ def if_( cond=unwrap_vars(cond), ), out_variadic=len(_else_branch_subgraph.requested_results), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "cond": get_value(cond), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .outputs ) @@ -1721,6 +1723,11 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) + input_prop_values = { + "M": get_value(M), + "cond": get_value(cond), + "v_initial": get_value(v_initial), + } return ( _Loop( _Loop.Attributes( @@ -1732,14 +1739,9 @@ def loop( v_initial=unwrap_vars(v_initial), ), out_variadic=len(_body_subgraph.requested_results) - 1, + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "M": get_value(M), - "cond": get_value(cond), - "v_initial": get_value(v_initial), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs ) @@ -1904,6 +1906,12 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + "pads": get_value(pads), + "constant_value": get_value(constant_value), + "axes": get_value(axes), + } return ( _Pad( _Pad.Attributes( @@ -1915,15 +1923,9 @@ def pad( constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "pads": get_value(pads), - "constant_value": get_value(constant_value), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .output ) @@ -2001,6 +2003,16 @@ def qlinear_matmul( - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` - T3: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ + input_prop_values = { + "a": get_value(a), + "a_scale": get_value(a_scale), + "a_zero_point": get_value(a_zero_point), + "b": get_value(b), + "b_scale": get_value(b_scale), + "b_zero_point": get_value(b_zero_point), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } return ( _QLinearMatMul( _QLinearMatMul.Attributes(), @@ -2014,19 +2026,9 @@ def qlinear_matmul( y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "a": get_value(a), - "a_scale": get_value(a_scale), - "a_zero_point": get_value(a_zero_point), - "b": get_value(b), - "b_scale": get_value(b_scale), - "b_zero_point": get_value(b_zero_point), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -2136,6 +2138,11 @@ def quantize_linear( - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` """ + input_prop_values = { + "x": get_value(x), + "y_scale": get_value(y_scale), + "y_zero_point": get_value(y_zero_point), + } return ( _QuantizeLinear( _QuantizeLinear.Attributes( @@ -2149,14 +2156,9 @@ def quantize_linear( y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "x": get_value(x), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .y ) @@ -2212,6 +2214,10 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "shape": get_value(shape), + } return ( _Reshape( _Reshape.Attributes( @@ -2221,13 +2227,9 @@ def reshape( data=unwrap_vars(data), shape=unwrap_vars(shape), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "shape": get_value(shape), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .reshaped ) @@ -2453,6 +2455,9 @@ def scan( ], body, ) + input_prop_values = { + "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), + } return ( _Scan( _Scan.Attributes( @@ -2477,14 +2482,9 @@ def scan( ), ), out_variadic=len(_body_subgraph.requested_results), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "initial_state_and_scan_inputs": get_value( - initial_state_and_scan_inputs - ), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs ) @@ -2565,6 +2565,9 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _Shape( _Shape.Attributes( @@ -2574,12 +2577,9 @@ def shape( _Shape.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .shape ) @@ -2611,18 +2611,18 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ + input_prop_values = { + "data": get_value(data), + } return ( _Size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .size ) @@ -2662,6 +2662,10 @@ def squeeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _Squeeze( _Squeeze.Attributes(), @@ -2669,13 +2673,9 @@ def squeeze( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .squeezed ) @@ -2714,6 +2714,9 @@ def transpose( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + } return ( _Transpose( _Transpose.Attributes( @@ -2722,12 +2725,9 @@ def transpose( _Transpose.Inputs( data=unwrap_vars(data), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .transposed ) @@ -2777,6 +2777,10 @@ def unsqueeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ + input_prop_values = { + "data": get_value(data), + "axes": get_value(axes), + } return ( _Unsqueeze( _Unsqueeze.Attributes(), @@ -2784,13 +2788,9 @@ def unsqueeze( data=unwrap_vars(data), axes=unwrap_vars(axes), ), + input_prop_values=input_prop_values, ) - .get_output_vars( - input_prop_values={ - "data": get_value(data), - "axes": get_value(axes), - } - ) + .get_output_vars(input_prop_values=input_prop_values) .expanded ) diff --git a/tests/test_custom_operator.py b/tests/test_custom_operator.py index f06b1b56..b4e178ae 100644 --- a/tests/test_custom_operator.py +++ b/tests/test_custom_operator.py @@ -69,7 +69,7 @@ def propagate_values(self, initializers) -> dict[str, np.ndarray]: def inverse(matrix: Var) -> Var: return ( Inverse(Inverse.Attributes(), Inverse.Inputs(matrix._var_info)) - .get_output_vars(X=matrix._value) + .get_output_vars(input_prop_values={"X": matrix._value}) .Y ) diff --git a/tests/test_function.py b/tests/test_function.py index aa37790c..aa7d7c08 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -70,7 +70,7 @@ def linear_inner( ), LinearFunction.Inputs(x._var_info), ) - .get_output_vars(X=x._value) + .get_output_vars(input_prop_values={"x": x._value}) .Y ) diff --git a/tools/generate_opset.py b/tools/generate_opset.py index 7d1a9e95..399a311f 100644 --- a/tools/generate_opset.py +++ b/tools/generate_opset.py @@ -647,7 +647,7 @@ def main( if pre_commit_hooks: print("Running pre-commit hooks to format & verify...") - if False and run_pre_commit_hooks(str(path)).returncode: + if run_pre_commit_hooks(str(path)).returncode: print("Running second pass of pre-commit hooks...") if run_pre_commit_hooks(str(path)).returncode: raise RuntimeError( diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index d3cfcb92..3b0ad1ab 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -14,6 +14,11 @@ _{{ attr.name }}_subgraph: Graph = subgraph( ) {% endif %} {% endfor %} +input_prop_values = { +{% for param in schema.inputs + %}"{{param.name}}":get_value({{param.name}}), {% +endfor %} + } return _{{ schema.name }}( _{{ schema.name }}.Attributes( {% for attr in attributes %} @@ -36,11 +41,9 @@ endfor %} ), {% if schema.outputs and is_variadic(schema.outputs[-1]) %}out_variadic={{ out_variadic_solution if out_variadic_solution else "{}_count".format(schema.outputs[-1].name) }}, {% -endif %}).get_output_vars(input_prop_values={ -{% for param in schema.inputs - %}"{{param.name}}":get_value({{param.name}}), {% -endfor %} - }){% +endif %} + input_prop_values=input_prop_values + ).get_output_vars(input_prop_values=input_prop_values){% if schema.outputs | length <= 1 %}.{{ schema.outputs[0].name }}{% else %}._unpack_to_any(){% From 3d77a87091763206a2f23c1c8a6e4ad6c12f80f6 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 6 Nov 2024 18:12:55 +0200 Subject: [PATCH 14/29] Hacky fix mypy --- src/spox/_node.py | 7 +- src/spox/_standard.py | 16 +- src/spox/_type_system.py | 5 +- src/spox/opset/ai/onnx/ml/v3.py | 42 ++-- src/spox/opset/ai/onnx/ml/v4.py | 7 +- src/spox/opset/ai/onnx/ml/v5.py | 7 +- src/spox/opset/ai/onnx/v17.py | 359 +++++++++++++++---------------- src/spox/opset/ai/onnx/v18.py | 55 +++-- src/spox/opset/ai/onnx/v19.py | 41 ++-- src/spox/opset/ai/onnx/v20.py | 31 ++- src/spox/opset/ai/onnx/v21.py | 47 ++-- tools/templates/construct.jinja2 | 2 +- tools/templates/preamble.jinja2 | 4 +- 13 files changed, 306 insertions(+), 317 deletions(-) diff --git a/src/spox/_node.py b/src/spox/_node.py index 96d899ed..75ddf178 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -18,8 +18,7 @@ from ._debug import STORE_TRACEBACK from ._exceptions import InferenceWarning from ._fields import BaseAttributes, BaseInputs, BaseOutputs, VarFieldKind -from ._type_system import Type -from ._value_prop import PropValueType +from ._type_system import PropDict, Type from ._var import VarInfo if typing.TYPE_CHECKING: @@ -95,7 +94,7 @@ def __init__( out_variadic: Optional[int] = None, infer_types: bool = True, validate: bool = True, - input_prop_values={}, + input_prop_values: PropDict = {}, **kwargs, ): """ @@ -207,7 +206,7 @@ def pre_init(self, **kwargs): def post_init(self, **kwargs): """Post-initialization hook. Called at the end of ``__init__`` after other default fields are set.""" - def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values: PropDict) -> PropDict: """ Propagate values from inputs, and, if possible, compute values for outputs as well. This method is used to implement ONNX partial data propagation - for example so that diff --git a/src/spox/_standard.py b/src/spox/_standard.py index 15ed0bb6..ecfada81 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -17,7 +17,7 @@ from ._schemas import SCHEMAS from ._scope import Scope from ._shape import SimpleShape -from ._type_system import Optional, Sequence, Tensor, Type +from ._type_system import Optional, PropDict, Sequence, Tensor, Type from ._utils import from_array from ._value_prop import PropValue, PropValueType @@ -54,7 +54,7 @@ def to_singleton_onnx_model( *, dummy_outputs: bool = True, with_dummy_subgraphs: bool = True, - prop_values={}, + input_prop_values: PropDict = {}, ) -> tuple[onnx.ModelProto, Scope]: """ Build a singleton model consisting of just this StandardNode. Used for type inference. @@ -107,7 +107,7 @@ def out_value_info(curr_key, curr_var): # TODO: fix this initializers_from_array = [ from_array(prop.value, name) # type: ignore - for name, prop in prop_values.items() + for name, prop in input_prop_values.items() if isinstance(prop, PropValue) and prop.value is not None and not isinstance(prop.type, Sequence) @@ -115,7 +115,7 @@ def out_value_info(curr_key, curr_var): initializers_from_sequence = [ from_array(prop.value, f"{name}_{i}") # type: ignore - for name, prop_list in prop_values.items() + for name, prop_list in input_prop_values.items() if isinstance(prop_list, list) for i, prop in enumerate(prop_list) if prop is not None and not isinstance(prop.value, Iterable) @@ -149,7 +149,7 @@ def infer_output_types_onnx(self, input_prop_values={}) -> dict[str, Type]: if any(var.type is None for var in self.inputs.get_var_infos().values()): return {} - model, _ = self.to_singleton_onnx_model(prop_values=input_prop_values) + model, _ = self.to_singleton_onnx_model(input_prop_values=input_prop_values) # Attempt to do shape inference - if an error is caught, we extend the traceback a bit try: @@ -173,7 +173,9 @@ def infer_output_types_onnx(self, input_prop_values={}) -> dict[str, Type]: for key, type_ in results.items() } - def propagate_values_onnx(self, input_prop_values) -> dict[str, PropValueType]: + def propagate_values_onnx( + self, input_prop_values: PropDict + ) -> dict[str, PropValueType]: """Perform value propagation by evaluating singleton model. The backend used for the propagation can be configured with the `spox._standard.ValuePropBackend` variable. @@ -188,7 +190,7 @@ def propagate_values_onnx(self, input_prop_values) -> dict[str, PropValueType]: # Cannot do propagation with subgraphs implicitly for performance - should be reimplemented return {} model, scope = self.to_singleton_onnx_model( - with_dummy_subgraphs=False, prop_values=input_prop_values + with_dummy_subgraphs=False, input_prop_values=input_prop_values ) wrap_feed, run, unwrap_feed = _value_prop.get_backend_calls() input_feed = { diff --git a/src/spox/_type_system.py b/src/spox/_type_system.py index 27c2695b..6450f839 100644 --- a/src/spox/_type_system.py +++ b/src/spox/_type_system.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause from dataclasses import dataclass -from typing import TypeVar +from typing import Any, TypeVar import numpy as np import numpy.typing as npt @@ -14,6 +14,9 @@ T = TypeVar("T") S = TypeVar("S") +# TODO: Fix typing +PropDict = dict[str, Any] + @dataclass(frozen=True) class Type: diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index 161ac890..47a3f1a5 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -4,9 +4,7 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import ( - Optional, -) +from typing import Optional import numpy as np @@ -22,7 +20,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type +from spox._type_system import PropDict, Tensor, Type from spox._var import Var, VarInfo, get_value, unwrap_vars @@ -662,7 +660,7 @@ def array_feature_extractor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "Y": get_value(Y), } @@ -711,7 +709,7 @@ def binarizer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -776,7 +774,7 @@ def cast_map( - T1: `map(int64,tensor(float))`, `map(int64,tensor(string))` - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -851,7 +849,7 @@ def category_mapper( - T1: `tensor(int64)`, `tensor(string)` - T2: `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -922,7 +920,7 @@ def dict_vectorizer( - T1: `map(int64,tensor(double))`, `map(int64,tensor(float))`, `map(int64,tensor(string))`, `map(string,tensor(double))`, `map(string,tensor(float))`, `map(string,tensor(int64))` - T2: `tensor(double)`, `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -979,7 +977,7 @@ def feature_vectorizer( Type constraints: - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1054,7 +1052,7 @@ def imputer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1163,7 +1161,7 @@ def label_encoder( - T1: `tensor(float)`, `tensor(int64)`, `tensor(string)` - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1246,7 +1244,7 @@ def linear_classifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1322,7 +1320,7 @@ def linear_regressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1379,7 +1377,7 @@ def normalizer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1446,7 +1444,7 @@ def one_hot_encoder( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1548,7 +1546,7 @@ def svmclassifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1645,7 +1643,7 @@ def svmregressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1711,7 +1709,7 @@ def scaler( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1864,7 +1862,7 @@ def tree_ensemble_classifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -2057,7 +2055,7 @@ def tree_ensemble_regressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -2158,7 +2156,7 @@ def zip_map( Type constraints: - T: `seq(map(int64,tensor(float)))`, `seq(map(string,tensor(float)))` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index a4f6dec9..e7cfc723 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -4,9 +4,7 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable from dataclasses import dataclass -from typing import ( - Optional, -) +from typing import Optional import numpy as np @@ -22,6 +20,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode +from spox._type_system import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.ml.v3 import ( _ArrayFeatureExtractor, @@ -191,7 +190,7 @@ def label_encoder( - T1: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` - T2: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index 529b2a10..5ff61e47 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -4,9 +4,7 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable from dataclasses import dataclass -from typing import ( - Optional, -) +from typing import Optional import numpy as np @@ -18,6 +16,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode +from spox._type_system import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.ml.v4 import ( _ArrayFeatureExtractor, @@ -224,7 +223,7 @@ def tree_ensemble( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 40244e54..128d5bfb 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -4,10 +4,7 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import ( - Callable, - Optional, -) +from typing import Callable, Optional from typing import cast as typing_cast import numpy as np @@ -29,8 +26,8 @@ from spox._graph import Graph, subgraph from spox._node import OpType from spox._standard import InferenceError, StandardNode +from spox._type_system import PropDict, Tensor, Type from spox._type_system import Sequence as SpoxSequence -from spox._type_system import Tensor, Type from spox._value_prop import PropValueType from spox._var import Var, VarInfo, get_value, unwrap_vars @@ -3958,7 +3955,7 @@ def abs( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -4000,7 +3997,7 @@ def acos( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -4043,7 +4040,7 @@ def acosh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -4096,7 +4093,7 @@ def add( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -4150,7 +4147,7 @@ def and_( - T: `tensor(bool)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -4216,7 +4213,7 @@ def arg_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -4286,7 +4283,7 @@ def arg_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -4334,7 +4331,7 @@ def asin( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -4376,7 +4373,7 @@ def asinh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -4418,7 +4415,7 @@ def atan( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -4461,7 +4458,7 @@ def atanh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -4598,7 +4595,7 @@ def average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -4743,7 +4740,7 @@ def batch_normalization( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "scale": get_value(scale), "B": get_value(B), @@ -4816,7 +4813,7 @@ def bernoulli( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -4885,7 +4882,7 @@ def bit_shift( Type constraints: - T: `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "Y": get_value(Y), } @@ -4946,7 +4943,7 @@ def blackman_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "size": get_value(size), } return ( @@ -5047,7 +5044,7 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -5099,7 +5096,7 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "target_type": get_value(target_type), } @@ -5145,7 +5142,7 @@ def ceil( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -5197,7 +5194,7 @@ def celu( Type constraints: - T: `tensor(float)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -5252,7 +5249,7 @@ def clip( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "min": get_value(min), "max": get_value(max), @@ -5318,7 +5315,7 @@ def compress( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "condition": get_value(condition), } @@ -5371,7 +5368,7 @@ def concat( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "inputs": get_value(inputs), } return ( @@ -5431,7 +5428,7 @@ def concat_from_sequence( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input_sequence": get_value(input_sequence), } return ( @@ -5505,7 +5502,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = {} + input_prop_values: PropDict = {} return ( _Constant( _Constant.Attributes( @@ -5562,7 +5559,7 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -5677,7 +5674,7 @@ def conv( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "W": get_value(W), "B": get_value(B), @@ -5812,7 +5809,7 @@ def conv_integer( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int32)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "w": get_value(w), "x_zero_point": get_value(x_zero_point), @@ -5969,7 +5966,7 @@ def conv_transpose( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "W": get_value(W), "B": get_value(B), @@ -6023,7 +6020,7 @@ def cos( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -6064,7 +6061,7 @@ def cosh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -6145,7 +6142,7 @@ def cumsum( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "axis": get_value(axis), } @@ -6239,7 +6236,7 @@ def dft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "dft_length": get_value(dft_length), } @@ -6323,7 +6320,7 @@ def depth_to_space( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -6392,7 +6389,7 @@ def dequantize_linear( Type constraints: - T: `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "x_scale": get_value(x_scale), "x_zero_point": get_value(x_zero_point), @@ -6444,7 +6441,7 @@ def det( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -6497,7 +6494,7 @@ def div( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -6591,7 +6588,7 @@ def dropout( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "ratio": get_value(ratio), "training_mode": get_value(training_mode), @@ -6680,7 +6677,7 @@ def dynamic_quantize_linear( - T1: `tensor(float)` - T2: `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), } return ( @@ -6758,7 +6755,7 @@ def einsum( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "Inputs": get_value(Inputs), } return ( @@ -6809,7 +6806,7 @@ def elu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -6863,7 +6860,7 @@ def equal( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -6907,7 +6904,7 @@ def erf( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -6948,7 +6945,7 @@ def exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -7002,7 +6999,7 @@ def expand( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "shape": get_value(shape), } @@ -7068,7 +7065,7 @@ def eye_like( - T1: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -7126,7 +7123,7 @@ def flatten( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -7172,7 +7169,7 @@ def floor( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -7360,7 +7357,7 @@ def gru( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "W": get_value(W), "R": get_value(R), @@ -7487,7 +7484,7 @@ def gather( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "indices": get_value(indices), } @@ -7601,7 +7598,7 @@ def gather_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "indices": get_value(indices), } @@ -7760,7 +7757,7 @@ def gather_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "indices": get_value(indices), } @@ -7853,7 +7850,7 @@ def gemm( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), "C": get_value(C), @@ -7912,7 +7909,7 @@ def global_average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -7967,7 +7964,7 @@ def global_lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -8019,7 +8016,7 @@ def global_max_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -8071,7 +8068,7 @@ def greater( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -8125,7 +8122,7 @@ def greater_or_equal( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -8225,7 +8222,7 @@ def grid_sample( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "grid": get_value(grid), } @@ -8288,7 +8285,7 @@ def hamming_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "size": get_value(size), } return ( @@ -8348,7 +8345,7 @@ def hann_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "size": get_value(size), } return ( @@ -8403,7 +8400,7 @@ def hard_sigmoid( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -8450,7 +8447,7 @@ def hard_swish( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -8505,7 +8502,7 @@ def hardmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -8548,7 +8545,7 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -8618,7 +8615,7 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - input_prop_values = { + input_prop_values: PropDict = { "cond": get_value(cond), } return ( @@ -8684,7 +8681,7 @@ def instance_normalization( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "scale": get_value(scale), "B": get_value(B), @@ -8745,7 +8742,7 @@ def isinf( - T1: `tensor(double)`, `tensor(float)` - T2: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -8790,7 +8787,7 @@ def isnan( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -8865,7 +8862,7 @@ def lrn( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -9080,7 +9077,7 @@ def lstm( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "W": get_value(W), "R": get_value(R), @@ -9206,7 +9203,7 @@ def layer_normalization( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - U: `tensor(bfloat16)`, `tensor(float)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "Scale": get_value(Scale), "B": get_value(B), @@ -9263,7 +9260,7 @@ def leaky_relu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -9317,7 +9314,7 @@ def less( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -9371,7 +9368,7 @@ def less_or_equal( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -9414,7 +9411,7 @@ def log( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -9468,7 +9465,7 @@ def log_softmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -9667,7 +9664,7 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - input_prop_values = { + input_prop_values: PropDict = { "M": get_value(M), "cond": get_value(cond), "v_initial": get_value(v_initial), @@ -9724,7 +9721,7 @@ def lp_normalization( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -9814,7 +9811,7 @@ def lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -9866,7 +9863,7 @@ def matmul( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -9936,7 +9933,7 @@ def matmul_integer( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int32)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), "a_zero_point": get_value(a_zero_point), @@ -9987,7 +9984,7 @@ def max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data_0": get_value(data_0), } return ( @@ -10140,7 +10137,7 @@ def max_pool( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int8)`, `tensor(uint8)` - I: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -10209,7 +10206,7 @@ def max_roi_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "rois": get_value(rois), } @@ -10326,7 +10323,7 @@ def max_unpool( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "I": get_value(I), "output_shape": get_value(output_shape), @@ -10379,7 +10376,7 @@ def mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "data_0": get_value(data_0), } return ( @@ -10430,7 +10427,7 @@ def mean_variance_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -10522,7 +10519,7 @@ def mel_weight_matrix( - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T3: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "num_mel_bins": get_value(num_mel_bins), "dft_length": get_value(dft_length), "sample_rate": get_value(sample_rate), @@ -10577,7 +10574,7 @@ def min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data_0": get_value(data_0), } return ( @@ -10645,7 +10642,7 @@ def mod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -10702,7 +10699,7 @@ def mul( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -10767,7 +10764,7 @@ def multinomial( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -10814,7 +10811,7 @@ def neg( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -10987,7 +10984,7 @@ def negative_log_likelihood_loss( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "target": get_value(target), "weight": get_value(weight), @@ -11076,7 +11073,7 @@ def non_max_suppression( Signature: ``ai.onnx@11::NonMaxSuppression``. """ - input_prop_values = { + input_prop_values: PropDict = { "boxes": get_value(boxes), "scores": get_value(scores), "max_output_boxes_per_class": get_value(max_output_boxes_per_class), @@ -11131,7 +11128,7 @@ def non_zero( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -11172,7 +11169,7 @@ def not_( Type constraints: - T: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -11269,7 +11266,7 @@ def one_hot( - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T3: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "indices": get_value(indices), "depth": get_value(depth), "values": get_value(values), @@ -11324,7 +11321,7 @@ def optional( - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -11370,7 +11367,7 @@ def optional_get_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -11414,7 +11411,7 @@ def optional_has_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - B: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -11466,7 +11463,7 @@ def or_( - T: `tensor(bool)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -11520,7 +11517,7 @@ def prelu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "slope": get_value(slope), } @@ -11632,7 +11629,7 @@ def pad( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "pads": get_value(pads), "constant_value": get_value(constant_value), @@ -11689,7 +11686,7 @@ def pow( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)` - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "Y": get_value(Y), } @@ -11847,7 +11844,7 @@ def qlinear_conv( - T3: `tensor(int8)`, `tensor(uint8)` - T4: `tensor(int32)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "x_scale": get_value(x_scale), "x_zero_point": get_value(x_zero_point), @@ -11958,7 +11955,7 @@ def qlinear_matmul( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int8)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "a": get_value(a), "a_scale": get_value(a_scale), "a_zero_point": get_value(a_zero_point), @@ -12042,7 +12039,7 @@ def quantize_linear( - T1: `tensor(float)`, `tensor(int32)` - T2: `tensor(int8)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "y_scale": get_value(y_scale), "y_zero_point": get_value(y_zero_point), @@ -12216,7 +12213,7 @@ def rnn( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "W": get_value(W), "R": get_value(R), @@ -12305,7 +12302,7 @@ def random_normal( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = {} + input_prop_values: PropDict = {} return ( _RandomNormal( _RandomNormal.Attributes( @@ -12376,7 +12373,7 @@ def random_normal_like( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -12447,7 +12444,7 @@ def random_uniform( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = {} + input_prop_values: PropDict = {} return ( _RandomUniform( _RandomUniform.Attributes( @@ -12518,7 +12515,7 @@ def random_uniform_like( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -12603,7 +12600,7 @@ def range( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "start": get_value(start), "limit": get_value(limit), "delta": get_value(delta), @@ -12650,7 +12647,7 @@ def reciprocal( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -12710,7 +12707,7 @@ def reduce_l1( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -12773,7 +12770,7 @@ def reduce_l2( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -12837,7 +12834,7 @@ def reduce_log_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -12901,7 +12898,7 @@ def reduce_log_sum_exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -12966,7 +12963,7 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -13029,7 +13026,7 @@ def reduce_mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -13093,7 +13090,7 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -13156,7 +13153,7 @@ def reduce_prod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -13228,7 +13225,7 @@ def reduce_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -13295,7 +13292,7 @@ def reduce_sum_square( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -13341,7 +13338,7 @@ def relu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -13408,7 +13405,7 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "shape": get_value(shape), } @@ -13547,7 +13544,7 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "roi": get_value(roi), "scales": get_value(scales), @@ -13643,7 +13640,7 @@ def reverse_sequence( Type constraints: - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "sequence_lens": get_value(sequence_lens), } @@ -13751,7 +13748,7 @@ def roi_align( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "rois": get_value(rois), "batch_indices": get_value(batch_indices), @@ -13820,7 +13817,7 @@ def round( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -13897,7 +13894,7 @@ def stft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "signal": get_value(signal), "frame_step": get_value(frame_step), "window": get_value(window), @@ -14142,7 +14139,7 @@ def scan( ], body, ) - input_prop_values = { + input_prop_values: PropDict = { "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), } return ( @@ -14296,7 +14293,7 @@ def scatter_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "indices": get_value(indices), "updates": get_value(updates), @@ -14428,7 +14425,7 @@ def scatter_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "indices": get_value(indices), "updates": get_value(updates), @@ -14489,7 +14486,7 @@ def selu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -14546,7 +14543,7 @@ def sequence_at( - I: `tensor(int32)`, `tensor(int64)` - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input_sequence": get_value(input_sequence), "position": get_value(position), } @@ -14591,7 +14588,7 @@ def sequence_construct( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - input_prop_values = { + input_prop_values: PropDict = { "inputs": get_value(inputs), } return ( @@ -14634,7 +14631,7 @@ def sequence_empty( Type constraints: - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - input_prop_values = {} + input_prop_values: PropDict = {} return ( _SequenceEmpty( _SequenceEmpty.Attributes( @@ -14686,7 +14683,7 @@ def sequence_erase( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - I: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input_sequence": get_value(input_sequence), "position": get_value(position), } @@ -14749,7 +14746,7 @@ def sequence_insert( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - I: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input_sequence": get_value(input_sequence), "tensor": get_value(tensor), "position": get_value(position), @@ -14796,7 +14793,7 @@ def sequence_length( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - I: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input_sequence": get_value(input_sequence), } return ( @@ -14872,7 +14869,7 @@ def sequence_map( ], body, ) - input_prop_values = { + input_prop_values: PropDict = { "input_sequence": get_value(input_sequence), "additional_inputs": get_value(additional_inputs), } @@ -14969,7 +14966,7 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -15025,7 +15022,7 @@ def shrink( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -15071,7 +15068,7 @@ def sigmoid( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -15114,7 +15111,7 @@ def sign( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -15155,7 +15152,7 @@ def sin( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -15196,7 +15193,7 @@ def sinh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -15239,7 +15236,7 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -15368,7 +15365,7 @@ def slice( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "starts": get_value(starts), "ends": get_value(ends), @@ -15432,7 +15429,7 @@ def softmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -15559,7 +15556,7 @@ def softmax_cross_entropy_loss( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "scores": get_value(scores), "labels": get_value(labels), "weights": get_value(weights), @@ -15609,7 +15606,7 @@ def softplus( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -15652,7 +15649,7 @@ def softsign( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -15702,7 +15699,7 @@ def space_to_depth( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -15762,7 +15759,7 @@ def split( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "split": get_value(split), } @@ -15838,7 +15835,7 @@ def split_to_sequence( - I: `tensor(int32)`, `tensor(int64)` - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "split": get_value(split), } @@ -15886,7 +15883,7 @@ def sqrt( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -15937,7 +15934,7 @@ def squeeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -16007,7 +16004,7 @@ def string_normalizer( Signature: ``ai.onnx@10::StringNormalizer``. """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -16069,7 +16066,7 @@ def sub( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -16116,7 +16113,7 @@ def sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "data_0": get_value(data_0), } return ( @@ -16157,7 +16154,7 @@ def tan( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -16199,7 +16196,7 @@ def tanh( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -16344,7 +16341,7 @@ def tf_idf_vectorizer( - T: `tensor(int32)`, `tensor(int64)`, `tensor(string)` - T1: `tensor(float)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -16402,7 +16399,7 @@ def thresholded_relu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -16454,7 +16451,7 @@ def tile( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "repeats": get_value(repeats), } @@ -16547,7 +16544,7 @@ def top_k( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - I: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "K": get_value(K), } @@ -16602,7 +16599,7 @@ def transpose( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -16673,7 +16670,7 @@ def trilu( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "k": get_value(k), } @@ -16862,7 +16859,7 @@ def unique( Type constraints: - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -16926,7 +16923,7 @@ def unsqueeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -16985,7 +16982,7 @@ def where( - B: `tensor(bool)` - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "condition": get_value(condition), "X": get_value(X), "Y": get_value(Y), @@ -17041,7 +17038,7 @@ def xor( - T: `tensor(bool)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index 1b44f18b..e785969e 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -4,9 +4,7 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import ( - Optional, -) +from typing import Optional import numpy as np import numpy.typing as npt @@ -20,6 +18,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode +from spox._type_system import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v17 import ( _DFT, @@ -934,7 +933,7 @@ def bitwise_and( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -977,7 +976,7 @@ def bitwise_not( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1028,7 +1027,7 @@ def bitwise_or( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -1081,7 +1080,7 @@ def bitwise_xor( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -1146,7 +1145,7 @@ def center_crop_pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input_data": get_value(input_data), "shape": get_value(shape), } @@ -1246,7 +1245,7 @@ def col2_im( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "image_shape": get_value(image_shape), "block_shape": get_value(block_shape), @@ -1335,7 +1334,7 @@ def group_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "scale": get_value(scale), "bias": get_value(bias), @@ -1466,7 +1465,7 @@ def lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1522,7 +1521,7 @@ def mish( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1567,7 +1566,7 @@ def optional_get_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -1612,7 +1611,7 @@ def optional_has_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - B: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -1762,7 +1761,7 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "pads": get_value(pads), "constant_value": get_value(constant_value), @@ -1839,7 +1838,7 @@ def reduce_l1( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -1915,7 +1914,7 @@ def reduce_l2( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -1992,7 +1991,7 @@ def reduce_log_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -2069,7 +2068,7 @@ def reduce_log_sum_exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -2147,7 +2146,7 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -2223,7 +2222,7 @@ def reduce_mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -2300,7 +2299,7 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -2376,7 +2375,7 @@ def reduce_prod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -2452,7 +2451,7 @@ def reduce_sum_square( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -2645,7 +2644,7 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "roi": get_value(roi), "scales": get_value(scales), @@ -2807,7 +2806,7 @@ def scatter_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "indices": get_value(indices), "updates": get_value(updates), @@ -2955,7 +2954,7 @@ def scatter_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "indices": get_value(indices), "updates": get_value(updates), @@ -3024,7 +3023,7 @@ def split( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "split": get_value(split), } diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index b3ed6c88..95ccfd06 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -4,10 +4,7 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import ( - Callable, - Optional, -) +from typing import Callable, Optional from typing import cast as typing_cast import numpy as np @@ -28,7 +25,7 @@ from spox._graph import Graph, subgraph from spox._node import OpType from spox._standard import StandardNode -from spox._type_system import Tensor, Type +from spox._type_system import PropDict, Tensor, Type from spox._value_prop import PropValueType from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v18 import ( @@ -916,7 +913,7 @@ def average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1063,7 +1060,7 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -1125,7 +1122,7 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "target_type": get_value(target_type), } @@ -1200,7 +1197,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = {} + input_prop_values: PropDict = {} return ( _Constant( _Constant.Attributes( @@ -1316,7 +1313,7 @@ def deform_conv( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "W": get_value(W), "offset": get_value(offset), @@ -1402,7 +1399,7 @@ def dequantize_linear( - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "x_scale": get_value(x_scale), "x_zero_point": get_value(x_zero_point), @@ -1460,7 +1457,7 @@ def equal( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "A": get_value(A), "B": get_value(B), } @@ -1503,7 +1500,7 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -1573,7 +1570,7 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - input_prop_values = { + input_prop_values: PropDict = { "cond": get_value(cond), } return ( @@ -1774,7 +1771,7 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - input_prop_values = { + input_prop_values: PropDict = { "M": get_value(M), "cond": get_value(cond), "v_initial": get_value(v_initial), @@ -1957,7 +1954,7 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "pads": get_value(pads), "constant_value": get_value(constant_value), @@ -2047,7 +2044,7 @@ def quantize_linear( - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "y_scale": get_value(y_scale), "y_zero_point": get_value(y_zero_point), @@ -2121,7 +2118,7 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "shape": get_value(shape), } @@ -2349,7 +2346,7 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "roi": get_value(roi), "scales": get_value(scales), @@ -2609,7 +2606,7 @@ def scan( ], body, ) - input_prop_values = { + input_prop_values: PropDict = { "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), } return ( @@ -2719,7 +2716,7 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -2765,7 +2762,7 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 45531a05..00123362 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -3,9 +3,7 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from dataclasses import dataclass -from typing import ( - Optional, -) +from typing import Optional import numpy as np import numpy.typing as npt @@ -18,6 +16,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode +from spox._type_system import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v19 import ( _GRU, @@ -733,7 +732,7 @@ def affine_grid( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "theta": get_value(theta), "size": get_value(size), } @@ -790,7 +789,7 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -898,7 +897,7 @@ def dft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "dft_length": get_value(dft_length), "axis": get_value(axis), @@ -959,7 +958,7 @@ def gelu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1079,7 +1078,7 @@ def grid_sample( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "grid": get_value(grid), } @@ -1159,7 +1158,7 @@ def image_decoder( - T1: `tensor(uint8)` - T2: `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "encoded_stream": get_value(encoded_stream), } return ( @@ -1216,7 +1215,7 @@ def isinf( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - T2: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1261,7 +1260,7 @@ def isnan( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - T2: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1335,7 +1334,7 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -1415,7 +1414,7 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -1474,7 +1473,7 @@ def regex_full_match( - T1: `tensor(string)` - T2: `tensor(bool)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( @@ -1522,7 +1521,7 @@ def string_concat( Type constraints: - T: `tensor(string)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "Y": get_value(Y), } @@ -1609,7 +1608,7 @@ def string_split( - T2: `tensor(string)` - T3: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), } return ( diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 08242da7..2bff4e7e 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -4,10 +4,7 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import ( - Callable, - Optional, -) +from typing import Callable, Optional from typing import cast as typing_cast import numpy as np @@ -28,7 +25,7 @@ from spox._graph import Graph, subgraph from spox._node import OpType from spox._standard import StandardNode -from spox._type_system import Tensor, Type +from spox._type_system import PropDict, Tensor, Type from spox._value_prop import PropValueType from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v20 import ( @@ -964,7 +961,7 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -1026,7 +1023,7 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), "target_type": get_value(target_type), } @@ -1101,7 +1098,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = {} + input_prop_values: PropDict = {} return ( _Constant( _Constant.Attributes( @@ -1158,7 +1155,7 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -1244,7 +1241,7 @@ def dequantize_linear( - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "x_scale": get_value(x_scale), "x_zero_point": get_value(x_zero_point), @@ -1306,7 +1303,7 @@ def flatten( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -1403,7 +1400,7 @@ def group_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values = { + input_prop_values: PropDict = { "X": get_value(X), "scale": get_value(scale), "bias": get_value(bias), @@ -1452,7 +1449,7 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "input": get_value(input), } return ( @@ -1522,7 +1519,7 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - input_prop_values = { + input_prop_values: PropDict = { "cond": get_value(cond), } return ( @@ -1723,7 +1720,7 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - input_prop_values = { + input_prop_values: PropDict = { "M": get_value(M), "cond": get_value(cond), "v_initial": get_value(v_initial), @@ -1906,7 +1903,7 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "pads": get_value(pads), "constant_value": get_value(constant_value), @@ -2003,7 +2000,7 @@ def qlinear_matmul( - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` - T3: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "a": get_value(a), "a_scale": get_value(a_scale), "a_zero_point": get_value(a_zero_point), @@ -2138,7 +2135,7 @@ def quantize_linear( - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "x": get_value(x), "y_scale": get_value(y_scale), "y_zero_point": get_value(y_zero_point), @@ -2214,7 +2211,7 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "shape": get_value(shape), } @@ -2455,7 +2452,7 @@ def scan( ], body, ) - input_prop_values = { + input_prop_values: PropDict = { "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), } return ( @@ -2565,7 +2562,7 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -2611,7 +2608,7 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -2662,7 +2659,7 @@ def squeeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } @@ -2714,7 +2711,7 @@ def transpose( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), } return ( @@ -2777,7 +2774,7 @@ def unsqueeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values = { + input_prop_values: PropDict = { "data": get_value(data), "axes": get_value(axes), } diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index 3b0ad1ab..ff5f842e 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -14,7 +14,7 @@ _{{ attr.name }}_subgraph: Graph = subgraph( ) {% endif %} {% endfor %} -input_prop_values = { +input_prop_values:PropDict = { {% for param in schema.inputs %}"{{param.name}}":get_value({{param.name}}), {% endfor %} diff --git a/tools/templates/preamble.jinja2 b/tools/templates/preamble.jinja2 index e5dc8e83..95ee0e64 100644 --- a/tools/templates/preamble.jinja2 +++ b/tools/templates/preamble.jinja2 @@ -7,7 +7,7 @@ from typing import ( Any, Callable, Optional, - Union, + Union,prea ) from typing import cast as typing_cast @@ -32,5 +32,5 @@ from spox._graph import Graph, subgraph from spox._internal_op import intro from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._type_system import Tensor, Type, Sequence as SpoxSequence, PropDict from spox._value_prop import PropValueType From 9060d12075e8bb6232250748d27dbf7319b40355 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 6 Nov 2024 21:46:15 +0200 Subject: [PATCH 15/29] Correctly codegen --- src/spox/opset/ai/onnx/v17.py | 397 +++++++++++++++++----------------- src/spox/opset/ai/onnx/v19.py | 63 +++--- src/spox/opset/ai/onnx/v20.py | 30 +-- src/spox/opset/ai/onnx/v21.py | 92 ++++---- 4 files changed, 292 insertions(+), 290 deletions(-) diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 128d5bfb..6aed7aaf 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -4641,8 +4641,8 @@ def batch_normalization( (training_mode=True). There are multiple cases for the number of outputs, which we list below: - - Output case #1: Y, running_mean, running_var (training_mode=True) - - Output case #2: Y (training_mode=False) + - Output case #1: Y, running_mean, running_var (training_mode=True) + - Output case #2: Y (training_mode=False) When training_mode=False, extra outputs are invalid. The outputs are updated as follows when training_mode=True: @@ -4998,26 +4998,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules: - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Parameters ========== @@ -6622,9 +6622,9 @@ def dynamic_quantize_linear( y_scale = (maximum(0, max(x)) - minimum(0, min(x))) / (qmax - qmin) - - where qmax and qmin are max and min values for quantization range - i.e. [0, 255] in case of uint8 - - data range is adjusted to include 0. + - where qmax and qmin are max and min values for quantization range i.e. + [0, 255] in case of uint8 + - data range is adjusted to include 0. Zero point is calculated as: @@ -6633,11 +6633,11 @@ def dynamic_quantize_linear( intermediate_zero_point = qmin - min(x)/y_scale y_zero_point = cast(round(saturate(itermediate_zero_point))) - - where qmax and qmin are max and min values for quantization range - .i.e [0, 255] in case of uint8 - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, - 127] if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. + - where qmax and qmin are max and min values for quantization range .i.e + [0, 255] in case of uint8 + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] + if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. Data quantization formula is: @@ -6645,9 +6645,9 @@ def dynamic_quantize_linear( y = saturate (round (x / y_scale) + y_zero_point) - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, - 127] if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] + if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. Parameters ========== @@ -7208,60 +7208,60 @@ def gru( Notations: - - ``X`` - input tensor - - ``z`` - update gate - - ``r`` - reset gate - - ``h`` - hidden gate - - ``t`` - time step (t-1 means previous time step) - - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden - gates - - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden - gates - - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates - - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates - - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, - and hidden gates - - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, - and hidden gates - - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden - gates - - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden - gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``z`` - update gate + - ``r`` - reset gate + - ``h`` - hidden gate + - ``t`` - time step (t-1 means previous time step) + - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden + gates + - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden + gates + - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates + - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates + - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, + and hidden gates + - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, + and hidden gates + - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden + gates + - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden + gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha \* x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha \* Tanh(beta \* x) - - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha \* x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha \* Tanh(beta \* x) + - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Sigmoid, g=Tanh): - - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) - - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) - - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when - linear_before_reset = 0 - - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when - linear_before_reset != 0 - - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** - inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) + - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when + linear_before_reset = 0 + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when + linear_before_reset != 0 + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** + inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -7791,8 +7791,8 @@ def gemm( General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 - - A' = transpose(A) if transA else A - - B' = transpose(B) if transB else B + - A' = transpose(A) if transA else A + - B' = transpose(B) if transB else B Compute Y = alpha \* A' \* B' + beta \* C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input @@ -7962,7 +7962,7 @@ def global_lp_pool( Signature: ``ai.onnx@2::GlobalLpPool``. Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ input_prop_values: PropDict = { "X": get_value(X), @@ -8908,65 +8908,65 @@ def lstm( Notations: - - ``X`` - input tensor - - ``i`` - input gate - - ``o`` - output gate - - ``f`` - forget gate - - ``c`` - cell gate - - ``t`` - time step (t-1 means previous time step) - - ``W[iofc]`` - W parameter weight matrix for input, output, forget, - and cell gates - - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, - and cell gates - - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell - gates - - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell - gates - - ``P[iof]`` - P peephole weight vector for input, output, and forget - gates - - ``WB[iofc]`` - W parameter weight matrix for backward input, output, - forget, and cell gates - - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, - forget, and cell gates - - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, - and cell gates - - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, - and cell gates - - ``PB[iof]`` - P peephole weight vector for backward input, output, - and forget gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``i`` - input gate + - ``o`` - output gate + - ``f`` - forget gate + - ``c`` - cell gate + - ``t`` - time step (t-1 means previous time step) + - ``W[iofc]`` - W parameter weight matrix for input, output, forget, and + cell gates + - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, + and cell gates + - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell + gates + - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell + gates + - ``P[iof]`` - P peephole weight vector for input, output, and forget + gates + - ``WB[iofc]`` - W parameter weight matrix for backward input, output, + forget, and cell gates + - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, + forget, and cell gates + - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, and + cell gates + - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, and + cell gates + - ``PB[iof]`` - P peephole weight vector for backward input, output, and + forget gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): - - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) - - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) - - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) - - Ct = ft (.) Ct-1 + it (.) ct - - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) - - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See - `the doc `__ for - more details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + - Ct = ft (.) Ct-1 + it (.) ct + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See + `the doc `__ for + more details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -9508,21 +9508,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond = + ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond = + true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -9838,8 +9838,8 @@ def matmul( B: Var, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + Matrix product that behaves like + `numpy.matmul `__. Parameters ========== @@ -9888,8 +9888,8 @@ def matmul_integer( b_zero_point: Optional[Var] = None, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + Matrix product that behaves like + `numpy.matmul `__. The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. @@ -10033,8 +10033,7 @@ def max_pool( output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. Sliding windows that would start in the right padded region are - ignored. + ``i``. ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: @@ -11894,8 +11893,8 @@ def qlinear_matmul( y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + Matrix product that behaves like + `numpy.matmul `__. It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). For @@ -12083,46 +12082,46 @@ def rnn( Notations: - - ``X`` - input tensor - - ``i`` - input gate - - ``t`` - time step (t-1 means previous time step) - - ``Wi`` - W parameter weight matrix for input gate - - ``Ri`` - R recurrence weight matrix for input gate - - ``Wbi`` - W parameter bias vector for input gate - - ``Rbi`` - R parameter bias vector for input gate - - ``WBi`` - W parameter weight matrix for backward input gate - - ``RBi`` - R recurrence weight matrix for backward input gate - - ``WBbi`` - WR bias vectors for backward input gate - - ``RBbi`` - RR bias vectors for backward input gate - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``i`` - input gate + - ``t`` - time step (t-1 means previous time step) + - ``Wi`` - W parameter weight matrix for input gate + - ``Ri`` - R recurrence weight matrix for input gate + - ``Wbi`` - W parameter bias vector for input gate + - ``Rbi`` - R parameter bias vector for input gate + - ``WBi`` - W parameter weight matrix for backward input gate + - ``RBi`` - R recurrence weight matrix for backward input gate + - ``WBbi`` - WR bias vectors for backward input gate + - ``RBbi`` - RR bias vectors for backward input gate + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Tanh): - - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has - **optional** inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has + **optional** inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -15465,10 +15464,10 @@ def softmax_cross_entropy_loss( L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. After L is available, this operator can optionally do a reduction operator. - - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, - D2,..., Dk), with K >= 1 in case of K-dimensional loss. - - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, - D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, + D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, + D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. The loss for one sample, l_i, can calculated as follows: @@ -15498,13 +15497,13 @@ def softmax_cross_entropy_loss( Finally, L is optionally reduced: - - If reduction = 'none', the output is L with shape (N, D1, D2, ..., - Dk). - - If reduction = 'sum', the output is scalar: Sum(L). - - If reduction = 'mean', the output is scalar: ReduceMean(L), or if - weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W - is of shape ``(N, D1, D2, ..., Dk)`` and - ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. + - If reduction = 'none', the output is L with shape (N, D1, D2, ..., + Dk). + - If reduction = 'sum', the output is scalar: Sum(L). + - If reduction = 'mean', the output is scalar: ReduceMean(L), or if + weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W is + of shape ``(N, D1, D2, ..., Dk)`` and + ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. Parameters ========== @@ -16482,22 +16481,22 @@ def top_k( Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer argument k, return two outputs: - - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a\_{n-1}] which contains the values of the top k elements along - the specified axis + - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] which contains the values of the top k elements along the + specified axis - - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a\_{n-1}] which contains the indices of the top k elements - (original indices from the input tensor). + - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] which contains the indices of the top k elements (original + indices from the input tensor). - - If "largest" is 1 (the default value) then the k largest elements are - returned. + - If "largest" is 1 (the default value) then the k largest elements are + returned. - - If "sorted" is 1 (the default value) then the resulting k elements - will be sorted. + - If "sorted" is 1 (the default value) then the resulting k elements + will be sorted. - - If "sorted" is 0, order of returned 'Values' and 'Indices' are - undefined. + - If "sorted" is 0, order of returned 'Values' and 'Indices' are + undefined. Given two equivalent values, this operator uses the indices along the axis as a tiebreaker. That is, the element with the lower index will diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 95ccfd06..49608dc1 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -818,8 +818,7 @@ def average_pool( output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. Sliding windows that would start in the right padded region are - ignored. + ``i``. ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: @@ -976,26 +975,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules if the destination type is not a float 8 type. - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Float 8 type were introduced to speed up the training of deep models. By default the conversion of a float *x* obeys to the following rules. @@ -1381,9 +1380,11 @@ def dequantize_linear( axis Attribute. (Optional) The axis of the dequantizing dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). + Used only for per-axis quantization. Negative value means counting + dimensions from the back. Accepted range is ``[-r, r-1]`` where + ``r = rank(input)``. When the rank of the input is 1, per-tensor + quantization is applied, rendering the axis unnecessary in this + scenario. Returns ======= @@ -1615,21 +1616,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond = + ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond = + true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 00123362..c5c1db85 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -1110,21 +1110,21 @@ def image_decoder( reason (e.g. corrupted encoded stream, invalid format, it will return an empty matrix). The following image formats are supported: - - BMP - - JPEG (note: Lossless JPEG support is optional) - - JPEG2000 - - TIFF - - PNG - - WebP - - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow - a channel-last layout: (Height, Width, Channels). **JPEG chroma - upsampling method:** When upsampling the chroma components by a - factor of 2, the pixels are linearly interpolated so that the centers - of the output pixels are 1/4 and 3/4 of the way between input pixel - centers. When rounding, 0.5 is rounded down and up at alternative - pixels locations to prevent bias towards larger values (ordered - dither pattern). Considering adjacent input pixels A, B, and C, B is - upsampled to pixels B0 and B1 so that + - BMP + - JPEG (note: Lossless JPEG support is optional) + - JPEG2000 + - TIFF + - PNG + - WebP + - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow + a channel-last layout: (Height, Width, Channels). **JPEG chroma + upsampling method:** When upsampling the chroma components by a factor + of 2, the pixels are linearly interpolated so that the centers of the + output pixels are 1/4 and 3/4 of the way between input pixel centers. + When rounding, 0.5 is rounded down and up at alternative pixels + locations to prevent bias towards larger values (ordered dither + pattern). Considering adjacent input pixels A, B, and C, B is + upsampled to pixels B0 and B1 so that :: diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 2bff4e7e..6256ad83 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -877,26 +877,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules if the destination type is not a float 8 type. - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Float 8 type were introduced to speed up the training of deep models. By default the conversion of a float *x* obeys to the following rules. @@ -1564,21 +1564,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond = + ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond = + true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -1938,8 +1938,8 @@ def qlinear_matmul( y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + Matrix product that behaves like + `numpy.matmul `__. It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). For @@ -2049,12 +2049,12 @@ def quantize_linear( Saturation is done according to: - - uint16: [0, 65535] - - int16: [-32768, 32767] - - uint8: [0, 255] - - int8: [-128, 127] - - uint4: [0, 15] - - int4: [-8, 7] + - uint16: [0, 65535] + - int16: [-32768, 32767] + - uint8: [0, 255] + - int8: [-128, 127] + - uint4: [0, 15] + - int4: [-8, 7] For ``(x / y_scale)``, it rounds to the nearest even. Refer to https://en.wikipedia.org/wiki/Rounding for details. @@ -2068,15 +2068,15 @@ def quantize_linear( shape of ``y_scale``. In all cases, ``y_zero_point`` must have the same shape as ``y_scale``. - - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. - - Per-axis quantization: The scale must be a 1-D tensor, with the - length of the quantization axis. For an input shape - ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D - tensor of length ``Di``. - - Blocked quantization: The scale's shape is identical to the input's - shape, except for one dimension, in which blocking is performed. - Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block - size ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. + - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. + - Per-axis quantization: The scale must be a 1-D tensor, with the length + of the quantization axis. For an input shape + ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D tensor + of length ``Di``. + - Blocked quantization: The scale's shape is identical to the input's + shape, except for one dimension, in which blocking is performed. Given + ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block size + ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. Parameters ========== @@ -2096,9 +2096,11 @@ def quantize_linear( axis Attribute. (Optional) The axis of the dequantizing dimension of the input tensor. - Used for per-axis and blocked quantization. Negative value means + Used only for per-axis and blocked quantization. Negative value means counting dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. + ``r = rank(input)``. When the rank of the input is 1, per-tensor + quantization is applied, rendering the axis unnecessary in this + scenario. block_size Attribute. (Optional) The size of the quantization block (number of times every From 6aa1bf477a1e616fa530ad058d4ae6fdff86aa8f Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Fri, 15 Nov 2024 18:20:48 +0200 Subject: [PATCH 16/29] Comments after code review --- src/spox/_exceptions.py | 2 +- src/spox/_fields.py | 92 ++- src/spox/_function.py | 2 +- src/spox/_future.py | 4 +- src/spox/_graph.py | 52 +- src/spox/_internal_op.py | 4 +- src/spox/_node.py | 21 +- src/spox/_public.py | 2 +- src/spox/opset/ai/onnx/ml/v3.py | 54 +- src/spox/opset/ai/onnx/ml/v4.py | 3 +- src/spox/opset/ai/onnx/ml/v5.py | 3 +- src/spox/opset/ai/onnx/v17.py | 927 +++++++++++++------------------ src/spox/opset/ai/onnx/v18.py | 75 +-- src/spox/opset/ai/onnx/v19.py | 116 ++-- src/spox/opset/ai/onnx/v20.py | 69 +-- src/spox/opset/ai/onnx/v21.py | 154 +++-- tests/test_function.py | 2 +- tools/templates/construct.jinja2 | 1 - 18 files changed, 650 insertions(+), 933 deletions(-) diff --git a/src/spox/_exceptions.py b/src/spox/_exceptions.py index 01e72906..fdca7eb7 100644 --- a/src/spox/_exceptions.py +++ b/src/spox/_exceptions.py @@ -8,7 +8,7 @@ class InferenceWarning(Warning): - """Warning related to partial typing of VarInfoiables. + """Warning related to partial typing of Variables. Incomplete type information may lead to reduced code safety or failure to build the model. The most common underlying cause for diff --git a/src/spox/_fields.py b/src/spox/_fields.py index 18e97bc0..bfbe6c56 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -6,7 +6,7 @@ import warnings from collections.abc import Iterable, Iterator, Sequence from dataclasses import dataclass -from typing import Any, Generic, Optional, TypeVar, Union +from typing import Any, Optional, Union from ._attributes import Attr from ._exceptions import InferenceWarning @@ -35,51 +35,48 @@ class VarFieldKind(enum.Enum): class BaseVars: - def _unpack_to_any(self) -> Any: + def __init__(self, vars): + self.vars = vars + + def _unpack_to_any(self): """Unpack the stored fields into a tuple of appropriate length, typed as Any.""" - return tuple(self.__dict__.values()) + return tuple(self.vars.values()) - def _flatten(self) -> Iterable[tuple[str, Optional[Var]]]: + def _flatten(self): """Iterate over the pairs of names and values of fields in this object.""" - for key, value in self.__dict__.items(): + for key, value in self.vars.items(): if value is None or isinstance(value, Var): yield key, value else: yield from ((f"{key}_{i}", v) for i, v in enumerate(value)) - def get_var_infos(self) -> dict[str, Var]: + def flatten_vars(self): """Return a flat mapping by name of all the VarInfos in this object.""" return {key: var for key, var in self._flatten() if var is not None} + def __getattr__(self, attr: str) -> Union["Var", Sequence["Var"]]: + """Retrieves the attribute if present in the stored variables.""" + try: + return self.vars[attr] + except KeyError: + raise AttributeError( + f"{self.__class__.__name__!r} object has no attribute {attr!r}" + ) -class BaseVarsMeta(type): - def __new__(cls, name, bases, namespace): - new_cls = super().__new__(cls, name, bases, namespace) - - if bases and "__annotations__" in namespace: - annotations: dict[str, Any] = {} - for name, typ in namespace["__annotations__"].items(): - if typ == VarInfo: - annotations[name] = Var - elif typ == Optional[VarInfo]: - annotations[name] = Optional[Var] - elif typ == Sequence[VarInfo]: - annotations[name] = Sequence[Var] - - vars_cls = dataclass( - type( - "Vars", - ( - BaseVars, - object, - ), - {"__annotations__": annotations}, - ) - ) # type: ignore + def __setattr__(self, attr: str, value: Union["Var", Sequence["Var"]]) -> None: + """Sets the attribute to a value if the attribute is present in the stored variables.""" + if attr == "vars": + super().__setattr__(attr, value) + else: + self.vars[attr] = value - setattr(new_cls, "Vars", vars_cls) + def __getitem__(self, key: str): + """Allows dictionary-like access to retrieve variables.""" + return self.vars[key] - return new_cls + def __setitem__(self, key: str, value) -> None: + """Allows dictionary-like access to set variables.""" + self.vars[key] = value @dataclass @@ -157,30 +154,23 @@ def fully_typed(self) -> bool: ) -TypeBaseVars = TypeVar("TypeBaseVars", bound=BaseVars) - - @dataclass -class BaseInputs(BaseVarInfos, Generic[TypeBaseVars], metaclass=BaseVarsMeta): - @dataclass - class Vars(BaseVars): - pass - - def vars(self, prop_values) -> TypeBaseVars: - vars_structure: dict[str, Union[Var, Sequence[Var]]] = {} +class BaseInputs(BaseVarInfos): + def vars(self, prop_values): + vars_dict: dict[str, Union[Var, Sequence[Var]]] = {} for field in dataclasses.fields(self): field_type = self._get_field_type(field) field_value = getattr(self, field.name) if field_type == VarFieldKind.SINGLE: - vars_structure[field.name] = Var(field_value, prop_values[field.name]) + vars_dict[field.name] = Var(field_value, prop_values[field.name]) elif ( field_type == VarFieldKind.OPTIONAL and prop_values.get(field.name, None) is not None ): - vars_structure[field.name] = Var(field_value, prop_values[field.name]) + vars_dict[field.name] = Var(field_value, prop_values[field.name]) elif field_type == VarFieldKind.VARIADIC: vars = [] @@ -189,21 +179,17 @@ def vars(self, prop_values) -> TypeBaseVars: var_value = prop_values.get(f"{field.name}_{i}", None) vars.append(Var(var_info, var_value)) - vars_structure[field.name] = vars + vars_dict[field.name] = vars - return self.__class__.Vars(**vars_structure) # type: ignore + return BaseVars(vars_dict) @dataclass -class BaseOutputs(BaseVarInfos, Generic[TypeBaseVars], metaclass=BaseVarsMeta): - @dataclass - class Vars(BaseVars): - pass - +class BaseOutputs(BaseVarInfos): def _propagate_vars( self, prop_values={}, - ) -> TypeBaseVars: + ): def _create_var(key, var_info): ret = Var(var_info, None) @@ -233,4 +219,4 @@ def _create_var(key, var_info): _create_var(f"{key}_{i}", v) for i, v in enumerate(var_info) ] - return self.__class__.Vars(**ret_dict) # type: ignore + return BaseVars(ret_dict) diff --git a/src/spox/_function.py b/src/spox/_function.py index ffc2a1c3..f9bc35c9 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -81,7 +81,7 @@ def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: self.func_inputs = self.Inputs(**self.func_args) # type: ignore self.func_outputs = self.constructor(self.func_attrs, self.func_inputs) self.func_graph = _graph.results( - **self.func_outputs._propagate_vars(input_prop_values).get_var_infos() + **self.func_outputs._propagate_vars(input_prop_values).flatten_vars() ).with_arguments(*func_args_var.values()) return { diff --git a/src/spox/_future.py b/src/spox/_future.py index 8199d563..e82a9809 100644 --- a/src/spox/_future.py +++ b/src/spox/_future.py @@ -60,8 +60,8 @@ def initializer(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: Returns ------- - VarInfo - VarInfoiable with the given constant ``value``. + Var + Variable with the given constant ``value``. Notes ----- diff --git a/src/spox/_graph.py b/src/spox/_graph.py index f7a6999b..0470b289 100644 --- a/src/spox/_graph.py +++ b/src/spox/_graph.py @@ -43,32 +43,24 @@ def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var for name, info in kwargs.items(): attr_name = AttrString(value=name, name="dummy") if isinstance(info, Type): - result[name] = ( - Argument( - Argument.Attributes( - name=attr_name, - type=AttrType(value=info, name="dummy"), - default=None, - ), - BaseInputs(), - ) - .get_output_vars() - .arg - ) + result[name] = Argument( + Argument.Attributes( + name=attr_name, + type=AttrType(value=info, name="dummy"), + default=None, + ), + BaseInputs(), + ).get_output_vars()["arg"] elif isinstance(info, np.ndarray): ty = Tensor(info.dtype, info.shape) - result[name] = ( - Argument( - Argument.Attributes( - name=attr_name, - type=AttrType(value=ty, name="dummy"), - default=AttrTensor(value=info, name="dummy"), - ), - BaseInputs(), - ) - .get_output_vars() - .arg - ) + result[name] = Argument( + Argument.Attributes( + name=attr_name, + type=AttrType(value=ty, name="dummy"), + default=AttrTensor(value=info, name="dummy"), + ), + BaseInputs(), + ).get_output_vars()["arg"] else: raise TypeError(f"Cannot construct argument from {type(info)}.") return result @@ -118,14 +110,10 @@ def initializer(arr: np.ndarray) -> Var: ------- Var which is always equal to the respective value provided by `arr`. """ - return ( - _Initializer( - _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), - BaseInputs(), - ) - .get_output_vars() - .arg - ) + return _Initializer( + _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), + BaseInputs(), + ).get_output_vars()["arg"] @dataclass(frozen=True, eq=False) diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index b7b68009..99c47664 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -73,11 +73,11 @@ class Attributes(BaseAttributes): default: Optional[AttrTensor] = None @dataclass - class Inputs(BaseInputs["Argument.Outputs.Vars"]): + class Inputs(BaseInputs): pass @dataclass - class Outputs(BaseOutputs["Argument.Outputs.Vars"]): + class Outputs(BaseOutputs): arg: VarInfo attrs: Attributes diff --git a/src/spox/_node.py b/src/spox/_node.py index 75ddf178..ba0c9a45 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -126,7 +126,7 @@ def __init__( # As inference functions may access which output vars we initialized (e.g. variadics) # we inject uninitialized vars first self.outputs = self._init_output_vars() - self.inference(infer_types, input_prop_values) + self.inference(infer_types=infer_types, input_prop_values={}) else: self.outputs = outputs @@ -222,7 +222,11 @@ def infer_output_types(self, input_prop_values) -> dict[str, Type]: """ return {} - def inference(self, infer_types: bool = True, input_prop_values={}): + def inference( + self, input_prop_values: Optional[PropDict] = None, infer_types: bool = True + ): + if input_prop_values is None: + input_prop_values = {} # Type inference routine - call infer_output_types if required # and check if it provides the expected outputs. out_types = ( @@ -232,12 +236,19 @@ def inference(self, infer_types: bool = True, input_prop_values={}): ) for key, var in self.outputs.get_var_infos().items(): - if var.type is None: # If no existing type from init_output_vars - # Attempt to use the ones from kwargs, if none then what type inference gave + typ = out_types.get(key) + if var.type is None or (typ is not None and typ._subtype(var.type)): + # If there is no type, or the infered type is a subtype + # we use the new type var.type = out_types.get(key) - def get_output_vars(self, input_prop_values={}): + def get_output_vars( + self, input_prop_values: Optional[PropDict] = None, infer_types: bool = True + ): + if input_prop_values is None: + input_prop_values = {} # After typing everything, try to get values for outputs + self.inference(infer_types=infer_types, input_prop_values=input_prop_values) out_values = self.propagate_values(input_prop_values) return self.outputs._propagate_vars(out_values) diff --git a/src/spox/_public.py b/src/spox/_public.py index 4dfce42a..b134e9a4 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -316,7 +316,7 @@ def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: return dict( zip( out_names, - node.get_output_vars(prop_values).get_var_infos().values(), + node.get_output_vars(prop_values).flatten_vars().values(), ) ) diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index 47a3f1a5..d51bf91e 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -670,8 +670,7 @@ def array_feature_extractor( _ArrayFeatureExtractor.Inputs( X=unwrap_vars(X), Y=unwrap_vars(Y), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Z @@ -719,8 +718,7 @@ def binarizer( ), _Binarizer.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -786,8 +784,7 @@ def cast_map( ), _CastMap.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -862,8 +859,7 @@ def category_mapper( ), _CategoryMapper.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -935,8 +931,7 @@ def dict_vectorizer( ), _DictVectorizer.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -989,8 +984,7 @@ def feature_vectorizer( ), _FeatureVectorizer.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1073,8 +1067,7 @@ def imputer( ), _Imputer.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1179,8 +1172,7 @@ def label_encoder( ), _LabelEncoder.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1263,8 +1255,7 @@ def linear_classifier( ), _LinearClassifier.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -1333,8 +1324,7 @@ def linear_regressor( ), _LinearRegressor.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1387,8 +1377,7 @@ def normalizer( ), _Normalizer.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1456,8 +1445,7 @@ def one_hot_encoder( ), _OneHotEncoder.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1574,8 +1562,7 @@ def svmclassifier( ), _SVMClassifier.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -1662,8 +1649,7 @@ def svmregressor( ), _SVMRegressor.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1720,8 +1706,7 @@ def scaler( ), _Scaler.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1915,8 +1900,7 @@ def tree_ensemble_classifier( ), _TreeEnsembleClassifier.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -2108,8 +2092,7 @@ def tree_ensemble_regressor( ), _TreeEnsembleRegressor.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -2171,8 +2154,7 @@ def zip_map( ), _ZipMap.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Z diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index e7cfc723..9e2b3426 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -211,8 +211,7 @@ def label_encoder( ), _LabelEncoder.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index 5ff61e47..03dd1880 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -259,8 +259,7 @@ def tree_ensemble( ), _TreeEnsemble.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 6aed7aaf..82d578a1 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -3963,8 +3963,7 @@ def abs( _Abs.Attributes(), _Abs.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -4005,8 +4004,7 @@ def acos( _Acos.Attributes(), _Acos.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4048,8 +4046,7 @@ def acosh( _Acosh.Attributes(), _Acosh.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4103,8 +4100,7 @@ def add( _Add.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -4157,8 +4153,7 @@ def and_( _And.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -4227,8 +4222,7 @@ def arg_max( ), _ArgMax.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -4297,8 +4291,7 @@ def arg_min( ), _ArgMin.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -4339,8 +4332,7 @@ def asin( _Asin.Attributes(), _Asin.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4381,8 +4373,7 @@ def asinh( _Asinh.Attributes(), _Asinh.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4423,8 +4414,7 @@ def atan( _Atan.Attributes(), _Atan.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4466,8 +4456,7 @@ def atanh( _Atanh.Attributes(), _Atanh.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4612,8 +4601,7 @@ def average_pool( ), _AveragePool.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -4641,8 +4629,8 @@ def batch_normalization( (training_mode=True). There are multiple cases for the number of outputs, which we list below: - - Output case #1: Y, running_mean, running_var (training_mode=True) - - Output case #2: Y (training_mode=False) + - Output case #1: Y, running_mean, running_var (training_mode=True) + - Output case #2: Y (training_mode=False) When training_mode=False, extra outputs are invalid. The outputs are updated as follows when training_mode=True: @@ -4760,8 +4748,7 @@ def batch_normalization( B=unwrap_vars(B), input_mean=unwrap_vars(input_mean), input_var=unwrap_vars(input_var), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -4824,8 +4811,7 @@ def bernoulli( ), _Bernoulli.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4894,8 +4880,7 @@ def bit_shift( _BitShift.Inputs( X=unwrap_vars(X), Y=unwrap_vars(Y), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Z @@ -4954,8 +4939,7 @@ def blackman_window( ), _BlackmanWindow.Inputs( size=unwrap_vars(size), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4998,26 +4982,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules: - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Parameters ========== @@ -5054,8 +5038,7 @@ def cast( ), _Cast.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5106,8 +5089,7 @@ def cast_like( _CastLike.Inputs( input=unwrap_vars(input), target_type=unwrap_vars(target_type), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5150,8 +5132,7 @@ def ceil( _Ceil.Attributes(), _Ceil.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -5204,8 +5185,7 @@ def celu( ), _Celu.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -5261,8 +5241,7 @@ def clip( input=unwrap_vars(input), min=unwrap_vars(min), max=unwrap_vars(max), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5327,8 +5306,7 @@ def compress( _Compress.Inputs( input=unwrap_vars(input), condition=unwrap_vars(condition), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5378,8 +5356,7 @@ def concat( ), _Concat.Inputs( inputs=unwrap_vars(inputs), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .concat_result @@ -5439,8 +5416,7 @@ def concat_from_sequence( ), _ConcatFromSequence.Inputs( input_sequence=unwrap_vars(input_sequence), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .concat_result @@ -5514,8 +5490,7 @@ def constant( value_string=AttrString.maybe(value_string, name="value_string"), value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), - _Constant.Inputs(), - input_prop_values=input_prop_values, + _Constant.Inputs(), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5569,8 +5544,7 @@ def constant_of_shape( ), _ConstantOfShape.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5693,8 +5667,7 @@ def conv( X=unwrap_vars(X), W=unwrap_vars(W), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -5830,8 +5803,7 @@ def conv_integer( w=unwrap_vars(w), x_zero_point=unwrap_vars(x_zero_point), w_zero_point=unwrap_vars(w_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -5987,8 +5959,7 @@ def conv_transpose( X=unwrap_vars(X), W=unwrap_vars(W), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -6028,8 +5999,7 @@ def cos( _Cos.Attributes(), _Cos.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6069,8 +6039,7 @@ def cosh( _Cosh.Attributes(), _Cosh.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6155,8 +6124,7 @@ def cumsum( _CumSum.Inputs( x=unwrap_vars(x), axis=unwrap_vars(axis), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -6250,8 +6218,7 @@ def dft( _DFT.Inputs( input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6331,8 +6298,7 @@ def depth_to_space( ), _DepthToSpace.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6403,8 +6369,7 @@ def dequantize_linear( x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -6449,8 +6414,7 @@ def det( _Det.Attributes(), _Det.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -6504,8 +6468,7 @@ def div( _Div.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -6602,8 +6565,7 @@ def dropout( data=unwrap_vars(data), ratio=unwrap_vars(ratio), training_mode=unwrap_vars(training_mode), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -6622,9 +6584,9 @@ def dynamic_quantize_linear( y_scale = (maximum(0, max(x)) - minimum(0, min(x))) / (qmax - qmin) - - where qmax and qmin are max and min values for quantization range i.e. - [0, 255] in case of uint8 - - data range is adjusted to include 0. + - where qmax and qmin are max and min values for quantization range + i.e. [0, 255] in case of uint8 + - data range is adjusted to include 0. Zero point is calculated as: @@ -6633,11 +6595,11 @@ def dynamic_quantize_linear( intermediate_zero_point = qmin - min(x)/y_scale y_zero_point = cast(round(saturate(itermediate_zero_point))) - - where qmax and qmin are max and min values for quantization range .i.e - [0, 255] in case of uint8 - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] - if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. + - where qmax and qmin are max and min values for quantization range + .i.e [0, 255] in case of uint8 + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, + 127] if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. Data quantization formula is: @@ -6645,9 +6607,9 @@ def dynamic_quantize_linear( y = saturate (round (x / y_scale) + y_zero_point) - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] - if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, + 127] if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. Parameters ========== @@ -6685,8 +6647,7 @@ def dynamic_quantize_linear( _DynamicQuantizeLinear.Attributes(), _DynamicQuantizeLinear.Inputs( x=unwrap_vars(x), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -6765,8 +6726,7 @@ def einsum( ), _Einsum.Inputs( Inputs=unwrap_vars(Inputs), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Output @@ -6816,8 +6776,7 @@ def elu( ), _Elu.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -6870,8 +6829,7 @@ def equal( _Equal.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -6912,8 +6870,7 @@ def erf( _Erf.Attributes(), _Erf.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6953,8 +6910,7 @@ def exp( _Exp.Attributes(), _Exp.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7009,8 +6965,7 @@ def expand( _Expand.Inputs( input=unwrap_vars(input), shape=unwrap_vars(shape), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7076,8 +7031,7 @@ def eye_like( ), _EyeLike.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7133,8 +7087,7 @@ def flatten( ), _Flatten.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7177,8 +7130,7 @@ def floor( _Floor.Attributes(), _Floor.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -7208,60 +7160,60 @@ def gru( Notations: - - ``X`` - input tensor - - ``z`` - update gate - - ``r`` - reset gate - - ``h`` - hidden gate - - ``t`` - time step (t-1 means previous time step) - - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden - gates - - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden - gates - - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates - - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates - - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, - and hidden gates - - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, - and hidden gates - - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden - gates - - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden - gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``z`` - update gate + - ``r`` - reset gate + - ``h`` - hidden gate + - ``t`` - time step (t-1 means previous time step) + - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden + gates + - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden + gates + - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates + - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates + - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, + and hidden gates + - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, + and hidden gates + - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden + gates + - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden + gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha \* x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha \* Tanh(beta \* x) - - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha \* x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha \* Tanh(beta \* x) + - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Sigmoid, g=Tanh): - - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) - - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) - - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when - linear_before_reset = 0 - - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when - linear_before_reset != 0 - - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** - inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) + - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when + linear_before_reset = 0 + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when + linear_before_reset != 0 + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** + inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -7390,8 +7342,7 @@ def gru( B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -7496,8 +7447,7 @@ def gather( _Gather.Inputs( data=unwrap_vars(data), indices=unwrap_vars(indices), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7610,8 +7560,7 @@ def gather_elements( _GatherElements.Inputs( data=unwrap_vars(data), indices=unwrap_vars(indices), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7769,8 +7718,7 @@ def gather_nd( _GatherND.Inputs( data=unwrap_vars(data), indices=unwrap_vars(indices), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7791,8 +7739,8 @@ def gemm( General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 - - A' = transpose(A) if transA else A - - B' = transpose(B) if transB else B + - A' = transpose(A) if transA else A + - B' = transpose(B) if transB else B Compute Y = alpha \* A' \* B' + beta \* C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input @@ -7867,8 +7815,7 @@ def gemm( A=unwrap_vars(A), B=unwrap_vars(B), C=unwrap_vars(C), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -7917,8 +7864,7 @@ def global_average_pool( _GlobalAveragePool.Attributes(), _GlobalAveragePool.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -7962,7 +7908,7 @@ def global_lp_pool( Signature: ``ai.onnx@2::GlobalLpPool``. Type constraints: - - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ input_prop_values: PropDict = { "X": get_value(X), @@ -7974,8 +7920,7 @@ def global_lp_pool( ), _GlobalLpPool.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8024,8 +7969,7 @@ def global_max_pool( _GlobalMaxPool.Attributes(), _GlobalMaxPool.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8078,8 +8022,7 @@ def greater( _Greater.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -8132,8 +8075,7 @@ def greater_or_equal( _GreaterOrEqual.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -8236,8 +8178,7 @@ def grid_sample( _GridSample.Inputs( X=unwrap_vars(X), grid=unwrap_vars(grid), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8296,8 +8237,7 @@ def hamming_window( ), _HammingWindow.Inputs( size=unwrap_vars(size), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8356,8 +8296,7 @@ def hann_window( ), _HannWindow.Inputs( size=unwrap_vars(size), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8411,8 +8350,7 @@ def hard_sigmoid( ), _HardSigmoid.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8455,8 +8393,7 @@ def hard_swish( _HardSwish.Attributes(), _HardSwish.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8512,8 +8449,7 @@ def hardmax( ), _Hardmax.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8553,8 +8489,7 @@ def identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8627,8 +8562,9 @@ def if_( _If.Inputs( cond=unwrap_vars(cond), ), - out_variadic=len(_else_branch_subgraph.requested_results), - input_prop_values=input_prop_values, + out_variadic=len( + _else_branch_subgraph.requested_results + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .outputs @@ -8695,8 +8631,7 @@ def instance_normalization( input=unwrap_vars(input), scale=unwrap_vars(scale), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8753,8 +8688,7 @@ def isinf( ), _IsInf.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8795,8 +8729,7 @@ def isnan( _IsNaN.Attributes(), _IsNaN.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8875,8 +8808,7 @@ def lrn( ), _LRN.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8908,65 +8840,65 @@ def lstm( Notations: - - ``X`` - input tensor - - ``i`` - input gate - - ``o`` - output gate - - ``f`` - forget gate - - ``c`` - cell gate - - ``t`` - time step (t-1 means previous time step) - - ``W[iofc]`` - W parameter weight matrix for input, output, forget, and - cell gates - - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, - and cell gates - - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell - gates - - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell - gates - - ``P[iof]`` - P peephole weight vector for input, output, and forget - gates - - ``WB[iofc]`` - W parameter weight matrix for backward input, output, - forget, and cell gates - - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, - forget, and cell gates - - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, and - cell gates - - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, and - cell gates - - ``PB[iof]`` - P peephole weight vector for backward input, output, and - forget gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``i`` - input gate + - ``o`` - output gate + - ``f`` - forget gate + - ``c`` - cell gate + - ``t`` - time step (t-1 means previous time step) + - ``W[iofc]`` - W parameter weight matrix for input, output, forget, + and cell gates + - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, + and cell gates + - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell + gates + - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell + gates + - ``P[iof]`` - P peephole weight vector for input, output, and forget + gates + - ``WB[iofc]`` - W parameter weight matrix for backward input, output, + forget, and cell gates + - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, + forget, and cell gates + - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, + and cell gates + - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, + and cell gates + - ``PB[iof]`` - P peephole weight vector for backward input, output, + and forget gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): - - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) - - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) - - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) - - Ct = ft (.) Ct-1 + it (.) ct - - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) - - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See - `the doc `__ for - more details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + - Ct = ft (.) Ct-1 + it (.) ct + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See + `the doc `__ for + more details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -9112,8 +9044,7 @@ def lstm( initial_h=unwrap_vars(initial_h), initial_c=unwrap_vars(initial_c), P=unwrap_vars(P), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -9219,8 +9150,7 @@ def layer_normalization( X=unwrap_vars(X), Scale=unwrap_vars(Scale), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -9270,8 +9200,7 @@ def leaky_relu( ), _LeakyRelu.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9324,8 +9253,7 @@ def less( _Less.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -9378,8 +9306,7 @@ def less_or_equal( _LessOrEqual.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -9419,8 +9346,7 @@ def log( _Log.Attributes(), _Log.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -9475,8 +9401,7 @@ def log_softmax( ), _LogSoftmax.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -9508,21 +9433,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond = - ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond = - true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -9679,8 +9604,7 @@ def loop( cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), - out_variadic=len(_body_subgraph.requested_results) - 1, - input_prop_values=input_prop_values, + out_variadic=len(_body_subgraph.requested_results) - 1, # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs @@ -9732,8 +9656,7 @@ def lp_normalization( ), _LpNormalization.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -9825,8 +9748,7 @@ def lp_pool( ), _LpPool.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9838,8 +9760,8 @@ def matmul( B: Var, ) -> Var: r""" - Matrix product that behaves like - `numpy.matmul `__. + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html Parameters ========== @@ -9873,8 +9795,7 @@ def matmul( _MatMul.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9888,8 +9809,8 @@ def matmul_integer( b_zero_point: Optional[Var] = None, ) -> Var: r""" - Matrix product that behaves like - `numpy.matmul `__. + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. @@ -9947,8 +9868,7 @@ def matmul_integer( B=unwrap_vars(B), a_zero_point=unwrap_vars(a_zero_point), b_zero_point=unwrap_vars(b_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9992,8 +9912,7 @@ def max( _Max.Attributes(), _Max.Inputs( data_0=unwrap_vars(data_0), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .max @@ -10033,7 +9952,8 @@ def max_pool( output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. + ``i``. Sliding windows that would start in the right padded region are + ignored. ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: @@ -10152,8 +10072,7 @@ def max_pool( ), _MaxPool.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -10218,8 +10137,7 @@ def max_roi_pool( _MaxRoiPool.Inputs( X=unwrap_vars(X), rois=unwrap_vars(rois), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -10338,8 +10256,7 @@ def max_unpool( X=unwrap_vars(X), I=unwrap_vars(I), output_shape=unwrap_vars(output_shape), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -10383,8 +10300,7 @@ def mean( _Mean.Attributes(), _Mean.Inputs( data_0=unwrap_vars(data_0), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .mean @@ -10436,8 +10352,7 @@ def mean_variance_normalization( ), _MeanVarianceNormalization.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -10536,8 +10451,7 @@ def mel_weight_matrix( sample_rate=unwrap_vars(sample_rate), lower_edge_hertz=unwrap_vars(lower_edge_hertz), upper_edge_hertz=unwrap_vars(upper_edge_hertz), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -10581,8 +10495,7 @@ def min( _Min.Attributes(), _Min.Inputs( data_0=unwrap_vars(data_0), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .min @@ -10653,8 +10566,7 @@ def mod( _Mod.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -10708,8 +10620,7 @@ def mul( _Mul.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -10775,8 +10686,7 @@ def multinomial( ), _Multinomial.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -10818,8 +10728,7 @@ def neg( _Neg.Attributes(), _Neg.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -10998,8 +10907,7 @@ def negative_log_likelihood_loss( input=unwrap_vars(input), target=unwrap_vars(target), weight=unwrap_vars(weight), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .loss @@ -11090,8 +10998,7 @@ def non_max_suppression( max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), iou_threshold=unwrap_vars(iou_threshold), score_threshold=unwrap_vars(score_threshold), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .selected_indices @@ -11135,8 +11042,7 @@ def non_zero( _NonZero.Attributes(), _NonZero.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -11176,8 +11082,7 @@ def not_( _Not.Attributes(), _Not.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -11279,8 +11184,7 @@ def one_hot( indices=unwrap_vars(indices), depth=unwrap_vars(depth), values=unwrap_vars(values), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11330,8 +11234,7 @@ def optional( ), _Optional.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11374,8 +11277,7 @@ def optional_get_element( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11418,8 +11320,7 @@ def optional_has_element( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11472,8 +11373,7 @@ def or_( _Or.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -11526,8 +11426,7 @@ def prelu( _PRelu.Inputs( X=unwrap_vars(X), slope=unwrap_vars(slope), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -11642,8 +11541,7 @@ def pad( data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11695,8 +11593,7 @@ def pow( _Pow.Inputs( X=unwrap_vars(X), Y=unwrap_vars(Y), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Z @@ -11874,8 +11771,7 @@ def qlinear_conv( y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -11893,8 +11789,8 @@ def qlinear_matmul( y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like - `numpy.matmul `__. + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). For @@ -11976,8 +11872,7 @@ def qlinear_matmul( b_zero_point=unwrap_vars(b_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -12052,8 +11947,7 @@ def quantize_linear( x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -12082,46 +11976,46 @@ def rnn( Notations: - - ``X`` - input tensor - - ``i`` - input gate - - ``t`` - time step (t-1 means previous time step) - - ``Wi`` - W parameter weight matrix for input gate - - ``Ri`` - R recurrence weight matrix for input gate - - ``Wbi`` - W parameter bias vector for input gate - - ``Rbi`` - R parameter bias vector for input gate - - ``WBi`` - W parameter weight matrix for backward input gate - - ``RBi`` - R recurrence weight matrix for backward input gate - - ``WBbi`` - WR bias vectors for backward input gate - - ``RBbi`` - RR bias vectors for backward input gate - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``i`` - input gate + - ``t`` - time step (t-1 means previous time step) + - ``Wi`` - W parameter weight matrix for input gate + - ``Ri`` - R recurrence weight matrix for input gate + - ``Wbi`` - W parameter bias vector for input gate + - ``Rbi`` - R parameter bias vector for input gate + - ``WBi`` - W parameter weight matrix for backward input gate + - ``RBi`` - R recurrence weight matrix for backward input gate + - ``WBbi`` - WR bias vectors for backward input gate + - ``RBbi`` - RR bias vectors for backward input gate + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Tanh): - - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has - **optional** inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has + **optional** inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -12242,8 +12136,7 @@ def rnn( B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -12311,8 +12204,7 @@ def random_normal( seed=AttrFloat32.maybe(seed, name="seed"), shape=AttrInt64s(shape, name="shape"), ), - _RandomNormal.Inputs(), - input_prop_values=input_prop_values, + _RandomNormal.Inputs(), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12385,8 +12277,7 @@ def random_normal_like( ), _RandomNormalLike.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12453,8 +12344,7 @@ def random_uniform( seed=AttrFloat32.maybe(seed, name="seed"), shape=AttrInt64s(shape, name="shape"), ), - _RandomUniform.Inputs(), - input_prop_values=input_prop_values, + _RandomUniform.Inputs(), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12527,8 +12417,7 @@ def random_uniform_like( ), _RandomUniformLike.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12611,8 +12500,7 @@ def range( start=unwrap_vars(start), limit=unwrap_vars(limit), delta=unwrap_vars(delta), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12654,8 +12542,7 @@ def reciprocal( _Reciprocal.Attributes(), _Reciprocal.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -12717,8 +12604,7 @@ def reduce_l1( ), _ReduceL1.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12780,8 +12666,7 @@ def reduce_l2( ), _ReduceL2.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12844,8 +12729,7 @@ def reduce_log_sum( ), _ReduceLogSum.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12908,8 +12792,7 @@ def reduce_log_sum_exp( ), _ReduceLogSumExp.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12973,8 +12856,7 @@ def reduce_max( ), _ReduceMax.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13036,8 +12918,7 @@ def reduce_mean( ), _ReduceMean.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13100,8 +12981,7 @@ def reduce_min( ), _ReduceMin.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13163,8 +13043,7 @@ def reduce_prod( ), _ReduceProd.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13239,8 +13118,7 @@ def reduce_sum( _ReduceSum.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13302,8 +13180,7 @@ def reduce_sum_square( ), _ReduceSumSquare.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13345,8 +13222,7 @@ def relu( _Relu.Attributes(), _Relu.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13416,8 +13292,7 @@ def reshape( _Reshape.Inputs( data=unwrap_vars(data), shape=unwrap_vars(shape), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reshaped @@ -13569,8 +13444,7 @@ def resize( roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13652,8 +13526,7 @@ def reverse_sequence( _ReverseSequence.Inputs( input=unwrap_vars(input), sequence_lens=unwrap_vars(sequence_lens), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13769,8 +13642,7 @@ def roi_align( X=unwrap_vars(X), rois=unwrap_vars(rois), batch_indices=unwrap_vars(batch_indices), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13824,8 +13696,7 @@ def round( _Round.Attributes(), _Round.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13909,8 +13780,7 @@ def stft( frame_step=unwrap_vars(frame_step), window=unwrap_vars(window), frame_length=unwrap_vars(frame_length), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14164,8 +14034,7 @@ def scan( initial_state_and_scan_inputs ), ), - out_variadic=len(_body_subgraph.requested_results), - input_prop_values=input_prop_values, + out_variadic=len(_body_subgraph.requested_results), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs @@ -14307,8 +14176,7 @@ def scatter_elements( data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14438,8 +14306,7 @@ def scatter_nd( data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14496,8 +14363,7 @@ def selu( ), _Selu.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -14552,8 +14418,7 @@ def sequence_at( _SequenceAt.Inputs( input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .tensor @@ -14595,8 +14460,7 @@ def sequence_construct( _SequenceConstruct.Attributes(), _SequenceConstruct.Inputs( inputs=unwrap_vars(inputs), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output_sequence @@ -14636,8 +14500,7 @@ def sequence_empty( _SequenceEmpty.Attributes( dtype=AttrDtype.maybe(dtype, name="dtype"), ), - _SequenceEmpty.Inputs(), - input_prop_values=input_prop_values, + _SequenceEmpty.Inputs(), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14692,8 +14555,7 @@ def sequence_erase( _SequenceErase.Inputs( input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output_sequence @@ -14757,8 +14619,7 @@ def sequence_insert( input_sequence=unwrap_vars(input_sequence), tensor=unwrap_vars(tensor), position=unwrap_vars(position), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output_sequence @@ -14800,8 +14661,7 @@ def sequence_length( _SequenceLength.Attributes(), _SequenceLength.Inputs( input_sequence=unwrap_vars(input_sequence), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .length @@ -14881,8 +14741,7 @@ def sequence_map( input_sequence=unwrap_vars(input_sequence), additional_inputs=unwrap_vars(additional_inputs), ), - out_variadic=len(_body_subgraph.requested_results), - input_prop_values=input_prop_values, + out_variadic=len(_body_subgraph.requested_results), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .out_sequence @@ -14976,8 +14835,7 @@ def shape( ), _Shape.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .shape @@ -15032,8 +14890,7 @@ def shrink( ), _Shrink.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15075,8 +14932,7 @@ def sigmoid( _Sigmoid.Attributes(), _Sigmoid.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -15118,8 +14974,7 @@ def sign( _Sign.Attributes(), _Sign.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15159,8 +15014,7 @@ def sin( _Sin.Attributes(), _Sin.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15200,8 +15054,7 @@ def sinh( _Sinh.Attributes(), _Sinh.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15243,8 +15096,7 @@ def size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .size @@ -15380,8 +15232,7 @@ def slice( ends=unwrap_vars(ends), axes=unwrap_vars(axes), steps=unwrap_vars(steps), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15438,8 +15289,7 @@ def softmax( ), _Softmax.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15464,10 +15314,10 @@ def softmax_cross_entropy_loss( L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. After L is available, this operator can optionally do a reduction operator. - - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, - D2,..., Dk), with K >= 1 in case of K-dimensional loss. - - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, - D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, + D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, + D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. The loss for one sample, l_i, can calculated as follows: @@ -15497,13 +15347,13 @@ def softmax_cross_entropy_loss( Finally, L is optionally reduced: - - If reduction = 'none', the output is L with shape (N, D1, D2, ..., - Dk). - - If reduction = 'sum', the output is scalar: Sum(L). - - If reduction = 'mean', the output is scalar: ReduceMean(L), or if - weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W is - of shape ``(N, D1, D2, ..., Dk)`` and - ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. + - If reduction = 'none', the output is L with shape (N, D1, D2, ..., + Dk). + - If reduction = 'sum', the output is scalar: Sum(L). + - If reduction = 'mean', the output is scalar: ReduceMean(L), or if + weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W + is of shape ``(N, D1, D2, ..., Dk)`` and + ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. Parameters ========== @@ -15570,8 +15420,7 @@ def softmax_cross_entropy_loss( scores=unwrap_vars(scores), labels=unwrap_vars(labels), weights=unwrap_vars(weights), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -15613,8 +15462,7 @@ def softplus( _Softplus.Attributes(), _Softplus.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -15656,8 +15504,7 @@ def softsign( _Softsign.Attributes(), _Softsign.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15708,8 +15555,7 @@ def space_to_depth( ), _SpaceToDepth.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15771,8 +15617,7 @@ def split( input=unwrap_vars(input), split=unwrap_vars(split), ), - out_variadic=outputs_count, - input_prop_values=input_prop_values, + out_variadic=outputs_count, # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .outputs @@ -15847,8 +15692,7 @@ def split_to_sequence( _SplitToSequence.Inputs( input=unwrap_vars(input), split=unwrap_vars(split), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output_sequence @@ -15890,8 +15734,7 @@ def sqrt( _Sqrt.Attributes(), _Sqrt.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -15943,8 +15786,7 @@ def squeeze( _Squeeze.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .squeezed @@ -16020,8 +15862,7 @@ def string_normalizer( ), _StringNormalizer.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -16075,8 +15916,7 @@ def sub( _Sub.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -16120,8 +15960,7 @@ def sum( _Sum.Attributes(), _Sum.Inputs( data_0=unwrap_vars(data_0), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .sum @@ -16161,8 +16000,7 @@ def tan( _Tan.Attributes(), _Tan.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16203,8 +16041,7 @@ def tanh( _Tanh.Attributes(), _Tanh.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16358,8 +16195,7 @@ def tf_idf_vectorizer( ), _TfIdfVectorizer.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -16408,8 +16244,7 @@ def thresholded_relu( ), _ThresholdedRelu.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -16460,8 +16295,7 @@ def tile( _Tile.Inputs( input=unwrap_vars(input), repeats=unwrap_vars(repeats), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16481,22 +16315,22 @@ def top_k( Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer argument k, return two outputs: - - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] which contains the values of the top k elements along the - specified axis + - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a\_{n-1}] which contains the values of the top k elements along + the specified axis - - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... - a\_{n-1}] which contains the indices of the top k elements (original - indices from the input tensor). + - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, + ... a\_{n-1}] which contains the indices of the top k elements + (original indices from the input tensor). - - If "largest" is 1 (the default value) then the k largest elements are - returned. + - If "largest" is 1 (the default value) then the k largest elements are + returned. - - If "sorted" is 1 (the default value) then the resulting k elements - will be sorted. + - If "sorted" is 1 (the default value) then the resulting k elements + will be sorted. - - If "sorted" is 0, order of returned 'Values' and 'Indices' are - undefined. + - If "sorted" is 0, order of returned 'Values' and 'Indices' are + undefined. Given two equivalent values, this operator uses the indices along the axis as a tiebreaker. That is, the element with the lower index will @@ -16557,8 +16391,7 @@ def top_k( _TopK.Inputs( X=unwrap_vars(X), K=unwrap_vars(K), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -16608,8 +16441,7 @@ def transpose( ), _Transpose.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .transposed @@ -16681,8 +16513,7 @@ def trilu( _Trilu.Inputs( input=unwrap_vars(input), k=unwrap_vars(k), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16869,8 +16700,7 @@ def unique( ), _Unique.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -16932,8 +16762,7 @@ def unsqueeze( _Unsqueeze.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .expanded @@ -16993,8 +16822,7 @@ def where( condition=unwrap_vars(condition), X=unwrap_vars(X), Y=unwrap_vars(Y), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -17047,8 +16875,7 @@ def xor( _Xor.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index e785969e..c02d6cca 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -943,8 +943,7 @@ def bitwise_and( _BitwiseAnd.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -984,8 +983,7 @@ def bitwise_not( _BitwiseNot.Attributes(), _BitwiseNot.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1037,8 +1035,7 @@ def bitwise_or( _BitwiseOr.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -1090,8 +1087,7 @@ def bitwise_xor( _BitwiseXor.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -1157,8 +1153,7 @@ def center_crop_pad( _CenterCropPad.Inputs( input_data=unwrap_vars(input_data), shape=unwrap_vars(shape), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output_data @@ -1261,8 +1256,7 @@ def col2_im( input=unwrap_vars(input), image_shape=unwrap_vars(image_shape), block_shape=unwrap_vars(block_shape), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1349,8 +1343,7 @@ def group_normalization( X=unwrap_vars(X), scale=unwrap_vars(scale), bias=unwrap_vars(bias), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1481,8 +1474,7 @@ def lp_pool( ), _LpPool.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1529,8 +1521,7 @@ def mish( _Mish.Attributes(), _Mish.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1574,8 +1565,7 @@ def optional_get_element( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1619,8 +1609,7 @@ def optional_has_element( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1777,8 +1766,7 @@ def pad( pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1853,8 +1841,7 @@ def reduce_l1( _ReduceL1.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -1929,8 +1916,7 @@ def reduce_l2( _ReduceL2.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2006,8 +1992,7 @@ def reduce_log_sum( _ReduceLogSum.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2083,8 +2068,7 @@ def reduce_log_sum_exp( _ReduceLogSumExp.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2161,8 +2145,7 @@ def reduce_max( _ReduceMax.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2237,8 +2220,7 @@ def reduce_mean( _ReduceMean.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2314,8 +2296,7 @@ def reduce_min( _ReduceMin.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2390,8 +2371,7 @@ def reduce_prod( _ReduceProd.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2466,8 +2446,7 @@ def reduce_sum_square( _ReduceSumSquare.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2675,8 +2654,7 @@ def resize( roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -2821,8 +2799,7 @@ def scatter_elements( data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -2968,8 +2945,7 @@ def scatter_nd( data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -3037,8 +3013,7 @@ def split( input=unwrap_vars(input), split=unwrap_vars(split), ), - out_variadic=num_outputs, - input_prop_values=input_prop_values, + out_variadic=num_outputs, # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .outputs diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 49608dc1..190c4d1f 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -818,7 +818,8 @@ def average_pool( output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. + ``i``. Sliding windows that would start in the right padded region are + ignored. ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: @@ -930,8 +931,7 @@ def average_pool( ), _AveragePool.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -975,26 +975,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules if the destination type is not a float 8 type. - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Float 8 type were introduced to speed up the training of deep models. By default the conversion of a float *x* obeys to the following rules. @@ -1070,8 +1070,7 @@ def cast( ), _Cast.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1133,8 +1132,7 @@ def cast_like( _CastLike.Inputs( input=unwrap_vars(input), target_type=unwrap_vars(target_type), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1208,8 +1206,7 @@ def constant( value_string=AttrString.maybe(value_string, name="value_string"), value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), - _Constant.Inputs(), - input_prop_values=input_prop_values, + _Constant.Inputs(), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1335,8 +1332,7 @@ def deform_conv( offset=unwrap_vars(offset), B=unwrap_vars(B), mask=unwrap_vars(mask), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1380,11 +1376,9 @@ def dequantize_linear( axis Attribute. (Optional) The axis of the dequantizing dimension of the input tensor. - Used only for per-axis quantization. Negative value means counting - dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. When the rank of the input is 1, per-tensor - quantization is applied, rendering the axis unnecessary in this - scenario. + Ignored for per-tensor quantization. Negative value means counting + dimensions from the back. Accepted range is [-r, r-1] where r = + rank(input). Returns ======= @@ -1414,8 +1408,7 @@ def dequantize_linear( x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -1468,8 +1461,7 @@ def equal( _Equal.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -1509,8 +1501,7 @@ def identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1583,8 +1574,9 @@ def if_( _If.Inputs( cond=unwrap_vars(cond), ), - out_variadic=len(_else_branch_subgraph.requested_results), - input_prop_values=input_prop_values, + out_variadic=len( + _else_branch_subgraph.requested_results + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .outputs @@ -1616,21 +1608,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond = - ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond = - true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -1787,8 +1779,7 @@ def loop( cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), - out_variadic=len(_body_subgraph.requested_results) - 1, - input_prop_values=input_prop_values, + out_variadic=len(_body_subgraph.requested_results) - 1, # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs @@ -1971,8 +1962,7 @@ def pad( pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -2060,8 +2050,7 @@ def quantize_linear( x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -2131,8 +2120,7 @@ def reshape( _Reshape.Inputs( data=unwrap_vars(data), shape=unwrap_vars(shape), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reshaped @@ -2378,8 +2366,7 @@ def resize( roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -2633,8 +2620,7 @@ def scan( initial_state_and_scan_inputs ), ), - out_variadic=len(_body_subgraph.requested_results), - input_prop_values=input_prop_values, + out_variadic=len(_body_subgraph.requested_results), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs @@ -2728,8 +2714,7 @@ def shape( ), _Shape.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .shape @@ -2771,8 +2756,7 @@ def size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .size diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index c5c1db85..d7584d4b 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -744,8 +744,7 @@ def affine_grid( _AffineGrid.Inputs( theta=unwrap_vars(theta), size=unwrap_vars(size), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .grid @@ -799,8 +798,7 @@ def constant_of_shape( ), _ConstantOfShape.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -912,8 +910,7 @@ def dft( input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), axis=unwrap_vars(axis), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -968,8 +965,7 @@ def gelu( ), _Gelu.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1092,8 +1088,7 @@ def grid_sample( _GridSample.Inputs( X=unwrap_vars(X), grid=unwrap_vars(grid), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1110,21 +1105,21 @@ def image_decoder( reason (e.g. corrupted encoded stream, invalid format, it will return an empty matrix). The following image formats are supported: - - BMP - - JPEG (note: Lossless JPEG support is optional) - - JPEG2000 - - TIFF - - PNG - - WebP - - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow - a channel-last layout: (Height, Width, Channels). **JPEG chroma - upsampling method:** When upsampling the chroma components by a factor - of 2, the pixels are linearly interpolated so that the centers of the - output pixels are 1/4 and 3/4 of the way between input pixel centers. - When rounding, 0.5 is rounded down and up at alternative pixels - locations to prevent bias towards larger values (ordered dither - pattern). Considering adjacent input pixels A, B, and C, B is - upsampled to pixels B0 and B1 so that + - BMP + - JPEG (note: Lossless JPEG support is optional) + - JPEG2000 + - TIFF + - PNG + - WebP + - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow + a channel-last layout: (Height, Width, Channels). **JPEG chroma + upsampling method:** When upsampling the chroma components by a + factor of 2, the pixels are linearly interpolated so that the centers + of the output pixels are 1/4 and 3/4 of the way between input pixel + centers. When rounding, 0.5 is rounded down and up at alternative + pixels locations to prevent bias towards larger values (ordered + dither pattern). Considering adjacent input pixels A, B, and C, B is + upsampled to pixels B0 and B1 so that :: @@ -1168,8 +1163,7 @@ def image_decoder( ), _ImageDecoder.Inputs( encoded_stream=unwrap_vars(encoded_stream), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .image @@ -1226,8 +1220,7 @@ def isinf( ), _IsInf.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1268,8 +1261,7 @@ def isnan( _IsNaN.Attributes(), _IsNaN.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1349,8 +1341,7 @@ def reduce_max( _ReduceMax.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -1429,8 +1420,7 @@ def reduce_min( _ReduceMin.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -1483,8 +1473,7 @@ def regex_full_match( ), _RegexFullMatch.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1531,8 +1520,7 @@ def string_concat( _StringConcat.Inputs( X=unwrap_vars(X), Y=unwrap_vars(Y), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Z @@ -1619,8 +1607,7 @@ def string_split( ), _StringSplit.Inputs( X=unwrap_vars(X), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 6256ad83..539ef4d0 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -877,26 +877,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules if the destination type is not a float 8 type. - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Float 8 type were introduced to speed up the training of deep models. By default the conversion of a float *x* obeys to the following rules. @@ -972,8 +972,7 @@ def cast( ), _Cast.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1035,8 +1034,7 @@ def cast_like( _CastLike.Inputs( input=unwrap_vars(input), target_type=unwrap_vars(target_type), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1110,8 +1108,7 @@ def constant( value_string=AttrString.maybe(value_string, name="value_string"), value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), - _Constant.Inputs(), - input_prop_values=input_prop_values, + _Constant.Inputs(), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1165,8 +1162,7 @@ def constant_of_shape( ), _ConstantOfShape.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1256,8 +1252,7 @@ def dequantize_linear( x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -1313,8 +1308,7 @@ def flatten( ), _Flatten.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1416,8 +1410,7 @@ def group_normalization( X=unwrap_vars(X), scale=unwrap_vars(scale), bias=unwrap_vars(bias), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1457,8 +1450,7 @@ def identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1531,8 +1523,9 @@ def if_( _If.Inputs( cond=unwrap_vars(cond), ), - out_variadic=len(_else_branch_subgraph.requested_results), - input_prop_values=input_prop_values, + out_variadic=len( + _else_branch_subgraph.requested_results + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .outputs @@ -1564,21 +1557,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond = - ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond + = ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond = - true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond + = true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -1735,8 +1728,7 @@ def loop( cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), - out_variadic=len(_body_subgraph.requested_results) - 1, - input_prop_values=input_prop_values, + out_variadic=len(_body_subgraph.requested_results) - 1, # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs @@ -1919,8 +1911,7 @@ def pad( pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1938,8 +1929,8 @@ def qlinear_matmul( y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like - `numpy.matmul `__. + Matrix product that behaves like numpy.matmul: + https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). For @@ -2022,8 +2013,7 @@ def qlinear_matmul( b_zero_point=unwrap_vars(b_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -2049,12 +2039,12 @@ def quantize_linear( Saturation is done according to: - - uint16: [0, 65535] - - int16: [-32768, 32767] - - uint8: [0, 255] - - int8: [-128, 127] - - uint4: [0, 15] - - int4: [-8, 7] + - uint16: [0, 65535] + - int16: [-32768, 32767] + - uint8: [0, 255] + - int8: [-128, 127] + - uint4: [0, 15] + - int4: [-8, 7] For ``(x / y_scale)``, it rounds to the nearest even. Refer to https://en.wikipedia.org/wiki/Rounding for details. @@ -2068,15 +2058,15 @@ def quantize_linear( shape of ``y_scale``. In all cases, ``y_zero_point`` must have the same shape as ``y_scale``. - - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. - - Per-axis quantization: The scale must be a 1-D tensor, with the length - of the quantization axis. For an input shape - ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D tensor - of length ``Di``. - - Blocked quantization: The scale's shape is identical to the input's - shape, except for one dimension, in which blocking is performed. Given - ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block size - ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. + - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. + - Per-axis quantization: The scale must be a 1-D tensor, with the + length of the quantization axis. For an input shape + ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D + tensor of length ``Di``. + - Blocked quantization: The scale's shape is identical to the input's + shape, except for one dimension, in which blocking is performed. + Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block + size ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. Parameters ========== @@ -2096,11 +2086,9 @@ def quantize_linear( axis Attribute. (Optional) The axis of the dequantizing dimension of the input tensor. - Used only for per-axis and blocked quantization. Negative value means + Used for per-axis and blocked quantization. Negative value means counting dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. When the rank of the input is 1, per-tensor - quantization is applied, rendering the axis unnecessary in this - scenario. + ``r = rank(input)``. block_size Attribute. (Optional) The size of the quantization block (number of times every @@ -2154,8 +2142,7 @@ def quantize_linear( x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -2225,8 +2212,7 @@ def reshape( _Reshape.Inputs( data=unwrap_vars(data), shape=unwrap_vars(shape), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .reshaped @@ -2480,8 +2466,7 @@ def scan( initial_state_and_scan_inputs ), ), - out_variadic=len(_body_subgraph.requested_results), - input_prop_values=input_prop_values, + out_variadic=len(_body_subgraph.requested_results), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs @@ -2575,8 +2560,7 @@ def shape( ), _Shape.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .shape @@ -2618,8 +2602,7 @@ def size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .size @@ -2671,8 +2654,7 @@ def squeeze( _Squeeze.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .squeezed @@ -2723,8 +2705,7 @@ def transpose( ), _Transpose.Inputs( data=unwrap_vars(data), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .transposed @@ -2786,8 +2767,7 @@ def unsqueeze( _Unsqueeze.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), - input_prop_values=input_prop_values, + ), # infer_types=False ) .get_output_vars(input_prop_values=input_prop_values) .expanded diff --git a/tests/test_function.py b/tests/test_function.py index aa7d7c08..4728b9b4 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -44,7 +44,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def constructor(self, attrs: dict[str, Attr], inputs: Inputs.Vars) -> Outputs: + def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: # FIXME: At some point, attribute references should be properly type-hinted. a = op.constant( value_float=_Ref( diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index ff5f842e..c3c4e7eb 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -42,7 +42,6 @@ endfor %} if schema.outputs and is_variadic(schema.outputs[-1]) %}out_variadic={{ out_variadic_solution if out_variadic_solution else "{}_count".format(schema.outputs[-1].name) }}, {% endif %} - input_prop_values=input_prop_values ).get_output_vars(input_prop_values=input_prop_values){% if schema.outputs | length <= 1 %}.{{ schema.outputs[0].name }}{% From 07f9676abd4d6d38e4045ce23c6f2d1887cfc9ff Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Mon, 18 Nov 2024 23:15:55 +0200 Subject: [PATCH 17/29] Improve type checking --- CHANGELOG.rst | 4 + src/spox/_build.py | 2 +- src/spox/_fields.py | 24 +- src/spox/_internal_op.py | 6 +- src/spox/_node.py | 8 +- src/spox/_public.py | 5 +- src/spox/_standard.py | 6 +- src/spox/_type_system.py | 5 +- src/spox/_value_prop.py | 9 +- src/spox/opset/ai/onnx/ml/v3.py | 63 +-- src/spox/opset/ai/onnx/ml/v4.py | 8 +- src/spox/opset/ai/onnx/ml/v5.py | 8 +- src/spox/opset/ai/onnx/v17.py | 371 +++++++++--------- src/spox/opset/ai/onnx/v18.py | 56 +-- src/spox/opset/ai/onnx/v19.py | 47 +-- src/spox/opset/ai/onnx/v20.py | 32 +- src/spox/opset/ai/onnx/v21.py | 53 +-- tools/generate_opset.py | 2 +- tools/templates/class.jinja2 | 4 +- tools/templates/preamble.jinja2 | 6 +- .../type_inference/loop16-fix.jinja2 | 2 +- 21 files changed, 373 insertions(+), 348 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2f2b3be4..ffd276ca 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,10 @@ Change log 0.13.0 (unreleased) ------------------- +**Other changes** + +- Split `Var`-s internally to help the garbage collector in collecting propagated values. + **Support change** - Support for ``Python 3.8`` has been dropped. diff --git a/src/spox/_build.py b/src/spox/_build.py index 8d782ba5..84f93e8e 100644 --- a/src/spox/_build.py +++ b/src/spox/_build.py @@ -410,7 +410,7 @@ def compile_graph( self, graph: "Graph", scope: Scope, prefix: str = "" ) -> BuildResult: """ - Compile a given Graph into a BuildResult. Handles naming of all the VarInfos/Nodes and only adds Nodes to a + Compile a given Graph into a BuildResult. Handles naming of all the Vars/Nodes and only adds Nodes to a Graph that should be present in the respective GraphProto. The passed Scope object is aware of values already available in the outer scope and may be the source of errors if the build fails. diff --git a/src/spox/_fields.py b/src/spox/_fields.py index bfbe6c56..cb92f413 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -6,11 +6,11 @@ import warnings from collections.abc import Iterable, Iterator, Sequence from dataclasses import dataclass -from typing import Any, Optional, Union +from typing import Any, Optional, Union, cast from ._attributes import Attr from ._exceptions import InferenceWarning -from ._value_prop import PropValue +from ._value_prop import PropDict, PropValue from ._var import Var, VarInfo @@ -156,7 +156,10 @@ def fully_typed(self) -> bool: @dataclass class BaseInputs(BaseVarInfos): - def vars(self, prop_values): + def vars(self, prop_values: Optional[PropDict] = None) -> BaseVars: + if prop_values is None: + prop_values = {} + vars_dict: dict[str, Union[Var, Sequence[Var]]] = {} for field in dataclasses.fields(self): @@ -164,19 +167,22 @@ def vars(self, prop_values): field_value = getattr(self, field.name) if field_type == VarFieldKind.SINGLE: - vars_dict[field.name] = Var(field_value, prop_values[field.name]) + prop_value = cast(PropValue, prop_values[field.name]) + vars_dict[field.name] = Var(field_value, prop_value) elif ( field_type == VarFieldKind.OPTIONAL and prop_values.get(field.name, None) is not None ): - vars_dict[field.name] = Var(field_value, prop_values[field.name]) + prop_value = cast(PropValue, prop_values[field.name]) + vars_dict[field.name] = Var(field_value, prop_value) elif field_type == VarFieldKind.VARIADIC: vars = [] for i, var_info in enumerate(field_value): var_value = prop_values.get(f"{field.name}_{i}", None) + assert isinstance(var_value, PropValue) vars.append(Var(var_info, var_value)) vars_dict[field.name] = vars @@ -186,10 +192,10 @@ def vars(self, prop_values): @dataclass class BaseOutputs(BaseVarInfos): - def _propagate_vars( - self, - prop_values={}, - ): + def _propagate_vars(self, prop_values: Optional[PropDict] = None) -> BaseVars: + if prop_values is None: + prop_values = {} + def _create_var(key, var_info): ret = Var(var_info, None) diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index 99c47664..a0618cf0 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -19,7 +19,7 @@ from ._scope import Scope from ._shape import SimpleShape from ._type_system import Tensor, Type -from ._value_prop import PropValueType +from ._value_prop import PropDict, PropValueType from ._var import Var, VarInfo, unwrap_vars # This is a default used for internal operators that @@ -121,12 +121,12 @@ class Outputs(BaseOutputs): inputs: BaseInputs outputs: Outputs - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: # Output type is based on the value of the type attribute arr = self.attrs.value.value return {"arg": Tensor(arr.dtype, arr.shape)} - def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values: PropDict) -> dict[str, PropValueType]: return {"arg": self.attrs.value.value} def update_metadata(self, opset_req, initializers, functions): diff --git a/src/spox/_node.py b/src/spox/_node.py index ba0c9a45..c4524e29 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -18,7 +18,8 @@ from ._debug import STORE_TRACEBACK from ._exceptions import InferenceWarning from ._fields import BaseAttributes, BaseInputs, BaseOutputs, VarFieldKind -from ._type_system import PropDict, Type +from ._type_system import Type +from ._value_prop import PropDict from ._var import VarInfo if typing.TYPE_CHECKING: @@ -94,7 +95,6 @@ def __init__( out_variadic: Optional[int] = None, infer_types: bool = True, validate: bool = True, - input_prop_values: PropDict = {}, **kwargs, ): """ @@ -126,7 +126,7 @@ def __init__( # As inference functions may access which output vars we initialized (e.g. variadics) # we inject uninitialized vars first self.outputs = self._init_output_vars() - self.inference(infer_types=infer_types, input_prop_values={}) + self.inference(infer_types=infer_types) else: self.outputs = outputs @@ -214,7 +214,7 @@ def propagate_values(self, input_prop_values: PropDict) -> PropDict: """ return {} - def infer_output_types(self, input_prop_values) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: """ Inference routine for output types. Often overriden by inheriting Node types. diff --git a/src/spox/_public.py b/src/spox/_public.py index b134e9a4..7911c474 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -17,6 +17,7 @@ from ._inline import _Inline from ._standard import _strip_dim_symbol from ._type_system import Type +from ._value_prop import PropDict from ._var import Var @@ -307,9 +308,9 @@ def inline_inner(*args: Var, **kwargs: Var) -> dict[str, Var]: model=model, ) - prop_values = { + prop_values: PropDict = { name: kwargs[name]._value - for i, name in enumerate(in_names) + for name in in_names if kwargs[name]._value is not None } diff --git a/src/spox/_standard.py b/src/spox/_standard.py index ecfada81..d1143f23 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -17,9 +17,9 @@ from ._schemas import SCHEMAS from ._scope import Scope from ._shape import SimpleShape -from ._type_system import Optional, PropDict, Sequence, Tensor, Type +from ._type_system import Optional, Sequence, Tensor, Type from ._utils import from_array -from ._value_prop import PropValue, PropValueType +from ._value_prop import PropDict, PropValue, PropValueType if TYPE_CHECKING: from ._graph import Graph @@ -209,7 +209,7 @@ def propagate_values_onnx( } return {k: v for k, v in results.items() if k is not None} - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: return self.infer_output_types_onnx(input_prop_values) def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: diff --git a/src/spox/_type_system.py b/src/spox/_type_system.py index 6450f839..27c2695b 100644 --- a/src/spox/_type_system.py +++ b/src/spox/_type_system.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause from dataclasses import dataclass -from typing import Any, TypeVar +from typing import TypeVar import numpy as np import numpy.typing as npt @@ -14,9 +14,6 @@ T = TypeVar("T") S = TypeVar("S") -# TODO: Fix typing -PropDict = dict[str, Any] - @dataclass(frozen=True) class Type: diff --git a/src/spox/_value_prop.py b/src/spox/_value_prop.py index 62a701da..2e01f86c 100644 --- a/src/spox/_value_prop.py +++ b/src/spox/_value_prop.py @@ -4,8 +4,10 @@ import enum import logging import warnings +from collections.abc import Iterable from dataclasses import dataclass from typing import Callable, Union +from typing import Optional as tOptional import numpy as np import numpy.typing as npt @@ -24,9 +26,10 @@ - PropValue -> Optional, Some (has value) - None -> Optional, Nothing (no value) """ -PropValueType = Union[np.ndarray, list["PropValue"], "PropValue", None] -ORTValue = Union[np.ndarray, list, None] -RefValue = Union[np.ndarray, list, float, None] +PropValueType = Union[np.ndarray, Iterable[tOptional["PropValue"]], "PropValue", None] +PropDict = dict[str, Union[Iterable[tOptional["PropValue"]], "PropValue", None]] +ORTValue = Union[np.ndarray, Iterable, None] +RefValue = Union[np.ndarray, Iterable, float, None] VALUE_PROP_STRICT_CHECK: bool = False diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index d51bf91e..f46c83a6 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -4,7 +4,9 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import Optional +from typing import ( + Optional, +) import numpy as np @@ -20,7 +22,8 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import PropDict, Tensor, Type +from spox._type_system import Tensor, Type +from spox._value_prop import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars @@ -38,7 +41,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Z: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: return {} xt, yt = self.inputs.X.unwrap_tensor(), self.inputs.Y.unwrap_tensor() @@ -73,7 +76,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {} op_type = OpType("Binarizer", "ai.onnx.ml", 1) @@ -121,7 +124,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: return {} cats1, cats2 = self.attrs.cats_int64s, self.attrs.cats_strings @@ -197,7 +200,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: return {} t = self.inputs.X.unwrap_tensor() @@ -309,7 +312,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: return {} sim = self.inputs.X.unwrap_tensor().shape @@ -343,7 +346,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if self.attrs.norm.value not in ("MAX", "L1", "L2"): raise InferenceError( f"Unknown normalisation method `{self.attrs.norm.value}`" @@ -372,7 +375,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: return {} if self.attrs.cats_int64s: @@ -465,7 +468,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if self.inputs.X.type is None: return {} sc, off = self.attrs.scale, self.attrs.offset @@ -525,7 +528,7 @@ class Outputs(BaseOutputs): Y: VarInfo Z: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: e = ( len(self.attrs.class_ids.value) if self.attrs.class_ids is not None @@ -589,7 +592,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): Y: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if self.inputs.fully_typed: shape = self.inputs.X.unwrap_tensor().shape assert shape is not None # already checked with fully_typed @@ -670,7 +673,7 @@ def array_feature_extractor( _ArrayFeatureExtractor.Inputs( X=unwrap_vars(X), Y=unwrap_vars(Y), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Z @@ -718,7 +721,7 @@ def binarizer( ), _Binarizer.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -784,7 +787,7 @@ def cast_map( ), _CastMap.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -859,7 +862,7 @@ def category_mapper( ), _CategoryMapper.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -931,7 +934,7 @@ def dict_vectorizer( ), _DictVectorizer.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -984,7 +987,7 @@ def feature_vectorizer( ), _FeatureVectorizer.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1067,7 +1070,7 @@ def imputer( ), _Imputer.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1172,7 +1175,7 @@ def label_encoder( ), _LabelEncoder.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1255,7 +1258,7 @@ def linear_classifier( ), _LinearClassifier.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -1324,7 +1327,7 @@ def linear_regressor( ), _LinearRegressor.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1377,7 +1380,7 @@ def normalizer( ), _Normalizer.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1445,7 +1448,7 @@ def one_hot_encoder( ), _OneHotEncoder.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1562,7 +1565,7 @@ def svmclassifier( ), _SVMClassifier.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -1649,7 +1652,7 @@ def svmregressor( ), _SVMRegressor.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1706,7 +1709,7 @@ def scaler( ), _Scaler.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1900,7 +1903,7 @@ def tree_ensemble_classifier( ), _TreeEnsembleClassifier.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -2092,7 +2095,7 @@ def tree_ensemble_regressor( ), _TreeEnsembleRegressor.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -2154,7 +2157,7 @@ def zip_map( ), _ZipMap.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Z diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index 9e2b3426..1406e125 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -4,7 +4,9 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable from dataclasses import dataclass -from typing import Optional +from typing import ( + Optional, +) import numpy as np @@ -20,7 +22,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._type_system import PropDict +from spox._value_prop import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.ml.v3 import ( _ArrayFeatureExtractor, @@ -211,7 +213,7 @@ def label_encoder( ), _LabelEncoder.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index 03dd1880..db93d63f 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -4,7 +4,9 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable from dataclasses import dataclass -from typing import Optional +from typing import ( + Optional, +) import numpy as np @@ -16,7 +18,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._type_system import PropDict +from spox._value_prop import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.ml.v4 import ( _ArrayFeatureExtractor, @@ -259,7 +261,7 @@ def tree_ensemble( ), _TreeEnsemble.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 82d578a1..eb9132ae 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -4,7 +4,10 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import Callable, Optional +from typing import ( + Callable, + Optional, +) from typing import cast as typing_cast import numpy as np @@ -26,9 +29,9 @@ from spox._graph import Graph, subgraph from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import PropDict, Tensor, Type from spox._type_system import Sequence as SpoxSequence -from spox._value_prop import PropValueType +from spox._type_system import Tensor, Type +from spox._value_prop import PropDict, PropValueType from spox._var import Var, VarInfo, get_value, unwrap_vars @@ -491,7 +494,7 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): output: VarInfo - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: self.infer_output_types_onnx() inp, cond = ( self.inputs.input.unwrap_tensor(), @@ -582,7 +585,7 @@ class Attributes(BaseAttributes): class Outputs(BaseOutputs): output: VarInfo - def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values: PropDict) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -1771,8 +1774,8 @@ class Inputs(BaseInputs): class Outputs(BaseOutputs): v_final_and_scan_outputs: Sequence[VarInfo] - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: - output_types = super().infer_output_types() + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: + output_types = super().infer_output_types({}) body = self.attrs.body.value n = len(body.requested_arguments) - 2 @@ -3963,7 +3966,7 @@ def abs( _Abs.Attributes(), _Abs.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -4004,7 +4007,7 @@ def acos( _Acos.Attributes(), _Acos.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4046,7 +4049,7 @@ def acosh( _Acosh.Attributes(), _Acosh.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4100,7 +4103,7 @@ def add( _Add.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -4153,7 +4156,7 @@ def and_( _And.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -4222,7 +4225,7 @@ def arg_max( ), _ArgMax.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -4291,7 +4294,7 @@ def arg_min( ), _ArgMin.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -4332,7 +4335,7 @@ def asin( _Asin.Attributes(), _Asin.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4373,7 +4376,7 @@ def asinh( _Asinh.Attributes(), _Asinh.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4414,7 +4417,7 @@ def atan( _Atan.Attributes(), _Atan.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4456,7 +4459,7 @@ def atanh( _Atanh.Attributes(), _Atanh.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4601,7 +4604,7 @@ def average_pool( ), _AveragePool.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -4748,7 +4751,7 @@ def batch_normalization( B=unwrap_vars(B), input_mean=unwrap_vars(input_mean), input_var=unwrap_vars(input_var), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -4811,7 +4814,7 @@ def bernoulli( ), _Bernoulli.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -4880,7 +4883,7 @@ def bit_shift( _BitShift.Inputs( X=unwrap_vars(X), Y=unwrap_vars(Y), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Z @@ -4939,7 +4942,7 @@ def blackman_window( ), _BlackmanWindow.Inputs( size=unwrap_vars(size), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5038,7 +5041,7 @@ def cast( ), _Cast.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5089,7 +5092,7 @@ def cast_like( _CastLike.Inputs( input=unwrap_vars(input), target_type=unwrap_vars(target_type), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5132,7 +5135,7 @@ def ceil( _Ceil.Attributes(), _Ceil.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -5185,7 +5188,7 @@ def celu( ), _Celu.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -5241,7 +5244,7 @@ def clip( input=unwrap_vars(input), min=unwrap_vars(min), max=unwrap_vars(max), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5306,7 +5309,7 @@ def compress( _Compress.Inputs( input=unwrap_vars(input), condition=unwrap_vars(condition), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5356,7 +5359,7 @@ def concat( ), _Concat.Inputs( inputs=unwrap_vars(inputs), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .concat_result @@ -5416,7 +5419,7 @@ def concat_from_sequence( ), _ConcatFromSequence.Inputs( input_sequence=unwrap_vars(input_sequence), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .concat_result @@ -5490,7 +5493,7 @@ def constant( value_string=AttrString.maybe(value_string, name="value_string"), value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), - _Constant.Inputs(), # infer_types=False + _Constant.Inputs(), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5544,7 +5547,7 @@ def constant_of_shape( ), _ConstantOfShape.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -5667,7 +5670,7 @@ def conv( X=unwrap_vars(X), W=unwrap_vars(W), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -5803,7 +5806,7 @@ def conv_integer( w=unwrap_vars(w), x_zero_point=unwrap_vars(x_zero_point), w_zero_point=unwrap_vars(w_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -5959,7 +5962,7 @@ def conv_transpose( X=unwrap_vars(X), W=unwrap_vars(W), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -5999,7 +6002,7 @@ def cos( _Cos.Attributes(), _Cos.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6039,7 +6042,7 @@ def cosh( _Cosh.Attributes(), _Cosh.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6124,7 +6127,7 @@ def cumsum( _CumSum.Inputs( x=unwrap_vars(x), axis=unwrap_vars(axis), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -6218,7 +6221,7 @@ def dft( _DFT.Inputs( input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6298,7 +6301,7 @@ def depth_to_space( ), _DepthToSpace.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6369,7 +6372,7 @@ def dequantize_linear( x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -6414,7 +6417,7 @@ def det( _Det.Attributes(), _Det.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -6468,7 +6471,7 @@ def div( _Div.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -6565,7 +6568,7 @@ def dropout( data=unwrap_vars(data), ratio=unwrap_vars(ratio), training_mode=unwrap_vars(training_mode), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -6647,7 +6650,7 @@ def dynamic_quantize_linear( _DynamicQuantizeLinear.Attributes(), _DynamicQuantizeLinear.Inputs( x=unwrap_vars(x), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -6726,7 +6729,7 @@ def einsum( ), _Einsum.Inputs( Inputs=unwrap_vars(Inputs), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Output @@ -6776,7 +6779,7 @@ def elu( ), _Elu.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -6829,7 +6832,7 @@ def equal( _Equal.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -6870,7 +6873,7 @@ def erf( _Erf.Attributes(), _Erf.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6910,7 +6913,7 @@ def exp( _Exp.Attributes(), _Exp.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -6965,7 +6968,7 @@ def expand( _Expand.Inputs( input=unwrap_vars(input), shape=unwrap_vars(shape), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7031,7 +7034,7 @@ def eye_like( ), _EyeLike.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7087,7 +7090,7 @@ def flatten( ), _Flatten.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7130,7 +7133,7 @@ def floor( _Floor.Attributes(), _Floor.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -7342,7 +7345,7 @@ def gru( B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -7447,7 +7450,7 @@ def gather( _Gather.Inputs( data=unwrap_vars(data), indices=unwrap_vars(indices), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7560,7 +7563,7 @@ def gather_elements( _GatherElements.Inputs( data=unwrap_vars(data), indices=unwrap_vars(indices), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7718,7 +7721,7 @@ def gather_nd( _GatherND.Inputs( data=unwrap_vars(data), indices=unwrap_vars(indices), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -7815,7 +7818,7 @@ def gemm( A=unwrap_vars(A), B=unwrap_vars(B), C=unwrap_vars(C), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -7864,7 +7867,7 @@ def global_average_pool( _GlobalAveragePool.Attributes(), _GlobalAveragePool.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -7920,7 +7923,7 @@ def global_lp_pool( ), _GlobalLpPool.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -7969,7 +7972,7 @@ def global_max_pool( _GlobalMaxPool.Attributes(), _GlobalMaxPool.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8022,7 +8025,7 @@ def greater( _Greater.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -8075,7 +8078,7 @@ def greater_or_equal( _GreaterOrEqual.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -8178,7 +8181,7 @@ def grid_sample( _GridSample.Inputs( X=unwrap_vars(X), grid=unwrap_vars(grid), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8237,7 +8240,7 @@ def hamming_window( ), _HammingWindow.Inputs( size=unwrap_vars(size), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8296,7 +8299,7 @@ def hann_window( ), _HannWindow.Inputs( size=unwrap_vars(size), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8350,7 +8353,7 @@ def hard_sigmoid( ), _HardSigmoid.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8393,7 +8396,7 @@ def hard_swish( _HardSwish.Attributes(), _HardSwish.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8449,7 +8452,7 @@ def hardmax( ), _Hardmax.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8489,7 +8492,7 @@ def identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8562,9 +8565,7 @@ def if_( _If.Inputs( cond=unwrap_vars(cond), ), - out_variadic=len( - _else_branch_subgraph.requested_results - ), # infer_types=False + out_variadic=len(_else_branch_subgraph.requested_results), ) .get_output_vars(input_prop_values=input_prop_values) .outputs @@ -8631,7 +8632,7 @@ def instance_normalization( input=unwrap_vars(input), scale=unwrap_vars(scale), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -8688,7 +8689,7 @@ def isinf( ), _IsInf.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8729,7 +8730,7 @@ def isnan( _IsNaN.Attributes(), _IsNaN.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -8808,7 +8809,7 @@ def lrn( ), _LRN.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9044,7 +9045,7 @@ def lstm( initial_h=unwrap_vars(initial_h), initial_c=unwrap_vars(initial_c), P=unwrap_vars(P), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -9150,7 +9151,7 @@ def layer_normalization( X=unwrap_vars(X), Scale=unwrap_vars(Scale), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -9200,7 +9201,7 @@ def leaky_relu( ), _LeakyRelu.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9253,7 +9254,7 @@ def less( _Less.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -9306,7 +9307,7 @@ def less_or_equal( _LessOrEqual.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -9346,7 +9347,7 @@ def log( _Log.Attributes(), _Log.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -9401,7 +9402,7 @@ def log_softmax( ), _LogSoftmax.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -9604,7 +9605,7 @@ def loop( cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), - out_variadic=len(_body_subgraph.requested_results) - 1, # infer_types=False + out_variadic=len(_body_subgraph.requested_results) - 1, ) .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs @@ -9656,7 +9657,7 @@ def lp_normalization( ), _LpNormalization.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -9748,7 +9749,7 @@ def lp_pool( ), _LpPool.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9795,7 +9796,7 @@ def matmul( _MatMul.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9868,7 +9869,7 @@ def matmul_integer( B=unwrap_vars(B), a_zero_point=unwrap_vars(a_zero_point), b_zero_point=unwrap_vars(b_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -9912,7 +9913,7 @@ def max( _Max.Attributes(), _Max.Inputs( data_0=unwrap_vars(data_0), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .max @@ -10072,7 +10073,7 @@ def max_pool( ), _MaxPool.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -10137,7 +10138,7 @@ def max_roi_pool( _MaxRoiPool.Inputs( X=unwrap_vars(X), rois=unwrap_vars(rois), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -10256,7 +10257,7 @@ def max_unpool( X=unwrap_vars(X), I=unwrap_vars(I), output_shape=unwrap_vars(output_shape), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -10300,7 +10301,7 @@ def mean( _Mean.Attributes(), _Mean.Inputs( data_0=unwrap_vars(data_0), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .mean @@ -10352,7 +10353,7 @@ def mean_variance_normalization( ), _MeanVarianceNormalization.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -10451,7 +10452,7 @@ def mel_weight_matrix( sample_rate=unwrap_vars(sample_rate), lower_edge_hertz=unwrap_vars(lower_edge_hertz), upper_edge_hertz=unwrap_vars(upper_edge_hertz), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -10495,7 +10496,7 @@ def min( _Min.Attributes(), _Min.Inputs( data_0=unwrap_vars(data_0), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .min @@ -10566,7 +10567,7 @@ def mod( _Mod.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -10620,7 +10621,7 @@ def mul( _Mul.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -10686,7 +10687,7 @@ def multinomial( ), _Multinomial.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -10728,7 +10729,7 @@ def neg( _Neg.Attributes(), _Neg.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -10907,7 +10908,7 @@ def negative_log_likelihood_loss( input=unwrap_vars(input), target=unwrap_vars(target), weight=unwrap_vars(weight), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .loss @@ -10998,7 +10999,7 @@ def non_max_suppression( max_output_boxes_per_class=unwrap_vars(max_output_boxes_per_class), iou_threshold=unwrap_vars(iou_threshold), score_threshold=unwrap_vars(score_threshold), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .selected_indices @@ -11042,7 +11043,7 @@ def non_zero( _NonZero.Attributes(), _NonZero.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -11082,7 +11083,7 @@ def not_( _Not.Attributes(), _Not.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -11184,7 +11185,7 @@ def one_hot( indices=unwrap_vars(indices), depth=unwrap_vars(depth), values=unwrap_vars(values), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11234,7 +11235,7 @@ def optional( ), _Optional.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11277,7 +11278,7 @@ def optional_get_element( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11320,7 +11321,7 @@ def optional_has_element( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11373,7 +11374,7 @@ def or_( _Or.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -11426,7 +11427,7 @@ def prelu( _PRelu.Inputs( X=unwrap_vars(X), slope=unwrap_vars(slope), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -11541,7 +11542,7 @@ def pad( data=unwrap_vars(data), pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -11593,7 +11594,7 @@ def pow( _Pow.Inputs( X=unwrap_vars(X), Y=unwrap_vars(Y), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Z @@ -11771,7 +11772,7 @@ def qlinear_conv( y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -11872,7 +11873,7 @@ def qlinear_matmul( b_zero_point=unwrap_vars(b_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -11947,7 +11948,7 @@ def quantize_linear( x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -12136,7 +12137,7 @@ def rnn( B=unwrap_vars(B), sequence_lens=unwrap_vars(sequence_lens), initial_h=unwrap_vars(initial_h), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -12204,7 +12205,7 @@ def random_normal( seed=AttrFloat32.maybe(seed, name="seed"), shape=AttrInt64s(shape, name="shape"), ), - _RandomNormal.Inputs(), # infer_types=False + _RandomNormal.Inputs(), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12277,7 +12278,7 @@ def random_normal_like( ), _RandomNormalLike.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12344,7 +12345,7 @@ def random_uniform( seed=AttrFloat32.maybe(seed, name="seed"), shape=AttrInt64s(shape, name="shape"), ), - _RandomUniform.Inputs(), # infer_types=False + _RandomUniform.Inputs(), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12417,7 +12418,7 @@ def random_uniform_like( ), _RandomUniformLike.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12500,7 +12501,7 @@ def range( start=unwrap_vars(start), limit=unwrap_vars(limit), delta=unwrap_vars(delta), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -12542,7 +12543,7 @@ def reciprocal( _Reciprocal.Attributes(), _Reciprocal.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -12604,7 +12605,7 @@ def reduce_l1( ), _ReduceL1.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12666,7 +12667,7 @@ def reduce_l2( ), _ReduceL2.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12729,7 +12730,7 @@ def reduce_log_sum( ), _ReduceLogSum.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12792,7 +12793,7 @@ def reduce_log_sum_exp( ), _ReduceLogSumExp.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12856,7 +12857,7 @@ def reduce_max( ), _ReduceMax.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12918,7 +12919,7 @@ def reduce_mean( ), _ReduceMean.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -12981,7 +12982,7 @@ def reduce_min( ), _ReduceMin.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13043,7 +13044,7 @@ def reduce_prod( ), _ReduceProd.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13118,7 +13119,7 @@ def reduce_sum( _ReduceSum.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13180,7 +13181,7 @@ def reduce_sum_square( ), _ReduceSumSquare.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -13222,7 +13223,7 @@ def relu( _Relu.Attributes(), _Relu.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13292,7 +13293,7 @@ def reshape( _Reshape.Inputs( data=unwrap_vars(data), shape=unwrap_vars(shape), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reshaped @@ -13444,7 +13445,7 @@ def resize( roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13526,7 +13527,7 @@ def reverse_sequence( _ReverseSequence.Inputs( input=unwrap_vars(input), sequence_lens=unwrap_vars(sequence_lens), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13642,7 +13643,7 @@ def roi_align( X=unwrap_vars(X), rois=unwrap_vars(rois), batch_indices=unwrap_vars(batch_indices), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13696,7 +13697,7 @@ def round( _Round.Attributes(), _Round.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -13780,7 +13781,7 @@ def stft( frame_step=unwrap_vars(frame_step), window=unwrap_vars(window), frame_length=unwrap_vars(frame_length), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14034,7 +14035,7 @@ def scan( initial_state_and_scan_inputs ), ), - out_variadic=len(_body_subgraph.requested_results), # infer_types=False + out_variadic=len(_body_subgraph.requested_results), ) .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs @@ -14176,7 +14177,7 @@ def scatter_elements( data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14306,7 +14307,7 @@ def scatter_nd( data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14363,7 +14364,7 @@ def selu( ), _Selu.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -14418,7 +14419,7 @@ def sequence_at( _SequenceAt.Inputs( input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .tensor @@ -14460,7 +14461,7 @@ def sequence_construct( _SequenceConstruct.Attributes(), _SequenceConstruct.Inputs( inputs=unwrap_vars(inputs), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output_sequence @@ -14500,7 +14501,7 @@ def sequence_empty( _SequenceEmpty.Attributes( dtype=AttrDtype.maybe(dtype, name="dtype"), ), - _SequenceEmpty.Inputs(), # infer_types=False + _SequenceEmpty.Inputs(), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14555,7 +14556,7 @@ def sequence_erase( _SequenceErase.Inputs( input_sequence=unwrap_vars(input_sequence), position=unwrap_vars(position), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output_sequence @@ -14619,7 +14620,7 @@ def sequence_insert( input_sequence=unwrap_vars(input_sequence), tensor=unwrap_vars(tensor), position=unwrap_vars(position), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output_sequence @@ -14661,7 +14662,7 @@ def sequence_length( _SequenceLength.Attributes(), _SequenceLength.Inputs( input_sequence=unwrap_vars(input_sequence), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .length @@ -14741,7 +14742,7 @@ def sequence_map( input_sequence=unwrap_vars(input_sequence), additional_inputs=unwrap_vars(additional_inputs), ), - out_variadic=len(_body_subgraph.requested_results), # infer_types=False + out_variadic=len(_body_subgraph.requested_results), ) .get_output_vars(input_prop_values=input_prop_values) .out_sequence @@ -14835,7 +14836,7 @@ def shape( ), _Shape.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .shape @@ -14890,7 +14891,7 @@ def shrink( ), _Shrink.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -14932,7 +14933,7 @@ def sigmoid( _Sigmoid.Attributes(), _Sigmoid.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -14974,7 +14975,7 @@ def sign( _Sign.Attributes(), _Sign.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15014,7 +15015,7 @@ def sin( _Sin.Attributes(), _Sin.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15054,7 +15055,7 @@ def sinh( _Sinh.Attributes(), _Sinh.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15096,7 +15097,7 @@ def size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .size @@ -15232,7 +15233,7 @@ def slice( ends=unwrap_vars(ends), axes=unwrap_vars(axes), steps=unwrap_vars(steps), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15289,7 +15290,7 @@ def softmax( ), _Softmax.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15420,7 +15421,7 @@ def softmax_cross_entropy_loss( scores=unwrap_vars(scores), labels=unwrap_vars(labels), weights=unwrap_vars(weights), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -15462,7 +15463,7 @@ def softplus( _Softplus.Attributes(), _Softplus.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -15504,7 +15505,7 @@ def softsign( _Softsign.Attributes(), _Softsign.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15555,7 +15556,7 @@ def space_to_depth( ), _SpaceToDepth.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -15617,7 +15618,7 @@ def split( input=unwrap_vars(input), split=unwrap_vars(split), ), - out_variadic=outputs_count, # infer_types=False + out_variadic=outputs_count, ) .get_output_vars(input_prop_values=input_prop_values) .outputs @@ -15692,7 +15693,7 @@ def split_to_sequence( _SplitToSequence.Inputs( input=unwrap_vars(input), split=unwrap_vars(split), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output_sequence @@ -15734,7 +15735,7 @@ def sqrt( _Sqrt.Attributes(), _Sqrt.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -15786,7 +15787,7 @@ def squeeze( _Squeeze.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .squeezed @@ -15862,7 +15863,7 @@ def string_normalizer( ), _StringNormalizer.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -15916,7 +15917,7 @@ def sub( _Sub.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -15960,7 +15961,7 @@ def sum( _Sum.Attributes(), _Sum.Inputs( data_0=unwrap_vars(data_0), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .sum @@ -16000,7 +16001,7 @@ def tan( _Tan.Attributes(), _Tan.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16041,7 +16042,7 @@ def tanh( _Tanh.Attributes(), _Tanh.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16195,7 +16196,7 @@ def tf_idf_vectorizer( ), _TfIdfVectorizer.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -16244,7 +16245,7 @@ def thresholded_relu( ), _ThresholdedRelu.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -16295,7 +16296,7 @@ def tile( _Tile.Inputs( input=unwrap_vars(input), repeats=unwrap_vars(repeats), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16391,7 +16392,7 @@ def top_k( _TopK.Inputs( X=unwrap_vars(X), K=unwrap_vars(K), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -16441,7 +16442,7 @@ def transpose( ), _Transpose.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .transposed @@ -16513,7 +16514,7 @@ def trilu( _Trilu.Inputs( input=unwrap_vars(input), k=unwrap_vars(k), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16700,7 +16701,7 @@ def unique( ), _Unique.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() @@ -16762,7 +16763,7 @@ def unsqueeze( _Unsqueeze.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .expanded @@ -16822,7 +16823,7 @@ def where( condition=unwrap_vars(condition), X=unwrap_vars(X), Y=unwrap_vars(Y), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -16875,7 +16876,7 @@ def xor( _Xor.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index c02d6cca..7d7f7f30 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -4,7 +4,9 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import Optional +from typing import ( + Optional, +) import numpy as np import numpy.typing as npt @@ -18,7 +20,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._type_system import PropDict +from spox._value_prop import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v17 import ( _DFT, @@ -943,7 +945,7 @@ def bitwise_and( _BitwiseAnd.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -983,7 +985,7 @@ def bitwise_not( _BitwiseNot.Attributes(), _BitwiseNot.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1035,7 +1037,7 @@ def bitwise_or( _BitwiseOr.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -1087,7 +1089,7 @@ def bitwise_xor( _BitwiseXor.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -1153,7 +1155,7 @@ def center_crop_pad( _CenterCropPad.Inputs( input_data=unwrap_vars(input_data), shape=unwrap_vars(shape), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output_data @@ -1256,7 +1258,7 @@ def col2_im( input=unwrap_vars(input), image_shape=unwrap_vars(image_shape), block_shape=unwrap_vars(block_shape), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1343,7 +1345,7 @@ def group_normalization( X=unwrap_vars(X), scale=unwrap_vars(scale), bias=unwrap_vars(bias), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1474,7 +1476,7 @@ def lp_pool( ), _LpPool.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1521,7 +1523,7 @@ def mish( _Mish.Attributes(), _Mish.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1565,7 +1567,7 @@ def optional_get_element( _OptionalGetElement.Attributes(), _OptionalGetElement.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1609,7 +1611,7 @@ def optional_has_element( _OptionalHasElement.Attributes(), _OptionalHasElement.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1766,7 +1768,7 @@ def pad( pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1841,7 +1843,7 @@ def reduce_l1( _ReduceL1.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -1916,7 +1918,7 @@ def reduce_l2( _ReduceL2.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -1992,7 +1994,7 @@ def reduce_log_sum( _ReduceLogSum.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2068,7 +2070,7 @@ def reduce_log_sum_exp( _ReduceLogSumExp.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2145,7 +2147,7 @@ def reduce_max( _ReduceMax.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2220,7 +2222,7 @@ def reduce_mean( _ReduceMean.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2296,7 +2298,7 @@ def reduce_min( _ReduceMin.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2371,7 +2373,7 @@ def reduce_prod( _ReduceProd.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2446,7 +2448,7 @@ def reduce_sum_square( _ReduceSumSquare.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -2654,7 +2656,7 @@ def resize( roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -2799,7 +2801,7 @@ def scatter_elements( data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -2945,7 +2947,7 @@ def scatter_nd( data=unwrap_vars(data), indices=unwrap_vars(indices), updates=unwrap_vars(updates), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -3013,7 +3015,7 @@ def split( input=unwrap_vars(input), split=unwrap_vars(split), ), - out_variadic=num_outputs, # infer_types=False + out_variadic=num_outputs, ) .get_output_vars(input_prop_values=input_prop_values) .outputs diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 190c4d1f..87c51c39 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -4,7 +4,10 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import Callable, Optional +from typing import ( + Callable, + Optional, +) from typing import cast as typing_cast import numpy as np @@ -25,8 +28,8 @@ from spox._graph import Graph, subgraph from spox._node import OpType from spox._standard import StandardNode -from spox._type_system import PropDict, Tensor, Type -from spox._value_prop import PropValueType +from spox._type_system import Tensor, Type +from spox._value_prop import PropDict, PropValueType from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v18 import ( _DFT, @@ -453,7 +456,7 @@ class Attributes(BaseAttributes): class Outputs(BaseOutputs): output: VarInfo - def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values: PropDict) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -931,7 +934,7 @@ def average_pool( ), _AveragePool.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1070,7 +1073,7 @@ def cast( ), _Cast.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1132,7 +1135,7 @@ def cast_like( _CastLike.Inputs( input=unwrap_vars(input), target_type=unwrap_vars(target_type), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1206,7 +1209,7 @@ def constant( value_string=AttrString.maybe(value_string, name="value_string"), value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), - _Constant.Inputs(), # infer_types=False + _Constant.Inputs(), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1332,7 +1335,7 @@ def deform_conv( offset=unwrap_vars(offset), B=unwrap_vars(B), mask=unwrap_vars(mask), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1408,7 +1411,7 @@ def dequantize_linear( x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -1461,7 +1464,7 @@ def equal( _Equal.Inputs( A=unwrap_vars(A), B=unwrap_vars(B), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .C @@ -1501,7 +1504,7 @@ def identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1574,9 +1577,7 @@ def if_( _If.Inputs( cond=unwrap_vars(cond), ), - out_variadic=len( - _else_branch_subgraph.requested_results - ), # infer_types=False + out_variadic=len(_else_branch_subgraph.requested_results), ) .get_output_vars(input_prop_values=input_prop_values) .outputs @@ -1779,7 +1780,7 @@ def loop( cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), - out_variadic=len(_body_subgraph.requested_results) - 1, # infer_types=False + out_variadic=len(_body_subgraph.requested_results) - 1, ) .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs @@ -1962,7 +1963,7 @@ def pad( pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -2050,7 +2051,7 @@ def quantize_linear( x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -2120,7 +2121,7 @@ def reshape( _Reshape.Inputs( data=unwrap_vars(data), shape=unwrap_vars(shape), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reshaped @@ -2366,7 +2367,7 @@ def resize( roi=unwrap_vars(roi), scales=unwrap_vars(scales), sizes=unwrap_vars(sizes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -2620,7 +2621,7 @@ def scan( initial_state_and_scan_inputs ), ), - out_variadic=len(_body_subgraph.requested_results), # infer_types=False + out_variadic=len(_body_subgraph.requested_results), ) .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs @@ -2714,7 +2715,7 @@ def shape( ), _Shape.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .shape @@ -2756,7 +2757,7 @@ def size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .size diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index d7584d4b..31660ccd 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -3,7 +3,9 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from dataclasses import dataclass -from typing import Optional +from typing import ( + Optional, +) import numpy as np import numpy.typing as npt @@ -16,7 +18,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._type_system import PropDict +from spox._value_prop import PropDict from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v19 import ( _GRU, @@ -744,7 +746,7 @@ def affine_grid( _AffineGrid.Inputs( theta=unwrap_vars(theta), size=unwrap_vars(size), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .grid @@ -798,7 +800,7 @@ def constant_of_shape( ), _ConstantOfShape.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -910,7 +912,7 @@ def dft( input=unwrap_vars(input), dft_length=unwrap_vars(dft_length), axis=unwrap_vars(axis), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -965,7 +967,7 @@ def gelu( ), _Gelu.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1088,7 +1090,7 @@ def grid_sample( _GridSample.Inputs( X=unwrap_vars(X), grid=unwrap_vars(grid), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1163,7 +1165,7 @@ def image_decoder( ), _ImageDecoder.Inputs( encoded_stream=unwrap_vars(encoded_stream), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .image @@ -1220,7 +1222,7 @@ def isinf( ), _IsInf.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1261,7 +1263,7 @@ def isnan( _IsNaN.Attributes(), _IsNaN.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1341,7 +1343,7 @@ def reduce_max( _ReduceMax.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -1420,7 +1422,7 @@ def reduce_min( _ReduceMin.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reduced @@ -1473,7 +1475,7 @@ def regex_full_match( ), _RegexFullMatch.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1520,7 +1522,7 @@ def string_concat( _StringConcat.Inputs( X=unwrap_vars(X), Y=unwrap_vars(Y), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Z @@ -1607,7 +1609,7 @@ def string_split( ), _StringSplit.Inputs( X=unwrap_vars(X), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) ._unpack_to_any() diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 539ef4d0..0a89e2e1 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -4,7 +4,10 @@ # ruff: noqa: E741 -- Allow ambiguous variable name from collections.abc import Iterable, Sequence from dataclasses import dataclass -from typing import Callable, Optional +from typing import ( + Callable, + Optional, +) from typing import cast as typing_cast import numpy as np @@ -25,8 +28,8 @@ from spox._graph import Graph, subgraph from spox._node import OpType from spox._standard import StandardNode -from spox._type_system import PropDict, Tensor, Type -from spox._value_prop import PropValueType +from spox._type_system import Tensor, Type +from spox._value_prop import PropDict, PropValueType from spox._var import Var, VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v20 import ( _DFT, @@ -433,7 +436,7 @@ class Attributes(BaseAttributes): class Outputs(BaseOutputs): output: VarInfo - def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values: PropDict) -> dict[str, PropValueType]: ((key, raw),) = ( (k, v.value) for k, v in self.attrs.get_fields().items() if v is not None ) @@ -972,7 +975,7 @@ def cast( ), _Cast.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1034,7 +1037,7 @@ def cast_like( _CastLike.Inputs( input=unwrap_vars(input), target_type=unwrap_vars(target_type), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1108,7 +1111,7 @@ def constant( value_string=AttrString.maybe(value_string, name="value_string"), value_strings=AttrStrings.maybe(value_strings, name="value_strings"), ), - _Constant.Inputs(), # infer_types=False + _Constant.Inputs(), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1162,7 +1165,7 @@ def constant_of_shape( ), _ConstantOfShape.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1252,7 +1255,7 @@ def dequantize_linear( x=unwrap_vars(x), x_scale=unwrap_vars(x_scale), x_zero_point=unwrap_vars(x_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -1308,7 +1311,7 @@ def flatten( ), _Flatten.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1410,7 +1413,7 @@ def group_normalization( X=unwrap_vars(X), scale=unwrap_vars(scale), bias=unwrap_vars(bias), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .Y @@ -1450,7 +1453,7 @@ def identity( _Identity.Attributes(), _Identity.Inputs( input=unwrap_vars(input), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -1523,9 +1526,7 @@ def if_( _If.Inputs( cond=unwrap_vars(cond), ), - out_variadic=len( - _else_branch_subgraph.requested_results - ), # infer_types=False + out_variadic=len(_else_branch_subgraph.requested_results), ) .get_output_vars(input_prop_values=input_prop_values) .outputs @@ -1728,7 +1729,7 @@ def loop( cond=unwrap_vars(cond), v_initial=unwrap_vars(v_initial), ), - out_variadic=len(_body_subgraph.requested_results) - 1, # infer_types=False + out_variadic=len(_body_subgraph.requested_results) - 1, ) .get_output_vars(input_prop_values=input_prop_values) .v_final_and_scan_outputs @@ -1911,7 +1912,7 @@ def pad( pads=unwrap_vars(pads), constant_value=unwrap_vars(constant_value), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .output @@ -2013,7 +2014,7 @@ def qlinear_matmul( b_zero_point=unwrap_vars(b_zero_point), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -2142,7 +2143,7 @@ def quantize_linear( x=unwrap_vars(x), y_scale=unwrap_vars(y_scale), y_zero_point=unwrap_vars(y_zero_point), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .y @@ -2212,7 +2213,7 @@ def reshape( _Reshape.Inputs( data=unwrap_vars(data), shape=unwrap_vars(shape), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .reshaped @@ -2466,7 +2467,7 @@ def scan( initial_state_and_scan_inputs ), ), - out_variadic=len(_body_subgraph.requested_results), # infer_types=False + out_variadic=len(_body_subgraph.requested_results), ) .get_output_vars(input_prop_values=input_prop_values) .final_state_and_scan_outputs @@ -2560,7 +2561,7 @@ def shape( ), _Shape.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .shape @@ -2602,7 +2603,7 @@ def size( _Size.Attributes(), _Size.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .size @@ -2654,7 +2655,7 @@ def squeeze( _Squeeze.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .squeezed @@ -2705,7 +2706,7 @@ def transpose( ), _Transpose.Inputs( data=unwrap_vars(data), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .transposed @@ -2767,7 +2768,7 @@ def unsqueeze( _Unsqueeze.Inputs( data=unwrap_vars(data), axes=unwrap_vars(axes), - ), # infer_types=False + ), ) .get_output_vars(input_prop_values=input_prop_values) .expanded diff --git a/tools/generate_opset.py b/tools/generate_opset.py index 399a311f..7d1a9e95 100644 --- a/tools/generate_opset.py +++ b/tools/generate_opset.py @@ -647,7 +647,7 @@ def main( if pre_commit_hooks: print("Running pre-commit hooks to format & verify...") - if run_pre_commit_hooks(str(path)).returncode: + if False and run_pre_commit_hooks(str(path)).returncode: print("Running second pass of pre-commit hooks...") if run_pre_commit_hooks(str(path)).returncode: raise RuntimeError( diff --git a/tools/templates/class.jinja2 b/tools/templates/class.jinja2 index 7698fd43..4ab22209 100644 --- a/tools/templates/class.jinja2 +++ b/tools/templates/class.jinja2 @@ -47,14 +47,14 @@ class _{{ schema.name }}(StandardNode): {% endif %} {% if type_inference %} - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: {% filter indent(width=8) %} {%+ include type_inference %} {% endfilter %} {% endif %} {% if value_propagation %} - def propagate_values(self, input_prop_values) -> dict[str, PropValueType]: + def propagate_values(self, input_prop_values: PropDict) -> dict[str, PropValueType]: {% filter indent(width=8) %} {%+ include value_propagation %} {% endfilter %} diff --git a/tools/templates/preamble.jinja2 b/tools/templates/preamble.jinja2 index 95ee0e64..7824457f 100644 --- a/tools/templates/preamble.jinja2 +++ b/tools/templates/preamble.jinja2 @@ -7,7 +7,7 @@ from typing import ( Any, Callable, Optional, - Union,prea + Union, ) from typing import cast as typing_cast @@ -32,5 +32,5 @@ from spox._graph import Graph, subgraph from spox._internal_op import intro from spox._node import OpType from spox._standard import InferenceError, StandardNode -from spox._type_system import Tensor, Type, Sequence as SpoxSequence, PropDict -from spox._value_prop import PropValueType +from spox._type_system import Tensor, Type, Sequence as SpoxSequence +from spox._value_prop import PropValueType, PropDict diff --git a/tools/templates/type_inference/loop16-fix.jinja2 b/tools/templates/type_inference/loop16-fix.jinja2 index 712a7258..b797693c 100644 --- a/tools/templates/type_inference/loop16-fix.jinja2 +++ b/tools/templates/type_inference/loop16-fix.jinja2 @@ -1,4 +1,4 @@ -output_types = super().infer_output_types() +output_types = super().infer_output_types({}) body = self.attrs.body.value n = len(body.requested_arguments) - 2 From df0bee9c7495fc9aaf4b938c42249a536dbd6089 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Mon, 18 Nov 2024 23:18:30 +0200 Subject: [PATCH 18/29] Pre-commit enable --- tools/generate_opset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/generate_opset.py b/tools/generate_opset.py index 7d1a9e95..399a311f 100644 --- a/tools/generate_opset.py +++ b/tools/generate_opset.py @@ -647,7 +647,7 @@ def main( if pre_commit_hooks: print("Running pre-commit hooks to format & verify...") - if False and run_pre_commit_hooks(str(path)).returncode: + if run_pre_commit_hooks(str(path)).returncode: print("Running second pass of pre-commit hooks...") if run_pre_commit_hooks(str(path)).returncode: raise RuntimeError( From 02e36ac2725fd7189e4e2116fdd9afa3b62d5a70 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Mon, 18 Nov 2024 23:27:57 +0200 Subject: [PATCH 19/29] Update documentation --- src/spox/_var.py | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/spox/_var.py b/src/spox/_var.py index fcba2158..7e5b1753 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -24,28 +24,10 @@ def _not_impl(self, *_): class VarInfo: """ - Abstraction for a single ONNX value - like a tensor - that can be passed around in Python code. - - A ``VarInfo`` represents some output of an operator. - This operator is stored internally to allow reproducing the graph. - - The ``type`` field is inferred and checked by operators. - It may be ``None`` if type inference failed, in which case it is unknown and should pass all type checks. - However, untyped ``VarInfo`` objects may not be used in some contexts. - Keep in mind that the types themselves may have some information missing. - For instance, tensors allow missing rank and shape information. - - There is an implicit value propagation mechanism, powered by the ONNX reference implementation. - Values may be propagated if a ``VarInfo`` always has a known and constant value at runtime. - This is used for type & shape inference. For instance, Reshape to a constant shape can have the shape inferred. + Internal information about a ``Var``. Should be mainly inaccessible for most uses of ``spox``. ``VarInfo`` should be treated as strictly immutable. If a ``VarInfo`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid. - - Protected fields are to be treated as internal. - Useful data is also shown by the string representation, but it should be treated as debug information. - - Should not be constructed directly - the main source of ``VarInfo`` objects are operator constructors. """ type: Optional[_type_system.Type] @@ -131,9 +113,11 @@ class Var: """ Abstraction for a single ONNX value - like a tensor - that can be passed around in Python code. - A ``VarInfo`` represents some output of an operator. + A ``Var`` represents some output of an operator. This operator is stored internally to allow reproducing the graph. + The ``VarInfo`` class holds all relevant information about a ``Var`` - like the ``type``. + The ``type`` field is inferred and checked by operators. It may be ``None`` if type inference failed, in which case it is unknown and should pass all type checks. However, untyped ``VarInfo`` objects may not be used in some contexts. @@ -144,8 +128,8 @@ class Var: Values may be propagated if a ``VarInfo`` always has a known and constant value at runtime. This is used for type & shape inference. For instance, Reshape to a constant shape can have the shape inferred. - ``VarInfo`` should be treated as strictly immutable. - If a ``VarInfo`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid. + ``Var`` should be treated as strictly immutable. + If a ``Var`` or any of its fields are modified, the behaviour is undefined and the produced graph may be invalid. Protected fields are to be treated as internal. Useful data is also shown by the string representation, but it should be treated as debug information. From 9488f6a137277c4a5fed7fec3cacde0a046c80ab Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Tue, 19 Nov 2024 20:34:46 +0200 Subject: [PATCH 20/29] Fix adapt node --- src/spox/_adapt.py | 21 ++++++++++++++------- tests/test_adapt.py | 13 +++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/spox/_adapt.py b/src/spox/_adapt.py index 8c95b2dc..ff848170 100644 --- a/src/spox/_adapt.py +++ b/src/spox/_adapt.py @@ -9,10 +9,11 @@ from ._attributes import AttrGraph from ._inline import _Inline -from ._internal_op import _InternalNode +from ._internal_op import _Initializer, _InternalNode from ._node import Node from ._schemas import SCHEMAS from ._scope import Scope +from ._utils import from_array from ._var import VarInfo @@ -30,16 +31,21 @@ def adapt_node( # By using a dictionary we ensure that we only have a single # ValueInfo per (possibly repeated) input name. input_info = { - var_names[var]: var.unwrap_type()._to_onnx_value_info( - var_names[var], _traceback_name=f"adapt-input {key}" + var_names[var_info]: var_info.unwrap_type()._to_onnx_value_info( + var_names[var_info], _traceback_name=f"adapt-input {key}" ) - for key, var in node.inputs.get_var_infos().items() + for key, var_info in node.inputs.get_var_infos().items() } output_info = [ - var.unwrap_type()._to_onnx_value_info( - var_names[var], _traceback_name=f"adapt-output {key}" + var_info.unwrap_type()._to_onnx_value_info( + var_names[var_info], _traceback_name=f"adapt-output {key}" ) - for key, var in node.outputs.get_var_infos().items() + for key, var_info in node.outputs.get_var_infos().items() + ] + initializers = [ + from_array(var_info._op.attrs.get_fields()["value"].value, name) # type: ignore + for name, var_info in node.inputs.get_var_infos().items() + if isinstance(var_info._op, _Initializer) ] except ValueError: return None @@ -50,6 +56,7 @@ def adapt_node( "spox__singleton_adapter_graph", list(input_info.values()), output_info, + initializers, ), opset_imports=[onnx.helper.make_operatorsetid("", source_version)], ) diff --git a/tests/test_adapt.py b/tests/test_adapt.py index 25c47646..a90e0778 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -15,6 +15,7 @@ from spox import Tensor, Var, argument, build, inline from spox._attributes import AttrInt64s from spox._fields import BaseAttributes, BaseInputs, BaseOutputs +from spox._future import initializer from spox._graph import arguments, results from spox._node import OpType from spox._standard import StandardNode @@ -163,6 +164,18 @@ def test_adapt_node_with_repeating_input_names(): build({"a": a}, {"b": b, "c": c}) +def test_adapt_node_initializer(): + init_data = [1.0, 2.0, 3.0] + + a = argument(Tensor(np.float32, ("N",))) + b = initializer(init_data, np.float32) + c = op18.equal(a, b) + d = op19.identity(a) + + model = build({"a": a}, {"b": b, "c": c, "d": d}) + np.testing.assert_allclose(model.graph.initializer[0].float_data, init_data) + + def test_inline_model_custom_node_only(): """Inline a model which only consists of a custom node. From c23086ba1291698511fb3c6df62362bd3c5bc745 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 20 Nov 2024 01:11:45 +0200 Subject: [PATCH 21/29] Fix function inputs passing --- src/spox/_fields.py | 4 ++-- src/spox/_function.py | 16 ++++++++-------- tests/test_function.py | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/spox/_fields.py b/src/spox/_fields.py index cb92f413..6167f07e 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -167,14 +167,14 @@ def vars(self, prop_values: Optional[PropDict] = None) -> BaseVars: field_value = getattr(self, field.name) if field_type == VarFieldKind.SINGLE: - prop_value = cast(PropValue, prop_values[field.name]) + prop_value = cast(PropValue, prop_values.get(field.name, None)) vars_dict[field.name] = Var(field_value, prop_value) elif ( field_type == VarFieldKind.OPTIONAL and prop_values.get(field.name, None) is not None ): - prop_value = cast(PropValue, prop_values[field.name]) + prop_value = cast(PropValue, prop_values.get(field.name, None)) vars_dict[field.name] = Var(field_value, prop_value) elif field_type == VarFieldKind.VARIADIC: diff --git a/src/spox/_function.py b/src/spox/_function.py index f9bc35c9..65b052d4 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -10,11 +10,11 @@ import onnx from . import _attributes -from ._fields import BaseAttributes, BaseInputs, BaseOutputs +from ._fields import BaseAttributes, BaseInputs, BaseOutputs, BaseVars from ._internal_op import _InternalNode from ._node import Node, OpType from ._type_system import Type -from ._var import Var, VarInfo, unwrap_vars, wrap_vars +from ._var import Var, VarInfo, unwrap_vars if TYPE_CHECKING: from . import _graph @@ -48,7 +48,7 @@ class Function(_InternalNode): func_outputs: BaseOutputs func_graph: "_graph.Graph" - def constructor(self, attrs, inputs): + def constructor(self, attrs: dict[str, _attributes.Attr], inputs: BaseVars): """ Abstract method for functions. @@ -79,7 +79,9 @@ def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: self.func_attrs[name] = attr self.func_inputs = self.Inputs(**self.func_args) # type: ignore - self.func_outputs = self.constructor(self.func_attrs, self.func_inputs) + self.func_outputs = self.constructor( + self.func_attrs, self.func_inputs.vars(input_prop_values) + ) self.func_graph = _graph.results( **self.func_outputs._propagate_vars(input_prop_values).flatten_vars() ).with_arguments(*func_args_var.values()) @@ -146,10 +148,8 @@ class Attributes(BaseAttributes): Outputs = _FuncOutputs op_type = OpType(name, domain, version) - def constructor(self, attrs, inputs): - return self.Outputs( - *unwrap_vars(fun(*wrap_vars(inputs.get_fields().values()))) - ) + def constructor(self, attrs: dict[str, _attributes.Attr], inputs: BaseVars): + return self.Outputs(*unwrap_vars(fun(*inputs.flatten_vars().values()))) return _Func diff --git a/tests/test_function.py b/tests/test_function.py index 4728b9b4..5018714d 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -14,7 +14,7 @@ import spox.opset.ai.onnx.v17 as op from spox._attributes import Attr, AttrFloat32, _Ref -from spox._fields import BaseAttributes, BaseInputs, BaseOutputs +from spox._fields import BaseAttributes, BaseInputs, BaseOutputs, BaseVars from spox._function import Function, to_function from spox._graph import arguments, results from spox._node import OpType @@ -44,7 +44,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: + def constructor(self, attrs: dict[str, Attr], inputs: BaseVars) -> Outputs: # FIXME: At some point, attribute references should be properly type-hinted. a = op.constant( value_float=_Ref( @@ -56,7 +56,7 @@ def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: attrs["shift_outer"], outer_name="shift_outer", name="value_float" ) # type: ignore ) - x = Var(inputs.X) + x = inputs.X return self.Outputs(op.add(op.mul(a, x), b)._var_info) def linear_inner( @@ -99,10 +99,10 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: + def constructor(self, attrs: dict[str, Attr], inputs: BaseVars) -> Outputs: return self.Outputs( linear( - Var(inputs.X), + inputs.X, _Ref(attrs["slope1"], outer_name="slope1", name="slope_outer"), _Ref(attrs["shift1"], outer_name="shift1", name="shift_outer"), )._var_info @@ -150,8 +150,8 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def constructor(self, attrs: dict[str, Attr], inputs: Inputs) -> Outputs: - x = Var(inputs.X) + def constructor(self, attrs: dict[str, Attr], inputs: BaseVars) -> Outputs: + x = inputs["X"] a = op.mul( linear( x, From 1aebc1ad63037f705b04907f81605411edd16b37 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 20 Nov 2024 01:16:02 +0200 Subject: [PATCH 22/29] Fix opset generation --- src/spox/opset/ai/onnx/v17.py | 397 +++++++++++++++++----------------- src/spox/opset/ai/onnx/v19.py | 63 +++--- src/spox/opset/ai/onnx/v20.py | 30 +-- src/spox/opset/ai/onnx/v21.py | 92 ++++---- 4 files changed, 292 insertions(+), 290 deletions(-) diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index eb9132ae..a65241e0 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -4632,8 +4632,8 @@ def batch_normalization( (training_mode=True). There are multiple cases for the number of outputs, which we list below: - - Output case #1: Y, running_mean, running_var (training_mode=True) - - Output case #2: Y (training_mode=False) + - Output case #1: Y, running_mean, running_var (training_mode=True) + - Output case #2: Y (training_mode=False) When training_mode=False, extra outputs are invalid. The outputs are updated as follows when training_mode=True: @@ -4985,26 +4985,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules: - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Parameters ========== @@ -6587,9 +6587,9 @@ def dynamic_quantize_linear( y_scale = (maximum(0, max(x)) - minimum(0, min(x))) / (qmax - qmin) - - where qmax and qmin are max and min values for quantization range - i.e. [0, 255] in case of uint8 - - data range is adjusted to include 0. + - where qmax and qmin are max and min values for quantization range i.e. + [0, 255] in case of uint8 + - data range is adjusted to include 0. Zero point is calculated as: @@ -6598,11 +6598,11 @@ def dynamic_quantize_linear( intermediate_zero_point = qmin - min(x)/y_scale y_zero_point = cast(round(saturate(itermediate_zero_point))) - - where qmax and qmin are max and min values for quantization range - .i.e [0, 255] in case of uint8 - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, - 127] if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. + - where qmax and qmin are max and min values for quantization range .i.e + [0, 255] in case of uint8 + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] + if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. Data quantization formula is: @@ -6610,9 +6610,9 @@ def dynamic_quantize_linear( y = saturate (round (x / y_scale) + y_zero_point) - - for saturation, it saturates to [0, 255] if it's uint8, or [-127, - 127] if it's int8. Right now only uint8 is supported. - - rounding to nearest ties to even. + - for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] + if it's int8. Right now only uint8 is supported. + - rounding to nearest ties to even. Parameters ========== @@ -7163,60 +7163,60 @@ def gru( Notations: - - ``X`` - input tensor - - ``z`` - update gate - - ``r`` - reset gate - - ``h`` - hidden gate - - ``t`` - time step (t-1 means previous time step) - - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden - gates - - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden - gates - - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates - - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates - - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, - and hidden gates - - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, - and hidden gates - - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden - gates - - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden - gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``z`` - update gate + - ``r`` - reset gate + - ``h`` - hidden gate + - ``t`` - time step (t-1 means previous time step) + - ``W[zrh]`` - W parameter weight matrix for update, reset, and hidden + gates + - ``R[zrh]`` - R recurrence weight matrix for update, reset, and hidden + gates + - ``Wb[zrh]`` - W bias vectors for update, reset, and hidden gates + - ``Rb[zrh]`` - R bias vectors for update, reset, and hidden gates + - ``WB[zrh]`` - W parameter weight matrix for backward update, reset, + and hidden gates + - ``RB[zrh]`` - R recurrence weight matrix for backward update, reset, + and hidden gates + - ``WBb[zrh]`` - W bias vectors for backward update, reset, and hidden + gates + - ``RBb[zrh]`` - R bias vectors for backward update, reset, and hidden + gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha \* x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha \* Tanh(beta \* x) - - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha \* x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha \* Tanh(beta \* x) + - HardSigmoid(x) - min(max(alpha \* x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha \* (e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Sigmoid, g=Tanh): - - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) - - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) - - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when - linear_before_reset = 0 - - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when - linear_before_reset != 0 - - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** - inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) + - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when + linear_before_reset = 0 + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when + linear_before_reset != 0 + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 This operator has **optional** + inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -7742,8 +7742,8 @@ def gemm( General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 - - A' = transpose(A) if transA else A - - B' = transpose(B) if transB else B + - A' = transpose(A) if transA else A + - B' = transpose(B) if transB else B Compute Y = alpha \* A' \* B' + beta \* C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input @@ -7911,7 +7911,7 @@ def global_lp_pool( Signature: ``ai.onnx@2::GlobalLpPool``. Type constraints: - - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` + - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ input_prop_values: PropDict = { "X": get_value(X), @@ -8841,65 +8841,65 @@ def lstm( Notations: - - ``X`` - input tensor - - ``i`` - input gate - - ``o`` - output gate - - ``f`` - forget gate - - ``c`` - cell gate - - ``t`` - time step (t-1 means previous time step) - - ``W[iofc]`` - W parameter weight matrix for input, output, forget, - and cell gates - - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, - and cell gates - - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell - gates - - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell - gates - - ``P[iof]`` - P peephole weight vector for input, output, and forget - gates - - ``WB[iofc]`` - W parameter weight matrix for backward input, output, - forget, and cell gates - - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, - forget, and cell gates - - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, - and cell gates - - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, - and cell gates - - ``PB[iof]`` - P peephole weight vector for backward input, output, - and forget gates - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``i`` - input gate + - ``o`` - output gate + - ``f`` - forget gate + - ``c`` - cell gate + - ``t`` - time step (t-1 means previous time step) + - ``W[iofc]`` - W parameter weight matrix for input, output, forget, and + cell gates + - ``R[iofc]`` - R recurrence weight matrix for input, output, forget, + and cell gates + - ``Wb[iofc]`` - W bias vectors for input, output, forget, and cell + gates + - ``Rb[iofc]`` - R bias vectors for input, output, forget, and cell + gates + - ``P[iof]`` - P peephole weight vector for input, output, and forget + gates + - ``WB[iofc]`` - W parameter weight matrix for backward input, output, + forget, and cell gates + - ``RB[iofc]`` - R recurrence weight matrix for backward input, output, + forget, and cell gates + - ``WBb[iofc]`` - W bias vectors for backward input, output, forget, and + cell gates + - ``RBb[iofc]`` - R bias vectors for backward input, output, forget, and + cell gates + - ``PB[iof]`` - P peephole weight vector for backward input, output, and + forget gates + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): - - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) - - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) - - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) - - Ct = ft (.) Ct-1 + it (.) ct - - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) - - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See - `the doc `__ for - more details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + - Ct = ft (.) Ct-1 + it (.) ct + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + - Ht = ot (.) h(Ct) This operator has **optional** inputs/outputs. See + `the doc `__ for + more details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -9434,21 +9434,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond = + ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond = + true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -9761,8 +9761,8 @@ def matmul( B: Var, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + Matrix product that behaves like + `numpy.matmul `__. Parameters ========== @@ -9810,8 +9810,8 @@ def matmul_integer( b_zero_point: Optional[Var] = None, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + Matrix product that behaves like + `numpy.matmul `__. The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. @@ -9953,8 +9953,7 @@ def max_pool( output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. Sliding windows that would start in the right padded region are - ignored. + ``i``. ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: @@ -11790,8 +11789,8 @@ def qlinear_matmul( y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + Matrix product that behaves like + `numpy.matmul `__. It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). For @@ -11977,46 +11976,46 @@ def rnn( Notations: - - ``X`` - input tensor - - ``i`` - input gate - - ``t`` - time step (t-1 means previous time step) - - ``Wi`` - W parameter weight matrix for input gate - - ``Ri`` - R recurrence weight matrix for input gate - - ``Wbi`` - W parameter bias vector for input gate - - ``Rbi`` - R parameter bias vector for input gate - - ``WBi`` - W parameter weight matrix for backward input gate - - ``RBi`` - R recurrence weight matrix for backward input gate - - ``WBbi`` - WR bias vectors for backward input gate - - ``RBbi`` - RR bias vectors for backward input gate - - ``H`` - Hidden state - - ``num_directions`` - 2 if direction == bidirectional else 1 + - ``X`` - input tensor + - ``i`` - input gate + - ``t`` - time step (t-1 means previous time step) + - ``Wi`` - W parameter weight matrix for input gate + - ``Ri`` - R recurrence weight matrix for input gate + - ``Wbi`` - W parameter bias vector for input gate + - ``Rbi`` - R parameter bias vector for input gate + - ``WBi`` - W parameter weight matrix for backward input gate + - ``RBi`` - R recurrence weight matrix for backward input gate + - ``WBbi`` - WR bias vectors for backward input gate + - ``RBbi`` - RR bias vectors for backward input gate + - ``H`` - Hidden state + - ``num_directions`` - 2 if direction == bidirectional else 1 Activation functions: - - Relu(x) - max(0, x) - - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) - - Sigmoid(x) - 1/(1 + e^{-x}) + - Relu(x) - max(0, x) + - Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + - Sigmoid(x) - 1/(1 + e^{-x}) NOTE: Below are optional - - Affine(x) - alpha*x + beta - - LeakyRelu(x) - x if x >= 0 else alpha \* x - - ThresholdedRelu(x) - x if x >= alpha else 0 - - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) - - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) - - Elu(x) - x if x >= 0 else alpha*(e^x - 1) - - Softsign(x) - x/(1 + \|x\|) - - Softplus(x) - log(1 + e^x) + - Affine(x) - alpha*x + beta + - LeakyRelu(x) - x if x >= 0 else alpha \* x + - ThresholdedRelu(x) - x if x >= alpha else 0 + - ScaledTanh(x) - alpha\ *Tanh(beta*\ x) + - HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + - Elu(x) - x if x >= 0 else alpha*(e^x - 1) + - Softsign(x) - x/(1 + \|x\|) + - Softplus(x) - log(1 + e^x) Equations (Default: f=Tanh): - - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has - **optional** inputs/outputs. See `the - doc `__ for more - details about the representation of optional arguments. An empty - string may be used in the place of an actual argument's name to - indicate a missing argument. Trailing optional arguments (those not - followed by an argument that is present) may also be simply omitted. + - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) This operator has + **optional** inputs/outputs. See `the + doc `__ for more + details about the representation of optional arguments. An empty + string may be used in the place of an actual argument's name to + indicate a missing argument. Trailing optional arguments (those not + followed by an argument that is present) may also be simply omitted. Parameters ========== @@ -15315,10 +15314,10 @@ def softmax_cross_entropy_loss( L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. After L is available, this operator can optionally do a reduction operator. - - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, - D2,..., Dk), with K >= 1 in case of K-dimensional loss. - - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, - D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(scores): (N, C) where C is the number of classes, or (N, C, D1, + D2,..., Dk), with K >= 1 in case of K-dimensional loss. + - shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, + D1, D2,..., Dk), with K >= 1 in case of K-dimensional loss. The loss for one sample, l_i, can calculated as follows: @@ -15348,13 +15347,13 @@ def softmax_cross_entropy_loss( Finally, L is optionally reduced: - - If reduction = 'none', the output is L with shape (N, D1, D2, ..., - Dk). - - If reduction = 'sum', the output is scalar: Sum(L). - - If reduction = 'mean', the output is scalar: ReduceMean(L), or if - weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W - is of shape ``(N, D1, D2, ..., Dk)`` and - ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. + - If reduction = 'none', the output is L with shape (N, D1, D2, ..., + Dk). + - If reduction = 'sum', the output is scalar: Sum(L). + - If reduction = 'mean', the output is scalar: ReduceMean(L), or if + weight is provided: ``ReduceSum(L) / ReduceSum(W)``, where tensor W is + of shape ``(N, D1, D2, ..., Dk)`` and + ``W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]``. Parameters ========== @@ -16316,22 +16315,22 @@ def top_k( Given an input tensor of shape [a_0, a_1, ..., a\_{n-1}] and integer argument k, return two outputs: - - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a\_{n-1}] which contains the values of the top k elements along - the specified axis + - Value tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] which contains the values of the top k elements along the + specified axis - - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, - ... a\_{n-1}] which contains the indices of the top k elements - (original indices from the input tensor). + - Index tensor of shape [a_0, a_1, ..., a\_{axis-1}, k, a\_{axis+1}, ... + a\_{n-1}] which contains the indices of the top k elements (original + indices from the input tensor). - - If "largest" is 1 (the default value) then the k largest elements are - returned. + - If "largest" is 1 (the default value) then the k largest elements are + returned. - - If "sorted" is 1 (the default value) then the resulting k elements - will be sorted. + - If "sorted" is 1 (the default value) then the resulting k elements + will be sorted. - - If "sorted" is 0, order of returned 'Values' and 'Indices' are - undefined. + - If "sorted" is 0, order of returned 'Values' and 'Indices' are + undefined. Given two equivalent values, this operator uses the indices along the axis as a tiebreaker. That is, the element with the lower index will diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index 87c51c39..acd9c494 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -821,8 +821,7 @@ def average_pool( output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1) if ceil_mode is enabled. ``pad_shape[i]`` is the sum of pads along axis - ``i``. Sliding windows that would start in the right padded region are - ignored. + ``i``. ``auto_pad`` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled: @@ -978,26 +977,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules if the destination type is not a float 8 type. - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Float 8 type were introduced to speed up the training of deep models. By default the conversion of a float *x* obeys to the following rules. @@ -1379,9 +1378,11 @@ def dequantize_linear( axis Attribute. (Optional) The axis of the dequantizing dimension of the input tensor. - Ignored for per-tensor quantization. Negative value means counting - dimensions from the back. Accepted range is [-r, r-1] where r = - rank(input). + Used only for per-axis quantization. Negative value means counting + dimensions from the back. Accepted range is ``[-r, r-1]`` where + ``r = rank(input)``. When the rank of the input is 1, per-tensor + quantization is applied, rendering the axis unnecessary in this + scenario. Returns ======= @@ -1609,21 +1610,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond = + ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond = + true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 31660ccd..ac389811 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -1107,21 +1107,21 @@ def image_decoder( reason (e.g. corrupted encoded stream, invalid format, it will return an empty matrix). The following image formats are supported: - - BMP - - JPEG (note: Lossless JPEG support is optional) - - JPEG2000 - - TIFF - - PNG - - WebP - - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow - a channel-last layout: (Height, Width, Channels). **JPEG chroma - upsampling method:** When upsampling the chroma components by a - factor of 2, the pixels are linearly interpolated so that the centers - of the output pixels are 1/4 and 3/4 of the way between input pixel - centers. When rounding, 0.5 is rounded down and up at alternative - pixels locations to prevent bias towards larger values (ordered - dither pattern). Considering adjacent input pixels A, B, and C, B is - upsampled to pixels B0 and B1 so that + - BMP + - JPEG (note: Lossless JPEG support is optional) + - JPEG2000 + - TIFF + - PNG + - WebP + - Portable image format (PBM, PGM, PPM, PXM, PNM) Decoded images follow + a channel-last layout: (Height, Width, Channels). **JPEG chroma + upsampling method:** When upsampling the chroma components by a factor + of 2, the pixels are linearly interpolated so that the centers of the + output pixels are 1/4 and 3/4 of the way between input pixel centers. + When rounding, 0.5 is rounded down and up at alternative pixels + locations to prevent bias towards larger values (ordered dither + pattern). Considering adjacent input pixels A, B, and C, B is + upsampled to pixels B0 and B1 so that :: diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 0a89e2e1..66279ce6 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -880,26 +880,26 @@ def cast( In more detail, the conversion among numerical types should follow these rules if the destination type is not a float 8 type. - - Casting from floating point to: + - Casting from floating point to: - - floating point: +/- infinity if OOR (out of range). - - fixed point: undefined if OOR. - - bool: +/- 0.0 to False; all else to True. + - floating point: +/- infinity if OOR (out of range). + - fixed point: undefined if OOR. + - bool: +/- 0.0 to False; all else to True. - - Casting from fixed point to: + - Casting from fixed point to: - - floating point: +/- infinity if OOR. (+ infinity in the case of - uint) - - fixed point: when OOR, discard higher bits and reinterpret (with - respect to two's complement representation for signed types). For - example, 200 (int16) -> -56 (int8). - - bool: zero to False; nonzero to True. + - floating point: +/- infinity if OOR. (+ infinity in the case of + uint) + - fixed point: when OOR, discard higher bits and reinterpret (with + respect to two's complement representation for signed types). For + example, 200 (int16) -> -56 (int8). + - bool: zero to False; nonzero to True. - - Casting from bool to: + - Casting from bool to: - - floating point: ``{1.0, 0.0}``. - - fixed point: ``{1, 0}``. - - bool: no change. + - floating point: ``{1.0, 0.0}``. + - fixed point: ``{1, 0}``. + - bool: no change. Float 8 type were introduced to speed up the training of deep models. By default the conversion of a float *x* obeys to the following rules. @@ -1558,21 +1558,21 @@ def loop( Operator inputs defined as (max_trip_count, condition_var). - - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value - is ignored, but is required in the body } + - input ("", ""): for (int i=0; ; ++i) { cond = ... // Note this value + is ignored, but is required in the body } - - input ("", cond) // Note this is analogous to a while loop bool cond - = ...; for (int i=0; cond; ++i) { cond = ...; } + - input ("", cond) // Note this is analogous to a while loop bool cond = + ...; for (int i=0; cond; ++i) { cond = ...; } - - input ("", 1) // Note this is analogous to a do-while loop bool cond - = true for (int i=0; cond; ++i) { cond = ...; } + - input ("", 1) // Note this is analogous to a do-while loop bool cond = + true for (int i=0; cond; ++i) { cond = ...; } - - input (trip_count, "") // Note this is analogous to a for loop int - trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // - ignored } + - input (trip_count, "") // Note this is analogous to a for loop int + trip_count = ... for (int i=0; i < trip_count; ++i) { cond = ...; // + ignored } - - input (trip_count, cond) int trip_count = ...; bool cond = ...; for - (int i=0; i < trip_count && cond; ++i) { cond = ...; } + - input (trip_count, cond) int trip_count = ...; bool cond = ...; for + (int i=0; i < trip_count && cond; ++i) { cond = ...; } *Sample usage - cond as well as trip count* @@ -1930,8 +1930,8 @@ def qlinear_matmul( y_zero_point: Var, ) -> Var: r""" - Matrix product that behaves like numpy.matmul: - https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + Matrix product that behaves like + `numpy.matmul `__. It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). For @@ -2040,12 +2040,12 @@ def quantize_linear( Saturation is done according to: - - uint16: [0, 65535] - - int16: [-32768, 32767] - - uint8: [0, 255] - - int8: [-128, 127] - - uint4: [0, 15] - - int4: [-8, 7] + - uint16: [0, 65535] + - int16: [-32768, 32767] + - uint8: [0, 255] + - int8: [-128, 127] + - uint4: [0, 15] + - int4: [-8, 7] For ``(x / y_scale)``, it rounds to the nearest even. Refer to https://en.wikipedia.org/wiki/Rounding for details. @@ -2059,15 +2059,15 @@ def quantize_linear( shape of ``y_scale``. In all cases, ``y_zero_point`` must have the same shape as ``y_scale``. - - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. - - Per-axis quantization: The scale must be a 1-D tensor, with the - length of the quantization axis. For an input shape - ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D - tensor of length ``Di``. - - Blocked quantization: The scale's shape is identical to the input's - shape, except for one dimension, in which blocking is performed. - Given ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block - size ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. + - Per-tensor (per-layer) quantization: ``y_scale`` is a scalar. + - Per-axis quantization: The scale must be a 1-D tensor, with the length + of the quantization axis. For an input shape + ``(D0, ..., Di, ..., Dn)`` and ``axis=i``, ``y_scale`` is a 1-D tensor + of length ``Di``. + - Blocked quantization: The scale's shape is identical to the input's + shape, except for one dimension, in which blocking is performed. Given + ``x`` shape ``(D0, ..., Di, ..., Dn)``, ``axis=i``, and block size + ``B``: ``y_scale`` shape is ``(D0, ..., ceil(Di/B), ..., Dn)``. Parameters ========== @@ -2087,9 +2087,11 @@ def quantize_linear( axis Attribute. (Optional) The axis of the dequantizing dimension of the input tensor. - Used for per-axis and blocked quantization. Negative value means + Used only for per-axis and blocked quantization. Negative value means counting dimensions from the back. Accepted range is ``[-r, r-1]`` where - ``r = rank(input)``. + ``r = rank(input)``. When the rank of the input is 1, per-tensor + quantization is applied, rendering the axis unnecessary in this + scenario. block_size Attribute. (Optional) The size of the quantization block (number of times every From 67d5b3bfba683f64c3b83f28c5f71ec28fe80750 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 20 Nov 2024 15:56:38 +0200 Subject: [PATCH 23/29] Hint that _VarInfo is private --- src/spox/_adapt.py | 8 +- src/spox/_build.py | 20 +- src/spox/_debug.py | 4 +- src/spox/_fields.py | 26 +- src/spox/_function.py | 10 +- src/spox/_graph.py | 6 +- src/spox/_inline.py | 6 +- src/spox/_internal_op.py | 10 +- src/spox/_node.py | 14 +- src/spox/_scope.py | 8 +- src/spox/_var.py | 32 +- src/spox/opset/ai/onnx/ml/v3.py | 82 +-- src/spox/opset/ai/onnx/ml/v4.py | 6 +- src/spox/opset/ai/onnx/ml/v5.py | 6 +- src/spox/opset/ai/onnx/v17.py | 1016 +++++++++++++++---------------- src/spox/opset/ai/onnx/v18.py | 158 ++--- src/spox/opset/ai/onnx/v19.py | 106 ++-- src/spox/opset/ai/onnx/v20.py | 70 +-- src/spox/opset/ai/onnx/v21.py | 124 ++-- tests/test_adapt.py | 6 +- tests/test_custom_operator.py | 6 +- tests/test_function.py | 14 +- tests/test_value_propagation.py | 4 +- 23 files changed, 871 insertions(+), 871 deletions(-) diff --git a/src/spox/_adapt.py b/src/spox/_adapt.py index ff848170..b6208ae8 100644 --- a/src/spox/_adapt.py +++ b/src/spox/_adapt.py @@ -14,7 +14,7 @@ from ._schemas import SCHEMAS from ._scope import Scope from ._utils import from_array -from ._var import VarInfo +from ._var import _VarInfo def adapt_node( @@ -22,7 +22,7 @@ def adapt_node( proto: onnx.NodeProto, source_version: int, target_version: int, - var_names: dict[VarInfo, str], + var_names: dict[_VarInfo, str], ) -> Optional[list[onnx.NodeProto]]: if source_version == target_version: return None @@ -70,7 +70,7 @@ def adapt_inline( node: _Inline, protos: list[onnx.NodeProto], target_opsets: dict[str, int], - var_names: dict[VarInfo, str], + var_names: dict[_VarInfo, str], node_name: str, ) -> list[onnx.NodeProto]: source_version = max({v for d, v in node.opset_req if d in ("", "ai.onnx")}) @@ -98,7 +98,7 @@ def adapt_best_effort( node: Node, protos: list[onnx.NodeProto], opsets: dict[str, int], - var_names: dict[VarInfo, str], + var_names: dict[_VarInfo, str], node_names: dict[Node, str], ) -> Optional[list[onnx.NodeProto]]: if isinstance(node, _Inline): diff --git a/src/spox/_build.py b/src/spox/_build.py index 84f93e8e..63556185 100644 --- a/src/spox/_build.py +++ b/src/spox/_build.py @@ -21,7 +21,7 @@ from ._node import Node from ._scope import Scope from ._traverse import iterative_dfs -from ._var import Var, VarInfo, unwrap_vars +from ._var import Var, _VarInfo, unwrap_vars if TYPE_CHECKING: from ._graph import Graph @@ -58,11 +58,11 @@ class BuildResult: scope: Scope nodes: dict[Node, tuple[onnx.NodeProto, ...]] - arguments: tuple[VarInfo, ...] - results: tuple[VarInfo, ...] + arguments: tuple[_VarInfo, ...] + results: tuple[_VarInfo, ...] opset_req: set[tuple[str, int]] functions: tuple["_function.Function", ...] - initializers: dict[VarInfo, np.ndarray] + initializers: dict[_VarInfo, np.ndarray] class Builder: @@ -164,12 +164,12 @@ def lca(self, a: "Graph", b: "Graph") -> "Graph": graphs: set["Graph"] graph_topo: list["Graph"] # Arguments, results - arguments_of: dict["Graph", list[VarInfo]] - results_of: dict["Graph", list[VarInfo]] + arguments_of: dict["Graph", list[_VarInfo]] + results_of: dict["Graph", list[_VarInfo]] source_of: dict["Graph", Node] # Arguments found by traversal - all_arguments_in: dict["Graph", set[VarInfo]] - claimed_arguments_in: dict["Graph", set[VarInfo]] + all_arguments_in: dict["Graph", set[_VarInfo]] + claimed_arguments_in: dict["Graph", set[_VarInfo]] # Scopes scope_tree: ScopeTree scope_own: dict["Graph", list[Node]] @@ -218,7 +218,7 @@ def get_intro_results( var._rename(key) return vars - def discover(self, graph: "Graph") -> tuple[set[VarInfo], set[VarInfo]]: + def discover(self, graph: "Graph") -> tuple[set[_VarInfo], set[_VarInfo]]: """ Run the discovery step of the build process. Resolves arguments and results for the involved graphs. Finds the topological ordering between (sub)graphs and sets their owners (nodes of which they are attributes). @@ -432,7 +432,7 @@ def compile_graph( # A bunch of model metadata we're collecting opset_req: set[tuple[str, int]] = set() functions: list[_function.Function] = [] - initializers: dict[VarInfo, np.ndarray] = {} + initializers: dict[_VarInfo, np.ndarray] = {} # Add arguments to our scope for arg in self.arguments_of[graph]: diff --git a/src/spox/_debug.py b/src/spox/_debug.py index 1942bfb9..a9b7c0aa 100644 --- a/src/spox/_debug.py +++ b/src/spox/_debug.py @@ -4,7 +4,7 @@ import sys from contextlib import contextmanager -from spox._var import VarInfo +from spox._var import _VarInfo # If `STORE_TRACEBACK` is `True` any node created will store a traceback for its point of creation. STORE_TRACEBACK = False @@ -36,7 +36,7 @@ def show_construction_tracebacks(debug_index): if -1 in found: del found[-1] for name, obj in reversed(found.values()): - if isinstance(obj, VarInfo): + if isinstance(obj, _VarInfo): if not obj: continue node = obj._op diff --git a/src/spox/_fields.py b/src/spox/_fields.py index 6167f07e..f2912955 100644 --- a/src/spox/_fields.py +++ b/src/spox/_fields.py @@ -11,7 +11,7 @@ from ._attributes import Attr from ._exceptions import InferenceWarning from ._value_prop import PropDict, PropValue -from ._var import Var, VarInfo +from ._var import Var, _VarInfo @dataclass @@ -87,10 +87,10 @@ def __post_init__(self): value = getattr(self, field.name) field_type = self._get_field_type(field) if field_type == VarFieldKind.SINGLE: - if not isinstance(value, VarInfo): + if not isinstance(value, _VarInfo): raise TypeError(f"Field expected VarInfo, got: {type(value)}.") elif field_type == VarFieldKind.OPTIONAL: - if value is not None and not isinstance(value, VarInfo): + if value is not None and not isinstance(value, _VarInfo): raise TypeError( f"Optional must be VarInfo or None, got: {type(value)}." ) @@ -101,7 +101,7 @@ def __post_init__(self): ) # Cast to tuple to avoid accidental mutation setattr(self, field.name, tuple(value)) - if bad := {type(var) for var in value} - {VarInfo}: + if bad := {type(var) for var in value} - {_VarInfo}: raise TypeError( f"Variadic field must only consist of VarInfos, got: {bad}." ) @@ -109,23 +109,23 @@ def __post_init__(self): @classmethod def _get_field_type(cls, field) -> VarFieldKind: """Access the kind of the field (single, optional, variadic) based on its type annotation.""" - if field.type == VarInfo: + if field.type == _VarInfo: return VarFieldKind.SINGLE - elif field.type == Optional[VarInfo]: + elif field.type == Optional[_VarInfo]: return VarFieldKind.OPTIONAL - elif field.type == Sequence[VarInfo]: + elif field.type == Sequence[_VarInfo]: return VarFieldKind.VARIADIC raise ValueError(f"Bad field type: '{field.type}'.") - def _flatten(self) -> Iterable[tuple[str, Optional[VarInfo]]]: + def _flatten(self) -> Iterable[tuple[str, Optional[_VarInfo]]]: """Iterate over the pairs of names and values of fields in this object.""" for key, value in self.__dict__.items(): - if value is None or isinstance(value, VarInfo): + if value is None or isinstance(value, _VarInfo): yield key, value else: yield from ((f"{key}_{i}", v) for i, v in enumerate(value)) - def __iter__(self) -> Iterator[Optional[VarInfo]]: + def __iter__(self) -> Iterator[Optional[_VarInfo]]: """Iterate over the values of fields in this object.""" yield from (v for _, v in self._flatten()) @@ -133,11 +133,11 @@ def __len__(self) -> int: """Count the number of fields in this object (should be same as declared in the class).""" return sum(1 for _ in self) - def get_var_infos(self) -> dict[str, VarInfo]: + def get_var_infos(self) -> dict[str, _VarInfo]: """Return a flat mapping by name of all the VarInfos in this object.""" return {key: var for key, var in self._flatten() if var is not None} - def get_fields(self) -> dict[str, Union[None, VarInfo, Sequence[VarInfo]]]: + def get_fields(self) -> dict[str, Union[None, _VarInfo, Sequence[_VarInfo]]]: """Return a mapping of all fields stored in this object by name.""" return self.__dict__.copy() @@ -218,7 +218,7 @@ def _create_var(key, var_info): ret_dict = {} for key, var_info in self.__dict__.items(): - if var_info is None or isinstance(var_info, VarInfo): + if var_info is None or isinstance(var_info, _VarInfo): ret_dict[key] = _create_var(key, var_info) else: ret_dict[key] = [ diff --git a/src/spox/_function.py b/src/spox/_function.py index 65b052d4..c4308d9f 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -14,14 +14,14 @@ from ._internal_op import _InternalNode from ._node import Node, OpType from ._type_system import Type -from ._var import Var, VarInfo, unwrap_vars +from ._var import Var, _VarInfo, unwrap_vars if TYPE_CHECKING: from . import _graph DEFAULT_FUNCTION_DOMAIN = "spox.default" -ConstructorT = TypeVar("ConstructorT", bound=Callable[..., Iterable[VarInfo]]) +ConstructorT = TypeVar("ConstructorT", bound=Callable[..., Iterable[_VarInfo]]) class Function(_InternalNode): @@ -42,7 +42,7 @@ class Function(_InternalNode): via the ``to_onnx_function`` method. """ - func_args: dict[str, VarInfo] + func_args: dict[str, _VarInfo] func_attrs: dict[str, _attributes.Attr] func_inputs: BaseInputs func_outputs: BaseOutputs @@ -130,12 +130,12 @@ def to_onnx_function( def _make_function_cls(fun, num_inputs, num_outputs, domain, version, name): _FuncInputs = make_dataclass( "_FuncInputs", - ((f"in{i}", VarInfo) for i in range(num_inputs)), + ((f"in{i}", _VarInfo) for i in range(num_inputs)), bases=(BaseInputs,), ) _FuncOutputs = make_dataclass( "_FuncOutputs", - ((f"out{i}", VarInfo) for i in range(num_outputs)), + ((f"out{i}", _VarInfo) for i in range(num_outputs)), bases=(BaseOutputs,), ) diff --git a/src/spox/_graph.py b/src/spox/_graph.py index 0470b289..a61dca7a 100644 --- a/src/spox/_graph.py +++ b/src/spox/_graph.py @@ -22,7 +22,7 @@ from ._schemas import max_opset_policy from ._type_system import Tensor, Type from ._utils import from_array -from ._var import Var, VarInfo +from ._var import Var, _VarInfo def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var]: @@ -222,7 +222,7 @@ def requested_results(self) -> dict[str, Var]: """Results (named) requested by this Graph (for building).""" return self._results - def get_arguments(self) -> dict[str, VarInfo]: + def get_arguments(self) -> dict[str, _VarInfo]: """ Get the effective named arguments (after build) of this Graph. @@ -233,7 +233,7 @@ def get_arguments(self) -> dict[str, VarInfo]: for var in self._get_build_result().arguments } - def get_results(self) -> dict[str, VarInfo]: + def get_results(self) -> dict[str, _VarInfo]: """ Get the effective named results (after build) of this Graph. diff --git a/src/spox/_inline.py b/src/spox/_inline.py index 4dd8e7a8..14dbb2aa 100644 --- a/src/spox/_inline.py +++ b/src/spox/_inline.py @@ -14,7 +14,7 @@ from spox._node import OpType from spox._scope import Scope from spox._type_system import Type -from spox._var import VarInfo +from spox._var import _VarInfo from . import _value_prop @@ -86,11 +86,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - inputs: Sequence[VarInfo] + inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - outputs: Sequence[VarInfo] + outputs: Sequence[_VarInfo] op_type = OpType("Inline", "spox.internal", 0) diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index a0618cf0..c22ca8ae 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -20,7 +20,7 @@ from ._shape import SimpleShape from ._type_system import Tensor, Type from ._value_prop import PropDict, PropValueType -from ._var import Var, VarInfo, unwrap_vars +from ._var import Var, _VarInfo, unwrap_vars # This is a default used for internal operators that # require the default domain. The most common of these @@ -78,7 +78,7 @@ class Inputs(BaseInputs): @dataclass class Outputs(BaseOutputs): - arg: VarInfo + arg: _VarInfo attrs: Attributes inputs: Inputs @@ -115,7 +115,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - arg: VarInfo + arg: _VarInfo attrs: Attributes inputs: BaseInputs @@ -149,11 +149,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - inputs: Sequence[VarInfo] + inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - outputs: Sequence[VarInfo] + outputs: Sequence[_VarInfo] op_type = OpType("Introduce", "spox.internal", 0) diff --git a/src/spox/_node.py b/src/spox/_node.py index c4524e29..1e2d9107 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -20,7 +20,7 @@ from ._fields import BaseAttributes, BaseInputs, BaseOutputs, VarFieldKind from ._type_system import Type from ._value_prop import PropDict -from ._var import VarInfo +from ._var import _VarInfo if typing.TYPE_CHECKING: from ._graph import Graph @@ -308,28 +308,28 @@ def _init_output_vars(self) -> BaseOutputs: (variadic,) = variadics else: variadic = None - outputs: dict[str, Union[VarInfo, Sequence[VarInfo]]] = { - field.name: VarInfo(self, None) + outputs: dict[str, Union[_VarInfo, Sequence[_VarInfo]]] = { + field.name: _VarInfo(self, None) for field in dataclasses.fields(self.Outputs) if field.name != variadic } if variadic is not None: assert self.out_variadic is not None - outputs[variadic] = [VarInfo(self, None) for _ in range(self.out_variadic)] + outputs[variadic] = [_VarInfo(self, None) for _ in range(self.out_variadic)] return self.Outputs(**outputs) # type: ignore @property - def dependencies(self) -> Iterable[VarInfo]: + def dependencies(self) -> Iterable[_VarInfo]: """List of input VarInfos into this Node.""" return (var for var in self.inputs.get_var_infos().values()) @property - def dependents(self) -> Iterable[VarInfo]: + def dependents(self) -> Iterable[_VarInfo]: """List of output VarInfos from this Node.""" return (var for var in self.outputs.get_var_infos().values()) @property - def incident(self) -> Iterable[VarInfo]: + def incident(self) -> Iterable[_VarInfo]: """List of both input and output VarInfos for this Node.""" return itertools.chain(self.dependencies, self.dependents) diff --git a/src/spox/_scope.py b/src/spox/_scope.py index c7c9ff53..fde170b2 100644 --- a/src/spox/_scope.py +++ b/src/spox/_scope.py @@ -5,7 +5,7 @@ from typing import Generic, Optional, TypeVar, Union, overload from ._node import Node -from ._var import VarInfo +from ._var import _VarInfo H = TypeVar("H", bound=Hashable) @@ -155,12 +155,12 @@ class Scope: Has namespaces (represented by a ScopeSpace) for VarInfos and Nodes. """ - var: ScopeSpace[VarInfo] + var: ScopeSpace[_VarInfo] node: ScopeSpace[Node] def __init__( self, - sub_var: Optional[ScopeSpace[VarInfo]] = None, + sub_var: Optional[ScopeSpace[_VarInfo]] = None, sub_node: Optional[ScopeSpace[Node]] = None, parent: Optional["Scope"] = None, ): @@ -180,7 +180,7 @@ def of(cls, *what): if not isinstance(key, str): key, value = value, key assert isinstance(key, str) - if isinstance(value, VarInfo): + if isinstance(value, _VarInfo): scope.var[key] = value elif isinstance(value, Node): scope.node[key] = value diff --git a/src/spox/_var.py b/src/spox/_var.py index 7e5b1753..6a92c069 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -22,7 +22,7 @@ def _not_impl(self, *_): add = sub = mul = truediv = floordiv = neg = and_ = or_ = xor = not_ = _not_impl -class VarInfo: +class _VarInfo: """ Internal information about a ``Var``. Should be mainly inaccessible for most uses of ``spox``. @@ -100,12 +100,12 @@ def unwrap_optional(self) -> _type_system.Optional: """Equivalent to ``self.unwrap_type().unwrap_optional()``.""" return self.unwrap_type().unwrap_optional() - def __copy__(self) -> "VarInfo": + def __copy__(self) -> "_VarInfo": # Simply return `self` to ensure that "copies" are still equal # during the build process return self - def __deepcopy__(self, _) -> "VarInfo": + def __deepcopy__(self, _) -> "_VarInfo": raise ValueError("'VarInfo' objects cannot be deepcopied.") @@ -137,14 +137,14 @@ class Var: Should not be constructed directly - the main source of ``VarInfo`` objects are operator constructors. """ - _var_info: VarInfo + _var_info: _VarInfo _value: Optional[_value_prop.PropValue] _operator_dispatcher: ClassVar[Any] = NotImplementedOperatorDispatcher() def __init__( self, - var_info: VarInfo, + var_info: _VarInfo, value: Optional[_value_prop.PropValue] = None, ): """The initializer of ``Var`` is protected. Use operator constructors to construct them instead.""" @@ -296,25 +296,25 @@ def __rxor__(self, other) -> "Var": @overload -def wrap_vars(var_info: VarInfo) -> Var: ... +def wrap_vars(var_info: _VarInfo) -> Var: ... @overload -def wrap_vars(var_info: Optional[VarInfo]) -> Optional[Var]: ... +def wrap_vars(var_info: Optional[_VarInfo]) -> Optional[Var]: ... @overload -def wrap_vars(var_info: dict[T, VarInfo]) -> dict[T, Var]: ... # type: ignore[misc] +def wrap_vars(var_info: dict[T, _VarInfo]) -> dict[T, Var]: ... # type: ignore[misc] @overload -def wrap_vars(var_info: Union[Sequence[VarInfo], Iterable[VarInfo]]) -> list[Var]: ... +def wrap_vars(var_info: Union[Sequence[_VarInfo], Iterable[_VarInfo]]) -> list[Var]: ... def wrap_vars(var_info): if var_info is None: return None - elif isinstance(var_info, VarInfo): + elif isinstance(var_info, _VarInfo): return Var(var_info) elif isinstance(var_info, dict): return {k: wrap_vars(v) for k, v in var_info.items()} @@ -325,19 +325,19 @@ def wrap_vars(var_info): @overload -def unwrap_vars(var: Var) -> VarInfo: ... +def unwrap_vars(var: Var) -> _VarInfo: ... @overload -def unwrap_vars(var: Optional[Var]) -> Optional[VarInfo]: ... +def unwrap_vars(var: Optional[Var]) -> Optional[_VarInfo]: ... @overload -def unwrap_vars(var: dict[T, Var]) -> dict[T, VarInfo]: ... # type: ignore[misc] +def unwrap_vars(var: dict[T, Var]) -> dict[T, _VarInfo]: ... # type: ignore[misc] @overload -def unwrap_vars(var: Union[Sequence[Var], Iterable[Var]]) -> list[VarInfo]: ... +def unwrap_vars(var: Union[Sequence[Var], Iterable[Var]]) -> list[_VarInfo]: ... def unwrap_vars(var): @@ -386,14 +386,14 @@ def get_value(var): def result_type( - *types: Union[VarInfo, np.generic, int, float], + *types: Union[_VarInfo, np.generic, int, float], ) -> type[np.generic]: """Promote type for all given element types/values using ``np.result_type``.""" return np.dtype( np.result_type( *( typ.unwrap_tensor().dtype - if isinstance(typ, Var) or isinstance(typ, VarInfo) + if isinstance(typ, Var) or isinstance(typ, _VarInfo) else typ for typ in types ) diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index f46c83a6..c98211bf 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -24,7 +24,7 @@ from spox._standard import InferenceError, StandardNode from spox._type_system import Tensor, Type from spox._value_prop import PropDict -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, get_value, unwrap_vars class _ArrayFeatureExtractor(StandardNode): @@ -34,12 +34,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - Y: VarInfo + X: _VarInfo + Y: _VarInfo @dataclass class Outputs(BaseOutputs): - Z: VarInfo + Z: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -70,11 +70,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {} @@ -95,11 +95,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("CastMap", "ai.onnx.ml", 1) @@ -118,11 +118,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -151,11 +151,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("DictVectorizer", "ai.onnx.ml", 1) @@ -171,11 +171,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: Sequence[VarInfo] + X: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("FeatureVectorizer", "ai.onnx.ml", 1) @@ -194,11 +194,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -257,11 +257,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("LabelEncoder", "ai.onnx.ml", 2) @@ -282,12 +282,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo - Z: VarInfo + Y: _VarInfo + Z: _VarInfo op_type = OpType("LinearClassifier", "ai.onnx.ml", 1) @@ -306,11 +306,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -340,11 +340,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if self.attrs.norm.value not in ("MAX", "L1", "L2"): @@ -369,11 +369,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if not self.inputs.fully_typed: @@ -413,12 +413,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo - Z: VarInfo + Y: _VarInfo + Z: _VarInfo op_type = OpType("SVMClassifier", "ai.onnx.ml", 1) @@ -441,11 +441,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("SVMRegressor", "ai.onnx.ml", 1) @@ -462,11 +462,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if self.inputs.X.type is None: @@ -521,12 +521,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo - Z: VarInfo + Y: _VarInfo + Z: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: e = ( @@ -586,11 +586,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: if self.inputs.fully_typed: @@ -620,11 +620,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Z: VarInfo + Z: _VarInfo op_type = OpType("ZipMap", "ai.onnx.ml", 1) diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index 1406e125..7d18772f 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -23,7 +23,7 @@ from spox._node import OpType from spox._standard import StandardNode from spox._value_prop import PropDict -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.ml.v3 import ( _ArrayFeatureExtractor, _Binarizer, @@ -80,11 +80,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("LabelEncoder", "ai.onnx.ml", 4) diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index db93d63f..02862ed9 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -19,7 +19,7 @@ from spox._node import OpType from spox._standard import StandardNode from spox._value_prop import PropDict -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.ml.v4 import ( _ArrayFeatureExtractor, _Binarizer, @@ -78,11 +78,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("TreeEnsemble", "ai.onnx.ml", 5) diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index a65241e0..465a38bb 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -32,7 +32,7 @@ from spox._type_system import Sequence as SpoxSequence from spox._type_system import Tensor, Type from spox._value_prop import PropDict, PropValueType -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, get_value, unwrap_vars class _Abs(StandardNode): @@ -42,11 +42,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Abs", "", 13) @@ -62,11 +62,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Acos", "", 7) @@ -82,11 +82,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Acosh", "", 9) @@ -102,12 +102,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Add", "", 14) @@ -123,12 +123,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("And", "", 7) @@ -146,11 +146,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ArgMax", "", 13) @@ -168,11 +168,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ArgMin", "", 13) @@ -188,11 +188,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Asin", "", 7) @@ -208,11 +208,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Asinh", "", 9) @@ -228,11 +228,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Atan", "", 7) @@ -248,11 +248,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Atanh", "", 9) @@ -273,11 +273,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("AveragePool", "", 11) @@ -295,17 +295,17 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - scale: VarInfo - B: VarInfo - input_mean: VarInfo - input_var: VarInfo + X: _VarInfo + scale: _VarInfo + B: _VarInfo + input_mean: _VarInfo + input_var: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo - running_mean: Optional[VarInfo] - running_var: Optional[VarInfo] + Y: _VarInfo + running_mean: Optional[_VarInfo] + running_var: Optional[_VarInfo] op_type = OpType("BatchNormalization", "", 15) @@ -322,11 +322,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Bernoulli", "", 15) @@ -342,12 +342,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - Y: VarInfo + X: _VarInfo + Y: _VarInfo @dataclass class Outputs(BaseOutputs): - Z: VarInfo + Z: _VarInfo op_type = OpType("BitShift", "", 11) @@ -364,11 +364,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - size: VarInfo + size: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("BlackmanWindow", "", 17) @@ -384,11 +384,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Cast", "", 13) @@ -404,12 +404,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - target_type: VarInfo + input: _VarInfo + target_type: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("CastLike", "", 15) @@ -425,11 +425,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Ceil", "", 13) @@ -445,11 +445,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Celu", "", 12) @@ -465,13 +465,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - min: Optional[VarInfo] - max: Optional[VarInfo] + input: _VarInfo + min: Optional[_VarInfo] + max: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Clip", "", 13) @@ -487,12 +487,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - condition: VarInfo + input: _VarInfo + condition: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: self.infer_output_types_onnx() @@ -534,11 +534,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - inputs: Sequence[VarInfo] + inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - concat_result: VarInfo + concat_result: _VarInfo op_type = OpType("Concat", "", 13) @@ -555,11 +555,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: VarInfo + input_sequence: _VarInfo @dataclass class Outputs(BaseOutputs): - concat_result: VarInfo + concat_result: _VarInfo op_type = OpType("ConcatFromSequence", "", 11) @@ -583,7 +583,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo def propagate_values(self, input_prop_values: PropDict) -> dict[str, PropValueType]: ((key, raw),) = ( @@ -625,11 +625,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("ConstantOfShape", "", 9) @@ -650,13 +650,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - W: VarInfo - B: Optional[VarInfo] + X: _VarInfo + W: _VarInfo + B: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Conv", "", 11) @@ -677,14 +677,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - w: VarInfo - x_zero_point: Optional[VarInfo] - w_zero_point: Optional[VarInfo] + x: _VarInfo + w: _VarInfo + x_zero_point: Optional[_VarInfo] + w_zero_point: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("ConvInteger", "", 10) @@ -707,13 +707,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - W: VarInfo - B: Optional[VarInfo] + X: _VarInfo + W: _VarInfo + B: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("ConvTranspose", "", 11) @@ -729,11 +729,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Cos", "", 7) @@ -749,11 +749,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Cosh", "", 9) @@ -770,12 +770,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - axis: VarInfo + x: _VarInfo + axis: _VarInfo @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("CumSum", "", 14) @@ -793,12 +793,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - dft_length: Optional[VarInfo] + input: _VarInfo + dft_length: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("DFT", "", 17) @@ -815,11 +815,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("DepthToSpace", "", 13) @@ -835,13 +835,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - x_scale: VarInfo - x_zero_point: Optional[VarInfo] + x: _VarInfo + x_scale: _VarInfo + x_zero_point: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("DequantizeLinear", "", 13) @@ -857,11 +857,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Det", "", 11) @@ -877,12 +877,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Div", "", 14) @@ -898,14 +898,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - ratio: Optional[VarInfo] - training_mode: Optional[VarInfo] + data: _VarInfo + ratio: Optional[_VarInfo] + training_mode: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo - mask: Optional[VarInfo] + output: _VarInfo + mask: Optional[_VarInfo] op_type = OpType("Dropout", "", 13) @@ -921,13 +921,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo + x: _VarInfo @dataclass class Outputs(BaseOutputs): - y: VarInfo - y_scale: VarInfo - y_zero_point: VarInfo + y: _VarInfo + y_scale: _VarInfo + y_zero_point: _VarInfo op_type = OpType("DynamicQuantizeLinear", "", 11) @@ -943,11 +943,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - Inputs: Sequence[VarInfo] + Inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - Output: VarInfo + Output: _VarInfo op_type = OpType("Einsum", "", 12) @@ -963,11 +963,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Elu", "", 6) @@ -983,12 +983,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Equal", "", 13) @@ -1004,11 +1004,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Erf", "", 13) @@ -1024,11 +1024,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Exp", "", 13) @@ -1044,12 +1044,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - shape: VarInfo + input: _VarInfo + shape: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Expand", "", 13) @@ -1066,11 +1066,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("EyeLike", "", 9) @@ -1086,11 +1086,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Flatten", "", 13) @@ -1106,11 +1106,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Floor", "", 13) @@ -1133,17 +1133,17 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - W: VarInfo - R: VarInfo - B: Optional[VarInfo] - sequence_lens: Optional[VarInfo] - initial_h: Optional[VarInfo] + X: _VarInfo + W: _VarInfo + R: _VarInfo + B: Optional[_VarInfo] + sequence_lens: Optional[_VarInfo] + initial_h: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Optional[VarInfo] - Y_h: Optional[VarInfo] + Y: Optional[_VarInfo] + Y_h: Optional[_VarInfo] op_type = OpType("GRU", "", 14) @@ -1159,12 +1159,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - indices: VarInfo + data: _VarInfo + indices: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Gather", "", 13) @@ -1180,12 +1180,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - indices: VarInfo + data: _VarInfo + indices: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("GatherElements", "", 13) @@ -1201,12 +1201,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - indices: VarInfo + data: _VarInfo + indices: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("GatherND", "", 13) @@ -1225,13 +1225,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo - C: Optional[VarInfo] + A: _VarInfo + B: _VarInfo + C: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Gemm", "", 13) @@ -1247,11 +1247,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("GlobalAveragePool", "", 1) @@ -1267,11 +1267,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("GlobalLpPool", "", 2) @@ -1287,11 +1287,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("GlobalMaxPool", "", 1) @@ -1307,12 +1307,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Greater", "", 13) @@ -1328,12 +1328,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("GreaterOrEqual", "", 16) @@ -1351,12 +1351,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - grid: VarInfo + X: _VarInfo + grid: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("GridSample", "", 16) @@ -1373,11 +1373,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - size: VarInfo + size: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("HammingWindow", "", 17) @@ -1394,11 +1394,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - size: VarInfo + size: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("HannWindow", "", 17) @@ -1415,11 +1415,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("HardSigmoid", "", 6) @@ -1435,11 +1435,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("HardSwish", "", 14) @@ -1455,11 +1455,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Hardmax", "", 13) @@ -1475,11 +1475,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Identity", "", 16) @@ -1496,11 +1496,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - cond: VarInfo + cond: _VarInfo @dataclass class Outputs(BaseOutputs): - outputs: Sequence[VarInfo] + outputs: Sequence[_VarInfo] op_type = OpType("If", "", 16) @@ -1516,13 +1516,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - scale: VarInfo - B: VarInfo + input: _VarInfo + scale: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("InstanceNormalization", "", 6) @@ -1539,11 +1539,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("IsInf", "", 10) @@ -1559,11 +1559,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("IsNaN", "", 13) @@ -1582,11 +1582,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("LRN", "", 13) @@ -1609,20 +1609,20 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - W: VarInfo - R: VarInfo - B: Optional[VarInfo] - sequence_lens: Optional[VarInfo] - initial_h: Optional[VarInfo] - initial_c: Optional[VarInfo] - P: Optional[VarInfo] + X: _VarInfo + W: _VarInfo + R: _VarInfo + B: Optional[_VarInfo] + sequence_lens: Optional[_VarInfo] + initial_h: Optional[_VarInfo] + initial_c: Optional[_VarInfo] + P: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Optional[VarInfo] - Y_h: Optional[VarInfo] - Y_c: Optional[VarInfo] + Y: Optional[_VarInfo] + Y_h: Optional[_VarInfo] + Y_c: Optional[_VarInfo] op_type = OpType("LSTM", "", 14) @@ -1640,15 +1640,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - Scale: VarInfo - B: Optional[VarInfo] + X: _VarInfo + Scale: _VarInfo + B: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo - Mean: Optional[VarInfo] - InvStdDev: Optional[VarInfo] + Y: _VarInfo + Mean: Optional[_VarInfo] + InvStdDev: Optional[_VarInfo] op_type = OpType("LayerNormalization", "", 17) @@ -1664,11 +1664,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("LeakyRelu", "", 16) @@ -1684,12 +1684,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Less", "", 13) @@ -1705,12 +1705,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("LessOrEqual", "", 16) @@ -1726,11 +1726,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Log", "", 13) @@ -1746,11 +1746,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("LogSoftmax", "", 13) @@ -1766,13 +1766,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - M: Optional[VarInfo] - cond: Optional[VarInfo] - v_initial: Sequence[VarInfo] + M: Optional[_VarInfo] + cond: Optional[_VarInfo] + v_initial: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - v_final_and_scan_outputs: Sequence[VarInfo] + v_final_and_scan_outputs: Sequence[_VarInfo] def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: output_types = super().infer_output_types({}) @@ -1803,11 +1803,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("LpNormalization", "", 1) @@ -1827,11 +1827,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("LpPool", "", 11) @@ -1847,12 +1847,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("MatMul", "", 13) @@ -1868,14 +1868,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo - a_zero_point: Optional[VarInfo] - b_zero_point: Optional[VarInfo] + A: _VarInfo + B: _VarInfo + a_zero_point: Optional[_VarInfo] + b_zero_point: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("MatMulInteger", "", 10) @@ -1891,11 +1891,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data_0: Sequence[VarInfo] + data_0: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - max: VarInfo + max: _VarInfo op_type = OpType("Max", "", 13) @@ -1917,12 +1917,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo - Indices: Optional[VarInfo] + Y: _VarInfo + Indices: Optional[_VarInfo] op_type = OpType("MaxPool", "", 12) @@ -1939,12 +1939,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - rois: VarInfo + X: _VarInfo + rois: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("MaxRoiPool", "", 1) @@ -1962,13 +1962,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - I: VarInfo - output_shape: Optional[VarInfo] + X: _VarInfo + I: _VarInfo + output_shape: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("MaxUnpool", "", 11) @@ -1984,11 +1984,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data_0: Sequence[VarInfo] + data_0: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - mean: VarInfo + mean: _VarInfo op_type = OpType("Mean", "", 13) @@ -2004,11 +2004,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("MeanVarianceNormalization", "", 13) @@ -2024,15 +2024,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - num_mel_bins: VarInfo - dft_length: VarInfo - sample_rate: VarInfo - lower_edge_hertz: VarInfo - upper_edge_hertz: VarInfo + num_mel_bins: _VarInfo + dft_length: _VarInfo + sample_rate: _VarInfo + lower_edge_hertz: _VarInfo + upper_edge_hertz: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("MelWeightMatrix", "", 17) @@ -2048,11 +2048,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data_0: Sequence[VarInfo] + data_0: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - min: VarInfo + min: _VarInfo op_type = OpType("Min", "", 13) @@ -2068,12 +2068,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Mod", "", 13) @@ -2089,12 +2089,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Mul", "", 14) @@ -2112,11 +2112,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Multinomial", "", 7) @@ -2132,11 +2132,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Neg", "", 13) @@ -2153,13 +2153,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - target: VarInfo - weight: Optional[VarInfo] + input: _VarInfo + target: _VarInfo + weight: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - loss: VarInfo + loss: _VarInfo op_type = OpType("NegativeLogLikelihoodLoss", "", 13) @@ -2175,15 +2175,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - boxes: VarInfo - scores: VarInfo - max_output_boxes_per_class: Optional[VarInfo] - iou_threshold: Optional[VarInfo] - score_threshold: Optional[VarInfo] + boxes: _VarInfo + scores: _VarInfo + max_output_boxes_per_class: Optional[_VarInfo] + iou_threshold: Optional[_VarInfo] + score_threshold: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - selected_indices: VarInfo + selected_indices: _VarInfo op_type = OpType("NonMaxSuppression", "", 11) @@ -2199,11 +2199,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("NonZero", "", 13) @@ -2219,11 +2219,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Not", "", 1) @@ -2239,13 +2239,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - indices: VarInfo - depth: VarInfo - values: VarInfo + indices: _VarInfo + depth: _VarInfo + values: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("OneHot", "", 11) @@ -2261,11 +2261,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Optional[VarInfo] + input: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Optional", "", 15) @@ -2281,11 +2281,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("OptionalGetElement", "", 15) @@ -2301,11 +2301,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("OptionalHasElement", "", 15) @@ -2321,12 +2321,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Or", "", 7) @@ -2342,12 +2342,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - slope: VarInfo + X: _VarInfo + slope: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("PRelu", "", 16) @@ -2363,13 +2363,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - pads: VarInfo - constant_value: Optional[VarInfo] + data: _VarInfo + pads: _VarInfo + constant_value: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Pad", "", 13) @@ -2385,12 +2385,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - Y: VarInfo + X: _VarInfo + Y: _VarInfo @dataclass class Outputs(BaseOutputs): - Z: VarInfo + Z: _VarInfo op_type = OpType("Pow", "", 15) @@ -2411,19 +2411,19 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - x_scale: VarInfo - x_zero_point: VarInfo - w: VarInfo - w_scale: VarInfo - w_zero_point: VarInfo - y_scale: VarInfo - y_zero_point: VarInfo - B: Optional[VarInfo] + x: _VarInfo + x_scale: _VarInfo + x_zero_point: _VarInfo + w: _VarInfo + w_scale: _VarInfo + w_zero_point: _VarInfo + y_scale: _VarInfo + y_zero_point: _VarInfo + B: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("QLinearConv", "", 10) @@ -2439,18 +2439,18 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - a: VarInfo - a_scale: VarInfo - a_zero_point: VarInfo - b: VarInfo - b_scale: VarInfo - b_zero_point: VarInfo - y_scale: VarInfo - y_zero_point: VarInfo + a: _VarInfo + a_scale: _VarInfo + a_zero_point: _VarInfo + b: _VarInfo + b_scale: _VarInfo + b_zero_point: _VarInfo + y_scale: _VarInfo + y_zero_point: _VarInfo @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("QLinearMatMul", "", 10) @@ -2466,13 +2466,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - y_scale: VarInfo - y_zero_point: Optional[VarInfo] + x: _VarInfo + y_scale: _VarInfo + y_zero_point: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("QuantizeLinear", "", 13) @@ -2494,17 +2494,17 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - W: VarInfo - R: VarInfo - B: Optional[VarInfo] - sequence_lens: Optional[VarInfo] - initial_h: Optional[VarInfo] + X: _VarInfo + W: _VarInfo + R: _VarInfo + B: Optional[_VarInfo] + sequence_lens: Optional[_VarInfo] + initial_h: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: Optional[VarInfo] - Y_h: Optional[VarInfo] + Y: Optional[_VarInfo] + Y_h: Optional[_VarInfo] op_type = OpType("RNN", "", 14) @@ -2526,7 +2526,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("RandomNormal", "", 1) @@ -2545,11 +2545,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("RandomNormalLike", "", 1) @@ -2571,7 +2571,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("RandomUniform", "", 1) @@ -2590,11 +2590,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("RandomUniformLike", "", 1) @@ -2610,13 +2610,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - start: VarInfo - limit: VarInfo - delta: VarInfo + start: _VarInfo + limit: _VarInfo + delta: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Range", "", 11) @@ -2632,11 +2632,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Reciprocal", "", 13) @@ -2653,11 +2653,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceL1", "", 13) @@ -2674,11 +2674,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceL2", "", 13) @@ -2695,11 +2695,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceLogSum", "", 13) @@ -2716,11 +2716,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceLogSumExp", "", 13) @@ -2737,11 +2737,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceMax", "", 13) @@ -2758,11 +2758,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceMean", "", 13) @@ -2779,11 +2779,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceMin", "", 13) @@ -2800,11 +2800,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceProd", "", 13) @@ -2821,12 +2821,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceSum", "", 13) @@ -2843,11 +2843,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceSumSquare", "", 13) @@ -2863,11 +2863,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Relu", "", 14) @@ -2883,12 +2883,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - shape: VarInfo + data: _VarInfo + shape: _VarInfo @dataclass class Outputs(BaseOutputs): - reshaped: VarInfo + reshaped: _VarInfo op_type = OpType("Reshape", "", 14) @@ -2909,14 +2909,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - roi: Optional[VarInfo] - scales: Optional[VarInfo] - sizes: Optional[VarInfo] + X: _VarInfo + roi: Optional[_VarInfo] + scales: Optional[_VarInfo] + sizes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Resize", "", 13) @@ -2933,12 +2933,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - sequence_lens: VarInfo + input: _VarInfo + sequence_lens: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("ReverseSequence", "", 10) @@ -2959,13 +2959,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - rois: VarInfo - batch_indices: VarInfo + X: _VarInfo + rois: _VarInfo + batch_indices: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("RoiAlign", "", 16) @@ -2981,11 +2981,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Round", "", 11) @@ -3001,14 +3001,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - signal: VarInfo - frame_step: VarInfo - window: Optional[VarInfo] - frame_length: Optional[VarInfo] + signal: _VarInfo + frame_step: _VarInfo + window: Optional[_VarInfo] + frame_length: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("STFT", "", 17) @@ -3029,11 +3029,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - initial_state_and_scan_inputs: Sequence[VarInfo] + initial_state_and_scan_inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - final_state_and_scan_outputs: Sequence[VarInfo] + final_state_and_scan_outputs: Sequence[_VarInfo] op_type = OpType("Scan", "", 16) @@ -3050,13 +3050,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - indices: VarInfo - updates: VarInfo + data: _VarInfo + indices: _VarInfo + updates: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("ScatterElements", "", 16) @@ -3072,13 +3072,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - indices: VarInfo - updates: VarInfo + data: _VarInfo + indices: _VarInfo + updates: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("ScatterND", "", 16) @@ -3095,11 +3095,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Selu", "", 6) @@ -3115,12 +3115,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: VarInfo - position: VarInfo + input_sequence: _VarInfo + position: _VarInfo @dataclass class Outputs(BaseOutputs): - tensor: VarInfo + tensor: _VarInfo op_type = OpType("SequenceAt", "", 11) @@ -3136,11 +3136,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - inputs: Sequence[VarInfo] + inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - output_sequence: VarInfo + output_sequence: _VarInfo op_type = OpType("SequenceConstruct", "", 11) @@ -3158,7 +3158,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("SequenceEmpty", "", 11) @@ -3174,12 +3174,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: VarInfo - position: Optional[VarInfo] + input_sequence: _VarInfo + position: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output_sequence: VarInfo + output_sequence: _VarInfo op_type = OpType("SequenceErase", "", 11) @@ -3195,13 +3195,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: VarInfo - tensor: VarInfo - position: Optional[VarInfo] + input_sequence: _VarInfo + tensor: _VarInfo + position: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output_sequence: VarInfo + output_sequence: _VarInfo op_type = OpType("SequenceInsert", "", 11) @@ -3217,11 +3217,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: VarInfo + input_sequence: _VarInfo @dataclass class Outputs(BaseOutputs): - length: VarInfo + length: _VarInfo op_type = OpType("SequenceLength", "", 11) @@ -3237,12 +3237,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_sequence: VarInfo - additional_inputs: Sequence[VarInfo] + input_sequence: _VarInfo + additional_inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - out_sequence: Sequence[VarInfo] + out_sequence: Sequence[_VarInfo] op_type = OpType("SequenceMap", "", 17) @@ -3259,11 +3259,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - shape: VarInfo + shape: _VarInfo op_type = OpType("Shape", "", 15) @@ -3280,11 +3280,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Shrink", "", 9) @@ -3300,11 +3300,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Sigmoid", "", 13) @@ -3320,11 +3320,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Sign", "", 13) @@ -3340,11 +3340,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Sin", "", 7) @@ -3360,11 +3360,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Sinh", "", 9) @@ -3380,11 +3380,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - size: VarInfo + size: _VarInfo op_type = OpType("Size", "", 13) @@ -3400,15 +3400,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - starts: VarInfo - ends: VarInfo - axes: Optional[VarInfo] - steps: Optional[VarInfo] + data: _VarInfo + starts: _VarInfo + ends: _VarInfo + axes: Optional[_VarInfo] + steps: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Slice", "", 13) @@ -3424,11 +3424,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Softmax", "", 13) @@ -3445,14 +3445,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - scores: VarInfo - labels: VarInfo - weights: Optional[VarInfo] + scores: _VarInfo + labels: _VarInfo + weights: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo - log_prob: Optional[VarInfo] + output: _VarInfo + log_prob: Optional[_VarInfo] op_type = OpType("SoftmaxCrossEntropyLoss", "", 13) @@ -3468,11 +3468,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Softplus", "", 1) @@ -3488,11 +3488,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Softsign", "", 1) @@ -3508,11 +3508,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("SpaceToDepth", "", 13) @@ -3528,12 +3528,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - split: Optional[VarInfo] + input: _VarInfo + split: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - outputs: Sequence[VarInfo] + outputs: Sequence[_VarInfo] op_type = OpType("Split", "", 13) @@ -3550,12 +3550,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - split: Optional[VarInfo] + input: _VarInfo + split: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output_sequence: VarInfo + output_sequence: _VarInfo op_type = OpType("SplitToSequence", "", 11) @@ -3571,11 +3571,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Sqrt", "", 13) @@ -3591,12 +3591,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - squeezed: VarInfo + squeezed: _VarInfo op_type = OpType("Squeeze", "", 13) @@ -3615,11 +3615,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("StringNormalizer", "", 10) @@ -3635,12 +3635,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Sub", "", 14) @@ -3656,11 +3656,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data_0: Sequence[VarInfo] + data_0: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - sum: VarInfo + sum: _VarInfo op_type = OpType("Sum", "", 13) @@ -3676,11 +3676,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Tan", "", 7) @@ -3696,11 +3696,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Tanh", "", 13) @@ -3724,11 +3724,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("TfIdfVectorizer", "", 9) @@ -3744,11 +3744,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("ThresholdedRelu", "", 10) @@ -3764,12 +3764,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - repeats: VarInfo + input: _VarInfo + repeats: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Tile", "", 13) @@ -3787,13 +3787,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - K: VarInfo + X: _VarInfo + K: _VarInfo @dataclass class Outputs(BaseOutputs): - Values: VarInfo - Indices: VarInfo + Values: _VarInfo + Indices: _VarInfo op_type = OpType("TopK", "", 11) @@ -3809,11 +3809,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - transposed: VarInfo + transposed: _VarInfo op_type = OpType("Transpose", "", 13) @@ -3829,12 +3829,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - k: Optional[VarInfo] + input: _VarInfo + k: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Trilu", "", 14) @@ -3851,14 +3851,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo - indices: Optional[VarInfo] - inverse_indices: Optional[VarInfo] - counts: Optional[VarInfo] + Y: _VarInfo + indices: Optional[_VarInfo] + inverse_indices: Optional[_VarInfo] + counts: Optional[_VarInfo] op_type = OpType("Unique", "", 11) @@ -3874,12 +3874,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: VarInfo + data: _VarInfo + axes: _VarInfo @dataclass class Outputs(BaseOutputs): - expanded: VarInfo + expanded: _VarInfo op_type = OpType("Unsqueeze", "", 13) @@ -3895,13 +3895,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - condition: VarInfo - X: VarInfo - Y: VarInfo + condition: _VarInfo + X: _VarInfo + Y: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Where", "", 16) @@ -3917,12 +3917,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Xor", "", 7) diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index 7d7f7f30..e9481293 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -21,7 +21,7 @@ from spox._node import OpType from spox._standard import StandardNode from spox._value_prop import PropDict -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v17 import ( _DFT, _GRU, @@ -351,12 +351,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("BitwiseAnd", "", 18) @@ -372,11 +372,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("BitwiseNot", "", 18) @@ -392,12 +392,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("BitwiseOr", "", 18) @@ -413,12 +413,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("BitwiseXor", "", 18) @@ -434,12 +434,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input_data: VarInfo - shape: VarInfo + input_data: _VarInfo + shape: _VarInfo @dataclass class Outputs(BaseOutputs): - output_data: VarInfo + output_data: _VarInfo op_type = OpType("CenterCropPad", "", 18) @@ -457,13 +457,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - image_shape: VarInfo - block_shape: VarInfo + input: _VarInfo + image_shape: _VarInfo + block_shape: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Col2Im", "", 18) @@ -480,13 +480,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - scale: VarInfo - bias: VarInfo + X: _VarInfo + scale: _VarInfo + bias: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("GroupNormalization", "", 18) @@ -508,11 +508,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("LpPool", "", 18) @@ -528,11 +528,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Mish", "", 18) @@ -548,11 +548,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("OptionalGetElement", "", 18) @@ -568,11 +568,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: Optional[VarInfo] + input: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("OptionalHasElement", "", 18) @@ -588,14 +588,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - pads: VarInfo - constant_value: Optional[VarInfo] - axes: Optional[VarInfo] + data: _VarInfo + pads: _VarInfo + constant_value: Optional[_VarInfo] + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Pad", "", 18) @@ -612,12 +612,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceL1", "", 18) @@ -634,12 +634,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceL2", "", 18) @@ -656,12 +656,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceLogSum", "", 18) @@ -678,12 +678,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceLogSumExp", "", 18) @@ -700,12 +700,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceMax", "", 18) @@ -722,12 +722,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceMean", "", 18) @@ -744,12 +744,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceMin", "", 18) @@ -766,12 +766,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceProd", "", 18) @@ -788,12 +788,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceSumSquare", "", 18) @@ -817,14 +817,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - roi: Optional[VarInfo] - scales: Optional[VarInfo] - sizes: Optional[VarInfo] + X: _VarInfo + roi: Optional[_VarInfo] + scales: Optional[_VarInfo] + sizes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Resize", "", 18) @@ -841,13 +841,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - indices: VarInfo - updates: VarInfo + data: _VarInfo + indices: _VarInfo + updates: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("ScatterElements", "", 18) @@ -863,13 +863,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - indices: VarInfo - updates: VarInfo + data: _VarInfo + indices: _VarInfo + updates: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("ScatterND", "", 18) @@ -886,12 +886,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - split: Optional[VarInfo] + input: _VarInfo + split: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - outputs: Sequence[VarInfo] + outputs: Sequence[_VarInfo] op_type = OpType("Split", "", 18) diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index acd9c494..aaac7aad 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -30,7 +30,7 @@ from spox._standard import StandardNode from spox._type_system import Tensor, Type from spox._value_prop import PropDict, PropValueType -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v18 import ( _DFT, _GRU, @@ -384,11 +384,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("AveragePool", "", 19) @@ -405,11 +405,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Cast", "", 19) @@ -425,12 +425,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - target_type: VarInfo + input: _VarInfo + target_type: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("CastLike", "", 19) @@ -454,7 +454,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo def propagate_values(self, input_prop_values: PropDict) -> dict[str, PropValueType]: ((key, raw),) = ( @@ -501,15 +501,15 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - W: VarInfo - offset: VarInfo - B: Optional[VarInfo] - mask: Optional[VarInfo] + X: _VarInfo + W: _VarInfo + offset: _VarInfo + B: Optional[_VarInfo] + mask: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("DeformConv", "", 19) @@ -525,13 +525,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - x_scale: VarInfo - x_zero_point: Optional[VarInfo] + x: _VarInfo + x_scale: _VarInfo + x_zero_point: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("DequantizeLinear", "", 19) @@ -547,12 +547,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - A: VarInfo - B: VarInfo + A: _VarInfo + B: _VarInfo @dataclass class Outputs(BaseOutputs): - C: VarInfo + C: _VarInfo op_type = OpType("Equal", "", 19) @@ -568,11 +568,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Identity", "", 19) @@ -589,11 +589,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - cond: VarInfo + cond: _VarInfo @dataclass class Outputs(BaseOutputs): - outputs: Sequence[VarInfo] + outputs: Sequence[_VarInfo] op_type = OpType("If", "", 19) @@ -609,13 +609,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - M: Optional[VarInfo] - cond: Optional[VarInfo] - v_initial: Sequence[VarInfo] + M: Optional[_VarInfo] + cond: Optional[_VarInfo] + v_initial: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - v_final_and_scan_outputs: Sequence[VarInfo] + v_final_and_scan_outputs: Sequence[_VarInfo] op_type = OpType("Loop", "", 19) @@ -631,14 +631,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - pads: VarInfo - constant_value: Optional[VarInfo] - axes: Optional[VarInfo] + data: _VarInfo + pads: _VarInfo + constant_value: Optional[_VarInfo] + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Pad", "", 19) @@ -655,13 +655,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - y_scale: VarInfo - y_zero_point: Optional[VarInfo] + x: _VarInfo + y_scale: _VarInfo + y_zero_point: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("QuantizeLinear", "", 19) @@ -677,12 +677,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - shape: VarInfo + data: _VarInfo + shape: _VarInfo @dataclass class Outputs(BaseOutputs): - reshaped: VarInfo + reshaped: _VarInfo op_type = OpType("Reshape", "", 19) @@ -706,14 +706,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - roi: Optional[VarInfo] - scales: Optional[VarInfo] - sizes: Optional[VarInfo] + X: _VarInfo + roi: Optional[_VarInfo] + scales: Optional[_VarInfo] + sizes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Resize", "", 19) @@ -734,11 +734,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - initial_state_and_scan_inputs: Sequence[VarInfo] + initial_state_and_scan_inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - final_state_and_scan_outputs: Sequence[VarInfo] + final_state_and_scan_outputs: Sequence[_VarInfo] op_type = OpType("Scan", "", 19) @@ -755,11 +755,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - shape: VarInfo + shape: _VarInfo op_type = OpType("Shape", "", 19) @@ -775,11 +775,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - size: VarInfo + size: _VarInfo op_type = OpType("Size", "", 19) diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index ac389811..86770841 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -19,7 +19,7 @@ from spox._node import OpType from spox._standard import StandardNode from spox._value_prop import PropDict -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v19 import ( _GRU, _LRN, @@ -387,12 +387,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - theta: VarInfo - size: VarInfo + theta: _VarInfo + size: _VarInfo @dataclass class Outputs(BaseOutputs): - grid: VarInfo + grid: _VarInfo op_type = OpType("AffineGrid", "", 20) @@ -408,11 +408,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("ConstantOfShape", "", 20) @@ -429,13 +429,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - dft_length: Optional[VarInfo] - axis: Optional[VarInfo] + input: _VarInfo + dft_length: Optional[_VarInfo] + axis: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("DFT", "", 20) @@ -451,11 +451,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("Gelu", "", 20) @@ -473,12 +473,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - grid: VarInfo + X: _VarInfo + grid: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("GridSample", "", 20) @@ -494,11 +494,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - encoded_stream: VarInfo + encoded_stream: _VarInfo @dataclass class Outputs(BaseOutputs): - image: VarInfo + image: _VarInfo op_type = OpType("ImageDecoder", "", 20) @@ -515,11 +515,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("IsInf", "", 20) @@ -535,11 +535,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("IsNaN", "", 20) @@ -556,12 +556,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceMax", "", 20) @@ -578,12 +578,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - reduced: VarInfo + reduced: _VarInfo op_type = OpType("ReduceMin", "", 20) @@ -599,11 +599,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("RegexFullMatch", "", 20) @@ -619,12 +619,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - Y: VarInfo + X: _VarInfo + Y: _VarInfo @dataclass class Outputs(BaseOutputs): - Z: VarInfo + Z: _VarInfo op_type = OpType("StringConcat", "", 20) @@ -641,12 +641,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo - Z: VarInfo + Y: _VarInfo + Z: _VarInfo op_type = OpType("StringSplit", "", 20) diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 66279ce6..003c3c65 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -30,7 +30,7 @@ from spox._standard import StandardNode from spox._type_system import Tensor, Type from spox._value_prop import PropDict, PropValueType -from spox._var import Var, VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, get_value, unwrap_vars from spox.opset.ai.onnx.v20 import ( _DFT, _GRU, @@ -385,11 +385,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Cast", "", 21) @@ -405,12 +405,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo - target_type: VarInfo + input: _VarInfo + target_type: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("CastLike", "", 21) @@ -434,7 +434,7 @@ class Attributes(BaseAttributes): @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo def propagate_values(self, input_prop_values: PropDict) -> dict[str, PropValueType]: ((key, raw),) = ( @@ -476,11 +476,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("ConstantOfShape", "", 21) @@ -497,13 +497,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - x_scale: VarInfo - x_zero_point: Optional[VarInfo] + x: _VarInfo + x_scale: _VarInfo + x_zero_point: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("DequantizeLinear", "", 21) @@ -519,11 +519,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Flatten", "", 21) @@ -541,13 +541,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo - scale: VarInfo - bias: VarInfo + X: _VarInfo + scale: _VarInfo + bias: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("GroupNormalization", "", 21) @@ -563,11 +563,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - input: VarInfo + input: _VarInfo @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Identity", "", 21) @@ -584,11 +584,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - cond: VarInfo + cond: _VarInfo @dataclass class Outputs(BaseOutputs): - outputs: Sequence[VarInfo] + outputs: Sequence[_VarInfo] op_type = OpType("If", "", 21) @@ -604,13 +604,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - M: Optional[VarInfo] - cond: Optional[VarInfo] - v_initial: Sequence[VarInfo] + M: Optional[_VarInfo] + cond: Optional[_VarInfo] + v_initial: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - v_final_and_scan_outputs: Sequence[VarInfo] + v_final_and_scan_outputs: Sequence[_VarInfo] op_type = OpType("Loop", "", 21) @@ -626,14 +626,14 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - pads: VarInfo - constant_value: Optional[VarInfo] - axes: Optional[VarInfo] + data: _VarInfo + pads: _VarInfo + constant_value: Optional[_VarInfo] + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - output: VarInfo + output: _VarInfo op_type = OpType("Pad", "", 21) @@ -649,18 +649,18 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - a: VarInfo - a_scale: VarInfo - a_zero_point: VarInfo - b: VarInfo - b_scale: VarInfo - b_zero_point: VarInfo - y_scale: VarInfo - y_zero_point: VarInfo + a: _VarInfo + a_scale: _VarInfo + a_zero_point: _VarInfo + b: _VarInfo + b_scale: _VarInfo + b_zero_point: _VarInfo + y_scale: _VarInfo + y_zero_point: _VarInfo @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("QLinearMatMul", "", 21) @@ -679,13 +679,13 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - x: VarInfo - y_scale: VarInfo - y_zero_point: Optional[VarInfo] + x: _VarInfo + y_scale: _VarInfo + y_zero_point: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - y: VarInfo + y: _VarInfo op_type = OpType("QuantizeLinear", "", 21) @@ -701,12 +701,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - shape: VarInfo + data: _VarInfo + shape: _VarInfo @dataclass class Outputs(BaseOutputs): - reshaped: VarInfo + reshaped: _VarInfo op_type = OpType("Reshape", "", 21) @@ -727,11 +727,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - initial_state_and_scan_inputs: Sequence[VarInfo] + initial_state_and_scan_inputs: Sequence[_VarInfo] @dataclass class Outputs(BaseOutputs): - final_state_and_scan_outputs: Sequence[VarInfo] + final_state_and_scan_outputs: Sequence[_VarInfo] op_type = OpType("Scan", "", 21) @@ -748,11 +748,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - shape: VarInfo + shape: _VarInfo op_type = OpType("Shape", "", 21) @@ -768,11 +768,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - size: VarInfo + size: _VarInfo op_type = OpType("Size", "", 21) @@ -788,12 +788,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: Optional[VarInfo] + data: _VarInfo + axes: Optional[_VarInfo] @dataclass class Outputs(BaseOutputs): - squeezed: VarInfo + squeezed: _VarInfo op_type = OpType("Squeeze", "", 21) @@ -809,11 +809,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - transposed: VarInfo + transposed: _VarInfo op_type = OpType("Transpose", "", 21) @@ -829,12 +829,12 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo - axes: VarInfo + data: _VarInfo + axes: _VarInfo @dataclass class Outputs(BaseOutputs): - expanded: VarInfo + expanded: _VarInfo op_type = OpType("Unsqueeze", "", 21) diff --git a/tests/test_adapt.py b/tests/test_adapt.py index a90e0778..2a6a2450 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -19,7 +19,7 @@ from spox._graph import arguments, results from spox._node import OpType from spox._standard import StandardNode -from spox._var import VarInfo +from spox._var import _VarInfo @pytest.fixture @@ -84,11 +84,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - data: VarInfo + data: _VarInfo @dataclass class Outputs(BaseOutputs): - squeezed: VarInfo + squeezed: _VarInfo op_type = OpType("Squeeze", "", 11) diff --git a/tests/test_custom_operator.py b/tests/test_custom_operator.py index b4e178ae..a2eeb4c1 100644 --- a/tests/test_custom_operator.py +++ b/tests/test_custom_operator.py @@ -19,7 +19,7 @@ from spox._graph import arguments, results from spox._node import Node, OpType from spox._type_system import Tensor, Type -from spox._var import VarInfo +from spox._var import _VarInfo # Define the Node for this operator - need to know the attributes, inputs and outputs statically @@ -33,11 +33,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo # This is optional, but is useful when defining the inference functions below. attrs: Attributes diff --git a/tests/test_function.py b/tests/test_function.py index 5018714d..a02568cd 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -19,7 +19,7 @@ from spox._graph import arguments, results from spox._node import OpType from spox._type_system import Tensor -from spox._var import Var, VarInfo +from spox._var import Var, _VarInfo @pytest.fixture @@ -32,11 +32,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("LinearFunction", "spox.test", 0) @@ -87,11 +87,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("LinearFunction2", "spox.test", 0) @@ -138,11 +138,11 @@ class Attributes(BaseAttributes): @dataclass class Inputs(BaseInputs): - X: VarInfo + X: _VarInfo @dataclass class Outputs(BaseOutputs): - Y: VarInfo + Y: _VarInfo op_type = OpType("CubicFunction", "spox.test.extra", 0) diff --git a/tests/test_value_propagation.py b/tests/test_value_propagation.py index 06a19550..19852b9c 100644 --- a/tests/test_value_propagation.py +++ b/tests/test_value_propagation.py @@ -13,7 +13,7 @@ from spox._graph import arguments, results from spox._shape import Shape from spox._value_prop import ORTValue, PropValue -from spox._var import VarInfo +from spox._var import _VarInfo @pytest.fixture( @@ -28,7 +28,7 @@ def value_prop_backend(request): def dummy_var(typ=None, value=None): """Function for creating a ``var`` without an operator but with a type and value.""" - return Var(VarInfo(None, typ), value) # type: ignore + return Var(_VarInfo(None, typ), value) # type: ignore def assert_equal_value(var: Var, expected: ORTValue): From 3f25d7eb7fd1424f0557283279847a1ecd47a286 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Fri, 22 Nov 2024 15:15:36 +0200 Subject: [PATCH 24/29] Fix jinja --- tools/templates/class.jinja2 | 12 ++++++------ tools/templates/preamble.jinja2 | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/templates/class.jinja2 b/tools/templates/class.jinja2 index 4ab22209..d3367d2b 100644 --- a/tools/templates/class.jinja2 +++ b/tools/templates/class.jinja2 @@ -14,11 +14,11 @@ class _{{ schema.name }}(StandardNode): {% for input in schema.inputs %} {{ input.name }}: {% if is_optional(input) - %}Optional[VarInfo]{% + %}Optional[_VarInfo]{% elif is_variadic(input) - %}Sequence[VarInfo]{% + %}Sequence[_VarInfo]{% else - %}VarInfo{% + %}_VarInfo{% endif %} {% endfor %} @@ -33,11 +33,11 @@ class _{{ schema.name }}(StandardNode): {% for output in schema.outputs %} {{ output.name }}: {% if is_optional(output) - %}Optional[VarInfo]{% + %}Optional[_VarInfo]{% elif is_variadic(output) - %}Sequence[VarInfo]{% + %}Sequence[_VarInfo]{% else - %}VarInfo{% + %}_VarInfo{% endif %} {% endfor %} diff --git a/tools/templates/preamble.jinja2 b/tools/templates/preamble.jinja2 index 7824457f..8569252a 100644 --- a/tools/templates/preamble.jinja2 +++ b/tools/templates/preamble.jinja2 @@ -14,7 +14,7 @@ from typing import cast as typing_cast import numpy as np import numpy.typing as npt -from spox._var import Var, VarInfo, result_type, unwrap_vars, get_value +from spox._var import Var, _VarInfo, result_type, unwrap_vars, get_value from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, From a8cebe239aed6e6f932eed63bdabaf929e18d7b4 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Tue, 26 Nov 2024 16:26:39 +0200 Subject: [PATCH 25/29] Fix variadic input value propagation --- src/spox/_var.py | 18 + src/spox/opset/ai/onnx/ml/v3.py | 112 +-- src/spox/opset/ai/onnx/ml/v4.py | 9 +- src/spox/opset/ai/onnx/ml/v5.py | 9 +- src/spox/opset/ai/onnx/v17.py | 1331 +++++++++++++++--------------- src/spox/opset/ai/onnx/v18.py | 209 +++-- src/spox/opset/ai/onnx/v19.py | 138 ++-- src/spox/opset/ai/onnx/v20.py | 95 ++- src/spox/opset/ai/onnx/v21.py | 162 ++-- tests/test_value_propagation.py | 7 + tools/templates/construct.jinja2 | 6 +- tools/templates/preamble.jinja2 | 2 +- 12 files changed, 1062 insertions(+), 1036 deletions(-) diff --git a/src/spox/_var.py b/src/spox/_var.py index 6a92c069..a0b1a082 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -399,3 +399,21 @@ def result_type( ) ) ).type + + +def create_prop_dict( + **kwargs: Union[Var, Sequence[Var], Optional[Var]], +) -> _value_prop.PropDict: + from ._fields import BaseVars + + flattened_vars = BaseVars(kwargs).flatten_vars() + + return { + key: ( + var._value + if isinstance(var, Var) + else {k: v._value for k, v in var.items()} + ) + for key, var in flattened_vars.items() + if var is not None + } diff --git a/src/spox/opset/ai/onnx/ml/v3.py b/src/spox/opset/ai/onnx/ml/v3.py index c98211bf..25c388ca 100644 --- a/src/spox/opset/ai/onnx/ml/v3.py +++ b/src/spox/opset/ai/onnx/ml/v3.py @@ -24,7 +24,7 @@ from spox._standard import InferenceError, StandardNode from spox._type_system import Tensor, Type from spox._value_prop import PropDict -from spox._var import Var, _VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, create_prop_dict, unwrap_vars class _ArrayFeatureExtractor(StandardNode): @@ -663,10 +663,10 @@ def array_feature_extractor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "Y": get_value(Y), - } + input_prop_values = create_prop_dict( + X=X, + Y=Y, + ) return ( _ArrayFeatureExtractor( _ArrayFeatureExtractor.Attributes(), @@ -711,9 +711,9 @@ def binarizer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Binarizer( _Binarizer.Attributes( @@ -775,9 +775,9 @@ def cast_map( - T1: `map(int64,tensor(float))`, `map(int64,tensor(string))` - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _CastMap( _CastMap.Attributes( @@ -849,9 +849,9 @@ def category_mapper( - T1: `tensor(int64)`, `tensor(string)` - T2: `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _CategoryMapper( _CategoryMapper.Attributes( @@ -919,9 +919,9 @@ def dict_vectorizer( - T1: `map(int64,tensor(double))`, `map(int64,tensor(float))`, `map(int64,tensor(string))`, `map(string,tensor(double))`, `map(string,tensor(float))`, `map(string,tensor(int64))` - T2: `tensor(double)`, `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _DictVectorizer( _DictVectorizer.Attributes( @@ -975,9 +975,9 @@ def feature_vectorizer( Type constraints: - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _FeatureVectorizer( _FeatureVectorizer.Attributes( @@ -1049,9 +1049,9 @@ def imputer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Imputer( _Imputer.Attributes( @@ -1157,9 +1157,9 @@ def label_encoder( - T1: `tensor(float)`, `tensor(int64)`, `tensor(string)` - T2: `tensor(float)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _LabelEncoder( _LabelEncoder.Attributes( @@ -1239,9 +1239,9 @@ def linear_classifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _LinearClassifier( _LinearClassifier.Attributes( @@ -1314,9 +1314,9 @@ def linear_regressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _LinearRegressor( _LinearRegressor.Attributes( @@ -1370,9 +1370,9 @@ def normalizer( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Normalizer( _Normalizer.Attributes( @@ -1436,9 +1436,9 @@ def one_hot_encoder( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _OneHotEncoder( _OneHotEncoder.Attributes( @@ -1537,9 +1537,9 @@ def svmclassifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _SVMClassifier( _SVMClassifier.Attributes( @@ -1633,9 +1633,9 @@ def svmregressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _SVMRegressor( _SVMRegressor.Attributes( @@ -1698,9 +1698,9 @@ def scaler( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Scaler( _Scaler.Attributes( @@ -1850,9 +1850,9 @@ def tree_ensemble_classifier( - T1: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` - T2: `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _TreeEnsembleClassifier( _TreeEnsembleClassifier.Attributes( @@ -2042,9 +2042,9 @@ def tree_ensemble_regressor( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _TreeEnsembleRegressor( _TreeEnsembleRegressor.Attributes( @@ -2142,9 +2142,9 @@ def zip_map( Type constraints: - T: `seq(map(int64,tensor(float)))`, `seq(map(string,tensor(float)))` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _ZipMap( _ZipMap.Attributes( diff --git a/src/spox/opset/ai/onnx/ml/v4.py b/src/spox/opset/ai/onnx/ml/v4.py index 7d18772f..9f9fdf90 100644 --- a/src/spox/opset/ai/onnx/ml/v4.py +++ b/src/spox/opset/ai/onnx/ml/v4.py @@ -22,8 +22,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._value_prop import PropDict -from spox._var import Var, _VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, create_prop_dict, unwrap_vars from spox.opset.ai.onnx.ml.v3 import ( _ArrayFeatureExtractor, _Binarizer, @@ -192,9 +191,9 @@ def label_encoder( - T1: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` - T2: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _LabelEncoder( _LabelEncoder.Attributes( diff --git a/src/spox/opset/ai/onnx/ml/v5.py b/src/spox/opset/ai/onnx/ml/v5.py index 02862ed9..4b073e70 100644 --- a/src/spox/opset/ai/onnx/ml/v5.py +++ b/src/spox/opset/ai/onnx/ml/v5.py @@ -18,8 +18,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._value_prop import PropDict -from spox._var import Var, _VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, create_prop_dict, unwrap_vars from spox.opset.ai.onnx.ml.v4 import ( _ArrayFeatureExtractor, _Binarizer, @@ -225,9 +224,9 @@ def tree_ensemble( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _TreeEnsemble( _TreeEnsemble.Attributes( diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index 465a38bb..e4d57437 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -32,7 +32,12 @@ from spox._type_system import Sequence as SpoxSequence from spox._type_system import Tensor, Type from spox._value_prop import PropDict, PropValueType -from spox._var import Var, _VarInfo, get_value, unwrap_vars +from spox._var import ( + Var, + _VarInfo, + create_prop_dict, + unwrap_vars, +) class _Abs(StandardNode): @@ -3958,9 +3963,9 @@ def abs( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Abs( _Abs.Attributes(), @@ -3999,9 +4004,9 @@ def acos( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Acos( _Acos.Attributes(), @@ -4041,9 +4046,9 @@ def acosh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Acosh( _Acosh.Attributes(), @@ -4093,10 +4098,10 @@ def add( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Add( _Add.Attributes(), @@ -4146,10 +4151,10 @@ def and_( - T: `tensor(bool)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _And( _And.Attributes(), @@ -4211,9 +4216,9 @@ def arg_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ArgMax( _ArgMax.Attributes( @@ -4280,9 +4285,9 @@ def arg_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ArgMin( _ArgMin.Attributes( @@ -4327,9 +4332,9 @@ def asin( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Asin( _Asin.Attributes(), @@ -4368,9 +4373,9 @@ def asinh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Asinh( _Asinh.Attributes(), @@ -4409,9 +4414,9 @@ def atan( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Atan( _Atan.Attributes(), @@ -4451,9 +4456,9 @@ def atanh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Atanh( _Atanh.Attributes(), @@ -4587,9 +4592,9 @@ def average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _AveragePool( _AveragePool.Attributes( @@ -4731,13 +4736,13 @@ def batch_normalization( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "scale": get_value(scale), - "B": get_value(B), - "input_mean": get_value(input_mean), - "input_var": get_value(input_var), - } + input_prop_values = create_prop_dict( + X=X, + scale=scale, + B=B, + input_mean=input_mean, + input_var=input_var, + ) return ( _BatchNormalization( _BatchNormalization.Attributes( @@ -4803,9 +4808,9 @@ def bernoulli( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Bernoulli( _Bernoulli.Attributes( @@ -4871,10 +4876,10 @@ def bit_shift( Type constraints: - T: `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "Y": get_value(Y), - } + input_prop_values = create_prop_dict( + X=X, + Y=Y, + ) return ( _BitShift( _BitShift.Attributes( @@ -4931,9 +4936,9 @@ def blackman_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "size": get_value(size), - } + input_prop_values = create_prop_dict( + size=size, + ) return ( _BlackmanWindow( _BlackmanWindow.Attributes( @@ -5031,9 +5036,9 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Cast( _Cast.Attributes( @@ -5082,10 +5087,10 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "target_type": get_value(target_type), - } + input_prop_values = create_prop_dict( + input=input, + target_type=target_type, + ) return ( _CastLike( _CastLike.Attributes(), @@ -5127,9 +5132,9 @@ def ceil( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Ceil( _Ceil.Attributes(), @@ -5178,9 +5183,9 @@ def celu( Type constraints: - T: `tensor(float)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Celu( _Celu.Attributes( @@ -5232,11 +5237,11 @@ def clip( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "min": get_value(min), - "max": get_value(max), - } + input_prop_values = create_prop_dict( + input=input, + min=min, + max=max, + ) return ( _Clip( _Clip.Attributes(), @@ -5297,10 +5302,10 @@ def compress( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "condition": get_value(condition), - } + input_prop_values = create_prop_dict( + input=input, + condition=condition, + ) return ( _Compress( _Compress.Attributes( @@ -5349,9 +5354,9 @@ def concat( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "inputs": get_value(inputs), - } + input_prop_values = create_prop_dict( + inputs=inputs, + ) return ( _Concat( _Concat.Attributes( @@ -5408,9 +5413,9 @@ def concat_from_sequence( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input_sequence": get_value(input_sequence), - } + input_prop_values = create_prop_dict( + input_sequence=input_sequence, + ) return ( _ConcatFromSequence( _ConcatFromSequence.Attributes( @@ -5481,7 +5486,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = {} + input_prop_values = create_prop_dict() return ( _Constant( _Constant.Attributes( @@ -5537,9 +5542,9 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _ConstantOfShape( _ConstantOfShape.Attributes( @@ -5651,11 +5656,11 @@ def conv( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "W": get_value(W), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + X=X, + W=W, + B=B, + ) return ( _Conv( _Conv.Attributes( @@ -5785,12 +5790,12 @@ def conv_integer( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int32)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "w": get_value(w), - "x_zero_point": get_value(x_zero_point), - "w_zero_point": get_value(w_zero_point), - } + input_prop_values = create_prop_dict( + x=x, + w=w, + x_zero_point=x_zero_point, + w_zero_point=w_zero_point, + ) return ( _ConvInteger( _ConvInteger.Attributes( @@ -5941,11 +5946,11 @@ def conv_transpose( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "W": get_value(W), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + X=X, + W=W, + B=B, + ) return ( _ConvTranspose( _ConvTranspose.Attributes( @@ -5994,9 +5999,9 @@ def cos( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Cos( _Cos.Attributes(), @@ -6034,9 +6039,9 @@ def cosh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Cosh( _Cosh.Attributes(), @@ -6114,10 +6119,10 @@ def cumsum( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "axis": get_value(axis), - } + input_prop_values = create_prop_dict( + x=x, + axis=axis, + ) return ( _CumSum( _CumSum.Attributes( @@ -6207,10 +6212,10 @@ def dft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "dft_length": get_value(dft_length), - } + input_prop_values = create_prop_dict( + input=input, + dft_length=dft_length, + ) return ( _DFT( _DFT.Attributes( @@ -6290,9 +6295,9 @@ def depth_to_space( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _DepthToSpace( _DepthToSpace.Attributes( @@ -6358,11 +6363,11 @@ def dequantize_linear( Type constraints: - T: `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "x_scale": get_value(x_scale), - "x_zero_point": get_value(x_zero_point), - } + input_prop_values = create_prop_dict( + x=x, + x_scale=x_scale, + x_zero_point=x_zero_point, + ) return ( _DequantizeLinear( _DequantizeLinear.Attributes( @@ -6409,9 +6414,9 @@ def det( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Det( _Det.Attributes(), @@ -6461,10 +6466,10 @@ def div( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Div( _Div.Attributes(), @@ -6554,11 +6559,11 @@ def dropout( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bool)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "ratio": get_value(ratio), - "training_mode": get_value(training_mode), - } + input_prop_values = create_prop_dict( + data=data, + ratio=ratio, + training_mode=training_mode, + ) return ( _Dropout( _Dropout.Attributes( @@ -6642,9 +6647,9 @@ def dynamic_quantize_linear( - T1: `tensor(float)` - T2: `tensor(uint8)` """ - input_prop_values: PropDict = { - "x": get_value(x), - } + input_prop_values = create_prop_dict( + x=x, + ) return ( _DynamicQuantizeLinear( _DynamicQuantizeLinear.Attributes(), @@ -6719,9 +6724,9 @@ def einsum( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "Inputs": get_value(Inputs), - } + input_prop_values = create_prop_dict( + Inputs=Inputs, + ) return ( _Einsum( _Einsum.Attributes( @@ -6769,9 +6774,9 @@ def elu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Elu( _Elu.Attributes( @@ -6822,10 +6827,10 @@ def equal( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Equal( _Equal.Attributes(), @@ -6865,9 +6870,9 @@ def erf( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Erf( _Erf.Attributes(), @@ -6905,9 +6910,9 @@ def exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Exp( _Exp.Attributes(), @@ -6958,10 +6963,10 @@ def expand( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "shape": get_value(shape), - } + input_prop_values = create_prop_dict( + input=input, + shape=shape, + ) return ( _Expand( _Expand.Attributes(), @@ -7023,9 +7028,9 @@ def eye_like( - T1: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _EyeLike( _EyeLike.Attributes( @@ -7080,9 +7085,9 @@ def flatten( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Flatten( _Flatten.Attributes( @@ -7125,9 +7130,9 @@ def floor( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Floor( _Floor.Attributes(), @@ -7312,14 +7317,14 @@ def gru( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "W": get_value(W), - "R": get_value(R), - "B": get_value(B), - "sequence_lens": get_value(sequence_lens), - "initial_h": get_value(initial_h), - } + input_prop_values = create_prop_dict( + X=X, + W=W, + R=R, + B=B, + sequence_lens=sequence_lens, + initial_h=initial_h, + ) return ( _GRU( _GRU.Attributes( @@ -7438,10 +7443,10 @@ def gather( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "indices": get_value(indices), - } + input_prop_values = create_prop_dict( + data=data, + indices=indices, + ) return ( _Gather( _Gather.Attributes( @@ -7551,10 +7556,10 @@ def gather_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "indices": get_value(indices), - } + input_prop_values = create_prop_dict( + data=data, + indices=indices, + ) return ( _GatherElements( _GatherElements.Attributes( @@ -7709,10 +7714,10 @@ def gather_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "indices": get_value(indices), - } + input_prop_values = create_prop_dict( + data=data, + indices=indices, + ) return ( _GatherND( _GatherND.Attributes( @@ -7801,11 +7806,11 @@ def gemm( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - "C": get_value(C), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + C=C, + ) return ( _Gemm( _Gemm.Attributes( @@ -7859,9 +7864,9 @@ def global_average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _GlobalAveragePool( _GlobalAveragePool.Attributes(), @@ -7913,9 +7918,9 @@ def global_lp_pool( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _GlobalLpPool( _GlobalLpPool.Attributes( @@ -7964,9 +7969,9 @@ def global_max_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _GlobalMaxPool( _GlobalMaxPool.Attributes(), @@ -8015,10 +8020,10 @@ def greater( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Greater( _Greater.Attributes(), @@ -8068,10 +8073,10 @@ def greater_or_equal( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _GreaterOrEqual( _GreaterOrEqual.Attributes(), @@ -8167,10 +8172,10 @@ def grid_sample( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "grid": get_value(grid), - } + input_prop_values = create_prop_dict( + X=X, + grid=grid, + ) return ( _GridSample( _GridSample.Attributes( @@ -8229,9 +8234,9 @@ def hamming_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "size": get_value(size), - } + input_prop_values = create_prop_dict( + size=size, + ) return ( _HammingWindow( _HammingWindow.Attributes( @@ -8288,9 +8293,9 @@ def hann_window( - T1: `tensor(int32)`, `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "size": get_value(size), - } + input_prop_values = create_prop_dict( + size=size, + ) return ( _HannWindow( _HannWindow.Attributes( @@ -8342,9 +8347,9 @@ def hard_sigmoid( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _HardSigmoid( _HardSigmoid.Attributes( @@ -8388,9 +8393,9 @@ def hard_swish( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _HardSwish( _HardSwish.Attributes(), @@ -8442,9 +8447,9 @@ def hardmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Hardmax( _Hardmax.Attributes( @@ -8484,9 +8489,9 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Identity( _Identity.Attributes(), @@ -8553,9 +8558,9 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - input_prop_values: PropDict = { - "cond": get_value(cond), - } + input_prop_values = create_prop_dict( + cond=cond, + ) return ( _If( _If.Attributes( @@ -8618,11 +8623,11 @@ def instance_normalization( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "scale": get_value(scale), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + input=input, + scale=scale, + B=B, + ) return ( _InstanceNormalization( _InstanceNormalization.Attributes( @@ -8678,9 +8683,9 @@ def isinf( - T1: `tensor(double)`, `tensor(float)` - T2: `tensor(bool)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _IsInf( _IsInf.Attributes( @@ -8722,9 +8727,9 @@ def isnan( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(bool)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _IsNaN( _IsNaN.Attributes(), @@ -8796,9 +8801,9 @@ def lrn( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _LRN( _LRN.Attributes( @@ -9010,16 +9015,16 @@ def lstm( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "W": get_value(W), - "R": get_value(R), - "B": get_value(B), - "sequence_lens": get_value(sequence_lens), - "initial_h": get_value(initial_h), - "initial_c": get_value(initial_c), - "P": get_value(P), - } + input_prop_values = create_prop_dict( + X=X, + W=W, + R=R, + B=B, + sequence_lens=sequence_lens, + initial_h=initial_h, + initial_c=initial_c, + P=P, + ) return ( _LSTM( _LSTM.Attributes( @@ -9135,11 +9140,11 @@ def layer_normalization( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - U: `tensor(bfloat16)`, `tensor(float)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "Scale": get_value(Scale), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + X=X, + Scale=Scale, + B=B, + ) return ( _LayerNormalization( _LayerNormalization.Attributes( @@ -9191,9 +9196,9 @@ def leaky_relu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _LeakyRelu( _LeakyRelu.Attributes( @@ -9244,10 +9249,10 @@ def less( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Less( _Less.Attributes(), @@ -9297,10 +9302,10 @@ def less_or_equal( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _LessOrEqual( _LessOrEqual.Attributes(), @@ -9339,9 +9344,9 @@ def log( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Log( _Log.Attributes(), @@ -9392,9 +9397,9 @@ def log_softmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _LogSoftmax( _LogSoftmax.Attributes( @@ -9590,11 +9595,11 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - input_prop_values: PropDict = { - "M": get_value(M), - "cond": get_value(cond), - "v_initial": get_value(v_initial), - } + input_prop_values = create_prop_dict( + M=M, + cond=cond, + v_initial=v_initial, + ) return ( _Loop( _Loop.Attributes( @@ -9646,9 +9651,9 @@ def lp_normalization( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _LpNormalization( _LpNormalization.Attributes( @@ -9735,9 +9740,9 @@ def lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _LpPool( _LpPool.Attributes( @@ -9786,10 +9791,10 @@ def matmul( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _MatMul( _MatMul.Attributes(), @@ -9855,12 +9860,12 @@ def matmul_integer( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int32)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - "a_zero_point": get_value(a_zero_point), - "b_zero_point": get_value(b_zero_point), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + a_zero_point=a_zero_point, + b_zero_point=b_zero_point, + ) return ( _MatMulInteger( _MatMulInteger.Attributes(), @@ -9905,9 +9910,9 @@ def max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data_0": get_value(data_0), - } + input_prop_values = create_prop_dict( + data_0=data_0, + ) return ( _Max( _Max.Attributes(), @@ -10056,9 +10061,9 @@ def max_pool( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int8)`, `tensor(uint8)` - I: `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _MaxPool( _MaxPool.Attributes( @@ -10124,10 +10129,10 @@ def max_roi_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "rois": get_value(rois), - } + input_prop_values = create_prop_dict( + X=X, + rois=rois, + ) return ( _MaxRoiPool( _MaxRoiPool.Attributes( @@ -10240,11 +10245,11 @@ def max_unpool( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "I": get_value(I), - "output_shape": get_value(output_shape), - } + input_prop_values = create_prop_dict( + X=X, + I=I, + output_shape=output_shape, + ) return ( _MaxUnpool( _MaxUnpool.Attributes( @@ -10292,9 +10297,9 @@ def mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "data_0": get_value(data_0), - } + input_prop_values = create_prop_dict( + data_0=data_0, + ) return ( _Mean( _Mean.Attributes(), @@ -10342,9 +10347,9 @@ def mean_variance_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _MeanVarianceNormalization( _MeanVarianceNormalization.Attributes( @@ -10433,13 +10438,13 @@ def mel_weight_matrix( - T2: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T3: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "num_mel_bins": get_value(num_mel_bins), - "dft_length": get_value(dft_length), - "sample_rate": get_value(sample_rate), - "lower_edge_hertz": get_value(lower_edge_hertz), - "upper_edge_hertz": get_value(upper_edge_hertz), - } + input_prop_values = create_prop_dict( + num_mel_bins=num_mel_bins, + dft_length=dft_length, + sample_rate=sample_rate, + lower_edge_hertz=lower_edge_hertz, + upper_edge_hertz=upper_edge_hertz, + ) return ( _MelWeightMatrix( _MelWeightMatrix.Attributes( @@ -10487,9 +10492,9 @@ def min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data_0": get_value(data_0), - } + input_prop_values = create_prop_dict( + data_0=data_0, + ) return ( _Min( _Min.Attributes(), @@ -10554,10 +10559,10 @@ def mod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Mod( _Mod.Attributes( @@ -10610,10 +10615,10 @@ def mul( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Mul( _Mul.Attributes(), @@ -10674,9 +10679,9 @@ def multinomial( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Multinomial( _Multinomial.Attributes( @@ -10720,9 +10725,9 @@ def neg( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Neg( _Neg.Attributes(), @@ -10892,11 +10897,11 @@ def negative_log_likelihood_loss( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "target": get_value(target), - "weight": get_value(weight), - } + input_prop_values = create_prop_dict( + input=input, + target=target, + weight=weight, + ) return ( _NegativeLogLikelihoodLoss( _NegativeLogLikelihoodLoss.Attributes( @@ -10980,13 +10985,13 @@ def non_max_suppression( Signature: ``ai.onnx@11::NonMaxSuppression``. """ - input_prop_values: PropDict = { - "boxes": get_value(boxes), - "scores": get_value(scores), - "max_output_boxes_per_class": get_value(max_output_boxes_per_class), - "iou_threshold": get_value(iou_threshold), - "score_threshold": get_value(score_threshold), - } + input_prop_values = create_prop_dict( + boxes=boxes, + scores=scores, + max_output_boxes_per_class=max_output_boxes_per_class, + iou_threshold=iou_threshold, + score_threshold=score_threshold, + ) return ( _NonMaxSuppression( _NonMaxSuppression.Attributes( @@ -11034,9 +11039,9 @@ def non_zero( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _NonZero( _NonZero.Attributes(), @@ -11074,9 +11079,9 @@ def not_( Type constraints: - T: `tensor(bool)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Not( _Not.Attributes(), @@ -11170,11 +11175,11 @@ def one_hot( - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T3: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "indices": get_value(indices), - "depth": get_value(depth), - "values": get_value(values), - } + input_prop_values = create_prop_dict( + indices=indices, + depth=depth, + values=values, + ) return ( _OneHot( _OneHot.Attributes( @@ -11224,9 +11229,9 @@ def optional( - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Optional( _Optional.Attributes( @@ -11269,9 +11274,9 @@ def optional_get_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _OptionalGetElement( _OptionalGetElement.Attributes(), @@ -11312,9 +11317,9 @@ def optional_has_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))` - B: `tensor(bool)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _OptionalHasElement( _OptionalHasElement.Attributes(), @@ -11363,10 +11368,10 @@ def or_( - T: `tensor(bool)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Or( _Or.Attributes(), @@ -11416,10 +11421,10 @@ def prelu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "slope": get_value(slope), - } + input_prop_values = create_prop_dict( + X=X, + slope=slope, + ) return ( _PRelu( _PRelu.Attributes(), @@ -11527,11 +11532,11 @@ def pad( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "pads": get_value(pads), - "constant_value": get_value(constant_value), - } + input_prop_values = create_prop_dict( + data=data, + pads=pads, + constant_value=constant_value, + ) return ( _Pad( _Pad.Attributes( @@ -11583,10 +11588,10 @@ def pow( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)` - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "Y": get_value(Y), - } + input_prop_values = create_prop_dict( + X=X, + Y=Y, + ) return ( _Pow( _Pow.Attributes(), @@ -11740,17 +11745,17 @@ def qlinear_conv( - T3: `tensor(int8)`, `tensor(uint8)` - T4: `tensor(int32)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "x_scale": get_value(x_scale), - "x_zero_point": get_value(x_zero_point), - "w": get_value(w), - "w_scale": get_value(w_scale), - "w_zero_point": get_value(w_zero_point), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + x=x, + x_scale=x_scale, + x_zero_point=x_zero_point, + w=w, + w_scale=w_scale, + w_zero_point=w_zero_point, + y_scale=y_scale, + y_zero_point=y_zero_point, + B=B, + ) return ( _QLinearConv( _QLinearConv.Attributes( @@ -11850,16 +11855,16 @@ def qlinear_matmul( - T2: `tensor(int8)`, `tensor(uint8)` - T3: `tensor(int8)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "a": get_value(a), - "a_scale": get_value(a_scale), - "a_zero_point": get_value(a_zero_point), - "b": get_value(b), - "b_scale": get_value(b_scale), - "b_zero_point": get_value(b_zero_point), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } + input_prop_values = create_prop_dict( + a=a, + a_scale=a_scale, + a_zero_point=a_zero_point, + b=b, + b_scale=b_scale, + b_zero_point=b_zero_point, + y_scale=y_scale, + y_zero_point=y_zero_point, + ) return ( _QLinearMatMul( _QLinearMatMul.Attributes(), @@ -11933,11 +11938,11 @@ def quantize_linear( - T1: `tensor(float)`, `tensor(int32)` - T2: `tensor(int8)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } + input_prop_values = create_prop_dict( + x=x, + y_scale=y_scale, + y_zero_point=y_zero_point, + ) return ( _QuantizeLinear( _QuantizeLinear.Attributes( @@ -12106,14 +12111,14 @@ def rnn( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T1: `tensor(int32)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "W": get_value(W), - "R": get_value(R), - "B": get_value(B), - "sequence_lens": get_value(sequence_lens), - "initial_h": get_value(initial_h), - } + input_prop_values = create_prop_dict( + X=X, + W=W, + R=R, + B=B, + sequence_lens=sequence_lens, + initial_h=initial_h, + ) return ( _RNN( _RNN.Attributes( @@ -12194,7 +12199,7 @@ def random_normal( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = {} + input_prop_values = create_prop_dict() return ( _RandomNormal( _RandomNormal.Attributes( @@ -12264,9 +12269,9 @@ def random_normal_like( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _RandomNormalLike( _RandomNormalLike.Attributes( @@ -12334,7 +12339,7 @@ def random_uniform( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = {} + input_prop_values = create_prop_dict() return ( _RandomUniform( _RandomUniform.Attributes( @@ -12404,9 +12409,9 @@ def random_uniform_like( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _RandomUniformLike( _RandomUniformLike.Attributes( @@ -12488,11 +12493,11 @@ def range( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "start": get_value(start), - "limit": get_value(limit), - "delta": get_value(delta), - } + input_prop_values = create_prop_dict( + start=start, + limit=limit, + delta=delta, + ) return ( _Range( _Range.Attributes(), @@ -12534,9 +12539,9 @@ def reciprocal( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Reciprocal( _Reciprocal.Attributes(), @@ -12593,9 +12598,9 @@ def reduce_l1( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceL1( _ReduceL1.Attributes( @@ -12655,9 +12660,9 @@ def reduce_l2( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceL2( _ReduceL2.Attributes( @@ -12718,9 +12723,9 @@ def reduce_log_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceLogSum( _ReduceLogSum.Attributes( @@ -12781,9 +12786,9 @@ def reduce_log_sum_exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceLogSumExp( _ReduceLogSumExp.Attributes( @@ -12845,9 +12850,9 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceMax( _ReduceMax.Attributes( @@ -12907,9 +12912,9 @@ def reduce_mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceMean( _ReduceMean.Attributes( @@ -12970,9 +12975,9 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceMin( _ReduceMin.Attributes( @@ -13032,9 +13037,9 @@ def reduce_prod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceProd( _ReduceProd.Attributes( @@ -13103,10 +13108,10 @@ def reduce_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceSum( _ReduceSum.Attributes( @@ -13169,9 +13174,9 @@ def reduce_sum_square( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _ReduceSumSquare( _ReduceSumSquare.Attributes( @@ -13214,9 +13219,9 @@ def relu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Relu( _Relu.Attributes(), @@ -13280,10 +13285,10 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "shape": get_value(shape), - } + input_prop_values = create_prop_dict( + data=data, + shape=shape, + ) return ( _Reshape( _Reshape.Attributes( @@ -13418,12 +13423,12 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "roi": get_value(roi), - "scales": get_value(scales), - "sizes": get_value(sizes), - } + input_prop_values = create_prop_dict( + X=X, + roi=roi, + scales=scales, + sizes=sizes, + ) return ( _Resize( _Resize.Attributes( @@ -13513,10 +13518,10 @@ def reverse_sequence( Type constraints: - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "sequence_lens": get_value(sequence_lens), - } + input_prop_values = create_prop_dict( + input=input, + sequence_lens=sequence_lens, + ) return ( _ReverseSequence( _ReverseSequence.Attributes( @@ -13620,11 +13625,11 @@ def roi_align( - T1: `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "rois": get_value(rois), - "batch_indices": get_value(batch_indices), - } + input_prop_values = create_prop_dict( + X=X, + rois=rois, + batch_indices=batch_indices, + ) return ( _RoiAlign( _RoiAlign.Attributes( @@ -13688,9 +13693,9 @@ def round( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Round( _Round.Attributes(), @@ -13764,12 +13769,12 @@ def stft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "signal": get_value(signal), - "frame_step": get_value(frame_step), - "window": get_value(window), - "frame_length": get_value(frame_length), - } + input_prop_values = create_prop_dict( + signal=signal, + frame_step=frame_step, + window=window, + frame_length=frame_length, + ) return ( _STFT( _STFT.Attributes( @@ -14008,9 +14013,9 @@ def scan( ], body, ) - input_prop_values: PropDict = { - "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), - } + input_prop_values = create_prop_dict( + initial_state_and_scan_inputs=initial_state_and_scan_inputs, + ) return ( _Scan( _Scan.Attributes( @@ -14161,11 +14166,11 @@ def scatter_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "indices": get_value(indices), - "updates": get_value(updates), - } + input_prop_values = create_prop_dict( + data=data, + indices=indices, + updates=updates, + ) return ( _ScatterElements( _ScatterElements.Attributes( @@ -14292,11 +14297,11 @@ def scatter_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "indices": get_value(indices), - "updates": get_value(updates), - } + input_prop_values = create_prop_dict( + data=data, + indices=indices, + updates=updates, + ) return ( _ScatterND( _ScatterND.Attributes( @@ -14352,9 +14357,9 @@ def selu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Selu( _Selu.Attributes( @@ -14408,10 +14413,10 @@ def sequence_at( - I: `tensor(int32)`, `tensor(int64)` - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input_sequence": get_value(input_sequence), - "position": get_value(position), - } + input_prop_values = create_prop_dict( + input_sequence=input_sequence, + position=position, + ) return ( _SequenceAt( _SequenceAt.Attributes(), @@ -14452,9 +14457,9 @@ def sequence_construct( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - input_prop_values: PropDict = { - "inputs": get_value(inputs), - } + input_prop_values = create_prop_dict( + inputs=inputs, + ) return ( _SequenceConstruct( _SequenceConstruct.Attributes(), @@ -14494,7 +14499,7 @@ def sequence_empty( Type constraints: - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - input_prop_values: PropDict = {} + input_prop_values = create_prop_dict() return ( _SequenceEmpty( _SequenceEmpty.Attributes( @@ -14545,10 +14550,10 @@ def sequence_erase( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - I: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "input_sequence": get_value(input_sequence), - "position": get_value(position), - } + input_prop_values = create_prop_dict( + input_sequence=input_sequence, + position=position, + ) return ( _SequenceErase( _SequenceErase.Attributes(), @@ -14607,11 +14612,11 @@ def sequence_insert( - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - I: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "input_sequence": get_value(input_sequence), - "tensor": get_value(tensor), - "position": get_value(position), - } + input_prop_values = create_prop_dict( + input_sequence=input_sequence, + tensor=tensor, + position=position, + ) return ( _SequenceInsert( _SequenceInsert.Attributes(), @@ -14653,9 +14658,9 @@ def sequence_length( - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` - I: `tensor(int64)` """ - input_prop_values: PropDict = { - "input_sequence": get_value(input_sequence), - } + input_prop_values = create_prop_dict( + input_sequence=input_sequence, + ) return ( _SequenceLength( _SequenceLength.Attributes(), @@ -14728,10 +14733,10 @@ def sequence_map( ], body, ) - input_prop_values: PropDict = { - "input_sequence": get_value(input_sequence), - "additional_inputs": get_value(additional_inputs), - } + input_prop_values = create_prop_dict( + input_sequence=input_sequence, + additional_inputs=additional_inputs, + ) return ( _SequenceMap( _SequenceMap.Attributes( @@ -14824,9 +14829,9 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _Shape( _Shape.Attributes( @@ -14879,9 +14884,9 @@ def shrink( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Shrink( _Shrink.Attributes( @@ -14924,9 +14929,9 @@ def sigmoid( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Sigmoid( _Sigmoid.Attributes(), @@ -14966,9 +14971,9 @@ def sign( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Sign( _Sign.Attributes(), @@ -15006,9 +15011,9 @@ def sin( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Sin( _Sin.Attributes(), @@ -15046,9 +15051,9 @@ def sinh( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Sinh( _Sinh.Attributes(), @@ -15088,9 +15093,9 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _Size( _Size.Attributes(), @@ -15216,13 +15221,13 @@ def slice( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "starts": get_value(starts), - "ends": get_value(ends), - "axes": get_value(axes), - "steps": get_value(steps), - } + input_prop_values = create_prop_dict( + data=data, + starts=starts, + ends=ends, + axes=axes, + steps=steps, + ) return ( _Slice( _Slice.Attributes(), @@ -15279,9 +15284,9 @@ def softmax( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Softmax( _Softmax.Attributes( @@ -15405,11 +15410,11 @@ def softmax_cross_entropy_loss( - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "scores": get_value(scores), - "labels": get_value(labels), - "weights": get_value(weights), - } + input_prop_values = create_prop_dict( + scores=scores, + labels=labels, + weights=weights, + ) return ( _SoftmaxCrossEntropyLoss( _SoftmaxCrossEntropyLoss.Attributes( @@ -15454,9 +15459,9 @@ def softplus( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Softplus( _Softplus.Attributes(), @@ -15496,9 +15501,9 @@ def softsign( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Softsign( _Softsign.Attributes(), @@ -15545,9 +15550,9 @@ def space_to_depth( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _SpaceToDepth( _SpaceToDepth.Attributes( @@ -15604,10 +15609,10 @@ def split( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "split": get_value(split), - } + input_prop_values = create_prop_dict( + input=input, + split=split, + ) return ( _Split( _Split.Attributes( @@ -15679,10 +15684,10 @@ def split_to_sequence( - I: `tensor(int32)`, `tensor(int64)` - S: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))` """ - input_prop_values: PropDict = { - "input": get_value(input), - "split": get_value(split), - } + input_prop_values = create_prop_dict( + input=input, + split=split, + ) return ( _SplitToSequence( _SplitToSequence.Attributes( @@ -15726,9 +15731,9 @@ def sqrt( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Sqrt( _Sqrt.Attributes(), @@ -15776,10 +15781,10 @@ def squeeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _Squeeze( _Squeeze.Attributes(), @@ -15845,9 +15850,9 @@ def string_normalizer( Signature: ``ai.onnx@10::StringNormalizer``. """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _StringNormalizer( _StringNormalizer.Attributes( @@ -15906,10 +15911,10 @@ def sub( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Sub( _Sub.Attributes(), @@ -15952,9 +15957,9 @@ def sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "data_0": get_value(data_0), - } + input_prop_values = create_prop_dict( + data_0=data_0, + ) return ( _Sum( _Sum.Attributes(), @@ -15992,9 +15997,9 @@ def tan( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Tan( _Tan.Attributes(), @@ -16033,9 +16038,9 @@ def tanh( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Tanh( _Tanh.Attributes(), @@ -16177,9 +16182,9 @@ def tf_idf_vectorizer( - T: `tensor(int32)`, `tensor(int64)`, `tensor(string)` - T1: `tensor(float)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _TfIdfVectorizer( _TfIdfVectorizer.Attributes( @@ -16234,9 +16239,9 @@ def thresholded_relu( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _ThresholdedRelu( _ThresholdedRelu.Attributes( @@ -16285,10 +16290,10 @@ def tile( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "repeats": get_value(repeats), - } + input_prop_values = create_prop_dict( + input=input, + repeats=repeats, + ) return ( _Tile( _Tile.Attributes(), @@ -16377,10 +16382,10 @@ def top_k( - T: `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - I: `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "K": get_value(K), - } + input_prop_values = create_prop_dict( + X=X, + K=K, + ) return ( _TopK( _TopK.Attributes( @@ -16431,9 +16436,9 @@ def transpose( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _Transpose( _Transpose.Attributes( @@ -16501,10 +16506,10 @@ def trilu( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "k": get_value(k), - } + input_prop_values = create_prop_dict( + input=input, + k=k, + ) return ( _Trilu( _Trilu.Attributes( @@ -16689,9 +16694,9 @@ def unique( Type constraints: - T: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Unique( _Unique.Attributes( @@ -16752,10 +16757,10 @@ def unsqueeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _Unsqueeze( _Unsqueeze.Attributes(), @@ -16810,11 +16815,11 @@ def where( - B: `tensor(bool)` - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "condition": get_value(condition), - "X": get_value(X), - "Y": get_value(Y), - } + input_prop_values = create_prop_dict( + condition=condition, + X=X, + Y=Y, + ) return ( _Where( _Where.Attributes(), @@ -16865,10 +16870,10 @@ def xor( - T: `tensor(bool)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Xor( _Xor.Attributes(), diff --git a/src/spox/opset/ai/onnx/v18.py b/src/spox/opset/ai/onnx/v18.py index e9481293..031c2541 100644 --- a/src/spox/opset/ai/onnx/v18.py +++ b/src/spox/opset/ai/onnx/v18.py @@ -20,8 +20,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._value_prop import PropDict -from spox._var import Var, _VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, create_prop_dict, unwrap_vars from spox.opset.ai.onnx.v17 import ( _DFT, _GRU, @@ -935,10 +934,10 @@ def bitwise_and( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _BitwiseAnd( _BitwiseAnd.Attributes(), @@ -977,9 +976,9 @@ def bitwise_not( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _BitwiseNot( _BitwiseNot.Attributes(), @@ -1027,10 +1026,10 @@ def bitwise_or( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _BitwiseOr( _BitwiseOr.Attributes(), @@ -1079,10 +1078,10 @@ def bitwise_xor( Type constraints: - T: `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _BitwiseXor( _BitwiseXor.Attributes(), @@ -1143,10 +1142,10 @@ def center_crop_pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "input_data": get_value(input_data), - "shape": get_value(shape), - } + input_prop_values = create_prop_dict( + input_data=input_data, + shape=shape, + ) return ( _CenterCropPad( _CenterCropPad.Attributes( @@ -1242,11 +1241,11 @@ def col2_im( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "image_shape": get_value(image_shape), - "block_shape": get_value(block_shape), - } + input_prop_values = create_prop_dict( + input=input, + image_shape=image_shape, + block_shape=block_shape, + ) return ( _Col2Im( _Col2Im.Attributes( @@ -1330,11 +1329,11 @@ def group_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "scale": get_value(scale), - "bias": get_value(bias), - } + input_prop_values = create_prop_dict( + X=X, + scale=scale, + bias=bias, + ) return ( _GroupNormalization( _GroupNormalization.Attributes( @@ -1460,9 +1459,9 @@ def lp_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _LpPool( _LpPool.Attributes( @@ -1515,9 +1514,9 @@ def mish( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Mish( _Mish.Attributes(), @@ -1559,9 +1558,9 @@ def optional_get_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - V: `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _OptionalGetElement( _OptionalGetElement.Attributes(), @@ -1603,9 +1602,9 @@ def optional_has_element( - O: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - B: `tensor(bool)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _OptionalHasElement( _OptionalHasElement.Attributes(), @@ -1752,12 +1751,12 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "pads": get_value(pads), - "constant_value": get_value(constant_value), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + pads=pads, + constant_value=constant_value, + axes=axes, + ) return ( _Pad( _Pad.Attributes( @@ -1828,10 +1827,10 @@ def reduce_l1( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceL1( _ReduceL1.Attributes( @@ -1903,10 +1902,10 @@ def reduce_l2( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceL2( _ReduceL2.Attributes( @@ -1979,10 +1978,10 @@ def reduce_log_sum( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceLogSum( _ReduceLogSum.Attributes( @@ -2055,10 +2054,10 @@ def reduce_log_sum_exp( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceLogSumExp( _ReduceLogSumExp.Attributes( @@ -2132,10 +2131,10 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceMax( _ReduceMax.Attributes( @@ -2207,10 +2206,10 @@ def reduce_mean( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceMean( _ReduceMean.Attributes( @@ -2283,10 +2282,10 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceMin( _ReduceMin.Attributes( @@ -2358,10 +2357,10 @@ def reduce_prod( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceProd( _ReduceProd.Attributes( @@ -2433,10 +2432,10 @@ def reduce_sum_square( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceSumSquare( _ReduceSumSquare.Attributes( @@ -2625,12 +2624,12 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "roi": get_value(roi), - "scales": get_value(scales), - "sizes": get_value(sizes), - } + input_prop_values = create_prop_dict( + X=X, + roi=roi, + scales=scales, + sizes=sizes, + ) return ( _Resize( _Resize.Attributes( @@ -2786,11 +2785,11 @@ def scatter_elements( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "indices": get_value(indices), - "updates": get_value(updates), - } + input_prop_values = create_prop_dict( + data=data, + indices=indices, + updates=updates, + ) return ( _ScatterElements( _ScatterElements.Attributes( @@ -2933,11 +2932,11 @@ def scatter_nd( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "indices": get_value(indices), - "updates": get_value(updates), - } + input_prop_values = create_prop_dict( + data=data, + indices=indices, + updates=updates, + ) return ( _ScatterND( _ScatterND.Attributes( @@ -3001,10 +3000,10 @@ def split( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "split": get_value(split), - } + input_prop_values = create_prop_dict( + input=input, + split=split, + ) return ( _Split( _Split.Attributes( diff --git a/src/spox/opset/ai/onnx/v19.py b/src/spox/opset/ai/onnx/v19.py index aaac7aad..b9f5f915 100644 --- a/src/spox/opset/ai/onnx/v19.py +++ b/src/spox/opset/ai/onnx/v19.py @@ -30,7 +30,7 @@ from spox._standard import StandardNode from spox._type_system import Tensor, Type from spox._value_prop import PropDict, PropValueType -from spox._var import Var, _VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, create_prop_dict, unwrap_vars from spox.opset.ai.onnx.v18 import ( _DFT, _GRU, @@ -915,9 +915,9 @@ def average_pool( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _AveragePool( _AveragePool.Attributes( @@ -1061,9 +1061,9 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Cast( _Cast.Attributes( @@ -1122,10 +1122,10 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "target_type": get_value(target_type), - } + input_prop_values = create_prop_dict( + input=input, + target_type=target_type, + ) return ( _CastLike( _CastLike.Attributes( @@ -1196,7 +1196,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = {} + input_prop_values = create_prop_dict() return ( _Constant( _Constant.Attributes( @@ -1311,13 +1311,13 @@ def deform_conv( Type constraints: - T: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "W": get_value(W), - "offset": get_value(offset), - "B": get_value(B), - "mask": get_value(mask), - } + input_prop_values = create_prop_dict( + X=X, + W=W, + offset=offset, + B=B, + mask=mask, + ) return ( _DeformConv( _DeformConv.Attributes( @@ -1398,11 +1398,11 @@ def dequantize_linear( - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int32)`, `tensor(int8)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "x_scale": get_value(x_scale), - "x_zero_point": get_value(x_zero_point), - } + input_prop_values = create_prop_dict( + x=x, + x_scale=x_scale, + x_zero_point=x_zero_point, + ) return ( _DequantizeLinear( _DequantizeLinear.Attributes( @@ -1455,10 +1455,10 @@ def equal( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(bool)` """ - input_prop_values: PropDict = { - "A": get_value(A), - "B": get_value(B), - } + input_prop_values = create_prop_dict( + A=A, + B=B, + ) return ( _Equal( _Equal.Attributes(), @@ -1497,9 +1497,9 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Identity( _Identity.Attributes(), @@ -1566,9 +1566,9 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - input_prop_values: PropDict = { - "cond": get_value(cond), - } + input_prop_values = create_prop_dict( + cond=cond, + ) return ( _If( _If.Attributes( @@ -1766,11 +1766,11 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - input_prop_values: PropDict = { - "M": get_value(M), - "cond": get_value(cond), - "v_initial": get_value(v_initial), - } + input_prop_values = create_prop_dict( + M=M, + cond=cond, + v_initial=v_initial, + ) return ( _Loop( _Loop.Attributes( @@ -1948,12 +1948,12 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "pads": get_value(pads), - "constant_value": get_value(constant_value), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + pads=pads, + constant_value=constant_value, + axes=axes, + ) return ( _Pad( _Pad.Attributes( @@ -2037,11 +2037,11 @@ def quantize_linear( - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } + input_prop_values = create_prop_dict( + x=x, + y_scale=y_scale, + y_zero_point=y_zero_point, + ) return ( _QuantizeLinear( _QuantizeLinear.Attributes( @@ -2110,10 +2110,10 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "shape": get_value(shape), - } + input_prop_values = create_prop_dict( + data=data, + shape=shape, + ) return ( _Reshape( _Reshape.Attributes( @@ -2337,12 +2337,12 @@ def resize( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "roi": get_value(roi), - "scales": get_value(scales), - "sizes": get_value(sizes), - } + input_prop_values = create_prop_dict( + X=X, + roi=roi, + scales=scales, + sizes=sizes, + ) return ( _Resize( _Resize.Attributes( @@ -2596,9 +2596,9 @@ def scan( ], body, ) - input_prop_values: PropDict = { - "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), - } + input_prop_values = create_prop_dict( + initial_state_and_scan_inputs=initial_state_and_scan_inputs, + ) return ( _Scan( _Scan.Attributes( @@ -2705,9 +2705,9 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _Shape( _Shape.Attributes( @@ -2750,9 +2750,9 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _Size( _Size.Attributes(), diff --git a/src/spox/opset/ai/onnx/v20.py b/src/spox/opset/ai/onnx/v20.py index 86770841..c228902c 100644 --- a/src/spox/opset/ai/onnx/v20.py +++ b/src/spox/opset/ai/onnx/v20.py @@ -18,8 +18,7 @@ from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._node import OpType from spox._standard import StandardNode -from spox._value_prop import PropDict -from spox._var import Var, _VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, create_prop_dict, unwrap_vars from spox.opset.ai.onnx.v19 import ( _GRU, _LRN, @@ -734,10 +733,10 @@ def affine_grid( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int64)` """ - input_prop_values: PropDict = { - "theta": get_value(theta), - "size": get_value(size), - } + input_prop_values = create_prop_dict( + theta=theta, + size=size, + ) return ( _AffineGrid( _AffineGrid.Attributes( @@ -790,9 +789,9 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _ConstantOfShape( _ConstantOfShape.Attributes( @@ -897,11 +896,11 @@ def dft( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` - T2: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "dft_length": get_value(dft_length), - "axis": get_value(axis), - } + input_prop_values = create_prop_dict( + input=input, + dft_length=dft_length, + axis=axis, + ) return ( _DFT( _DFT.Attributes( @@ -957,9 +956,9 @@ def gelu( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _Gelu( _Gelu.Attributes( @@ -1076,10 +1075,10 @@ def grid_sample( - T1: `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "grid": get_value(grid), - } + input_prop_values = create_prop_dict( + X=X, + grid=grid, + ) return ( _GridSample( _GridSample.Attributes( @@ -1155,9 +1154,9 @@ def image_decoder( - T1: `tensor(uint8)` - T2: `tensor(uint8)` """ - input_prop_values: PropDict = { - "encoded_stream": get_value(encoded_stream), - } + input_prop_values = create_prop_dict( + encoded_stream=encoded_stream, + ) return ( _ImageDecoder( _ImageDecoder.Attributes( @@ -1211,9 +1210,9 @@ def isinf( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - T2: `tensor(bool)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _IsInf( _IsInf.Attributes( @@ -1255,9 +1254,9 @@ def isnan( - T1: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)` - T2: `tensor(bool)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _IsNaN( _IsNaN.Attributes(), @@ -1328,10 +1327,10 @@ def reduce_max( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceMax( _ReduceMax.Attributes( @@ -1407,10 +1406,10 @@ def reduce_min( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _ReduceMin( _ReduceMin.Attributes( @@ -1465,9 +1464,9 @@ def regex_full_match( - T1: `tensor(string)` - T2: `tensor(bool)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _RegexFullMatch( _RegexFullMatch.Attributes( @@ -1512,10 +1511,10 @@ def string_concat( Type constraints: - T: `tensor(string)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "Y": get_value(Y), - } + input_prop_values = create_prop_dict( + X=X, + Y=Y, + ) return ( _StringConcat( _StringConcat.Attributes(), @@ -1598,9 +1597,9 @@ def string_split( - T2: `tensor(string)` - T3: `tensor(int64)` """ - input_prop_values: PropDict = { - "X": get_value(X), - } + input_prop_values = create_prop_dict( + X=X, + ) return ( _StringSplit( _StringSplit.Attributes( diff --git a/src/spox/opset/ai/onnx/v21.py b/src/spox/opset/ai/onnx/v21.py index 003c3c65..2f2e2b4b 100644 --- a/src/spox/opset/ai/onnx/v21.py +++ b/src/spox/opset/ai/onnx/v21.py @@ -30,7 +30,7 @@ from spox._standard import StandardNode from spox._type_system import Tensor, Type from spox._value_prop import PropDict, PropValueType -from spox._var import Var, _VarInfo, get_value, unwrap_vars +from spox._var import Var, _VarInfo, create_prop_dict, unwrap_vars from spox.opset.ai.onnx.v20 import ( _DFT, _GRU, @@ -964,9 +964,9 @@ def cast( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Cast( _Cast.Attributes( @@ -1025,10 +1025,10 @@ def cast_like( - T1: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - "target_type": get_value(target_type), - } + input_prop_values = create_prop_dict( + input=input, + target_type=target_type, + ) return ( _CastLike( _CastLike.Attributes( @@ -1099,7 +1099,7 @@ def constant( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = {} + input_prop_values = create_prop_dict() return ( _Constant( _Constant.Attributes( @@ -1155,9 +1155,9 @@ def constant_of_shape( - T1: `tensor(int64)` - T2: `tensor(bfloat16)`, `tensor(bool)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _ConstantOfShape( _ConstantOfShape.Attributes( @@ -1240,11 +1240,11 @@ def dequantize_linear( - T1: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` - T2: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "x_scale": get_value(x_scale), - "x_zero_point": get_value(x_zero_point), - } + input_prop_values = create_prop_dict( + x=x, + x_scale=x_scale, + x_zero_point=x_zero_point, + ) return ( _DequantizeLinear( _DequantizeLinear.Attributes( @@ -1301,9 +1301,9 @@ def flatten( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Flatten( _Flatten.Attributes( @@ -1397,11 +1397,11 @@ def group_normalization( Type constraints: - T: `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)` """ - input_prop_values: PropDict = { - "X": get_value(X), - "scale": get_value(scale), - "bias": get_value(bias), - } + input_prop_values = create_prop_dict( + X=X, + scale=scale, + bias=bias, + ) return ( _GroupNormalization( _GroupNormalization.Attributes( @@ -1445,9 +1445,9 @@ def identity( Type constraints: - V: `optional(seq(tensor(bool)))`, `optional(seq(tensor(complex128)))`, `optional(seq(tensor(complex64)))`, `optional(seq(tensor(double)))`, `optional(seq(tensor(float)))`, `optional(seq(tensor(float16)))`, `optional(seq(tensor(int16)))`, `optional(seq(tensor(int32)))`, `optional(seq(tensor(int64)))`, `optional(seq(tensor(int8)))`, `optional(seq(tensor(string)))`, `optional(seq(tensor(uint16)))`, `optional(seq(tensor(uint32)))`, `optional(seq(tensor(uint64)))`, `optional(seq(tensor(uint8)))`, `optional(tensor(bool))`, `optional(tensor(complex128))`, `optional(tensor(complex64))`, `optional(tensor(double))`, `optional(tensor(float))`, `optional(tensor(float16))`, `optional(tensor(int16))`, `optional(tensor(int32))`, `optional(tensor(int64))`, `optional(tensor(int8))`, `optional(tensor(string))`, `optional(tensor(uint16))`, `optional(tensor(uint32))`, `optional(tensor(uint64))`, `optional(tensor(uint8))`, `seq(tensor(bool))`, `seq(tensor(complex128))`, `seq(tensor(complex64))`, `seq(tensor(double))`, `seq(tensor(float))`, `seq(tensor(float16))`, `seq(tensor(int16))`, `seq(tensor(int32))`, `seq(tensor(int64))`, `seq(tensor(int8))`, `seq(tensor(string))`, `seq(tensor(uint16))`, `seq(tensor(uint32))`, `seq(tensor(uint64))`, `seq(tensor(uint8))`, `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "input": get_value(input), - } + input_prop_values = create_prop_dict( + input=input, + ) return ( _Identity( _Identity.Attributes(), @@ -1514,9 +1514,9 @@ def if_( """ _else_branch_subgraph: Graph = subgraph((), else_branch) _then_branch_subgraph: Graph = subgraph((), then_branch) - input_prop_values: PropDict = { - "cond": get_value(cond), - } + input_prop_values = create_prop_dict( + cond=cond, + ) return ( _If( _If.Attributes( @@ -1714,11 +1714,11 @@ def loop( + [var.unwrap_type() for var in v_initial], body, ) - input_prop_values: PropDict = { - "M": get_value(M), - "cond": get_value(cond), - "v_initial": get_value(v_initial), - } + input_prop_values = create_prop_dict( + M=M, + cond=cond, + v_initial=v_initial, + ) return ( _Loop( _Loop.Attributes( @@ -1896,12 +1896,12 @@ def pad( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - Tind: `tensor(int32)`, `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "pads": get_value(pads), - "constant_value": get_value(constant_value), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + pads=pads, + constant_value=constant_value, + axes=axes, + ) return ( _Pad( _Pad.Attributes( @@ -1992,16 +1992,16 @@ def qlinear_matmul( - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` - T3: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int8)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "a": get_value(a), - "a_scale": get_value(a_scale), - "a_zero_point": get_value(a_zero_point), - "b": get_value(b), - "b_scale": get_value(b_scale), - "b_zero_point": get_value(b_zero_point), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } + input_prop_values = create_prop_dict( + a=a, + a_scale=a_scale, + a_zero_point=a_zero_point, + b=b, + b_scale=b_scale, + b_zero_point=b_zero_point, + y_scale=y_scale, + y_zero_point=y_zero_point, + ) return ( _QLinearMatMul( _QLinearMatMul.Attributes(), @@ -2128,11 +2128,11 @@ def quantize_linear( - T1: `tensor(bfloat16)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)` - T2: `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int4)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint4)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "x": get_value(x), - "y_scale": get_value(y_scale), - "y_zero_point": get_value(y_zero_point), - } + input_prop_values = create_prop_dict( + x=x, + y_scale=y_scale, + y_zero_point=y_zero_point, + ) return ( _QuantizeLinear( _QuantizeLinear.Attributes( @@ -2203,10 +2203,10 @@ def reshape( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "shape": get_value(shape), - } + input_prop_values = create_prop_dict( + data=data, + shape=shape, + ) return ( _Reshape( _Reshape.Attributes( @@ -2443,9 +2443,9 @@ def scan( ], body, ) - input_prop_values: PropDict = { - "initial_state_and_scan_inputs": get_value(initial_state_and_scan_inputs), - } + input_prop_values = create_prop_dict( + initial_state_and_scan_inputs=initial_state_and_scan_inputs, + ) return ( _Scan( _Scan.Attributes( @@ -2552,9 +2552,9 @@ def shape( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _Shape( _Shape.Attributes( @@ -2597,9 +2597,9 @@ def size( - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` - T1: `tensor(int64)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _Size( _Size.Attributes(), @@ -2647,10 +2647,10 @@ def squeeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _Squeeze( _Squeeze.Attributes(), @@ -2698,9 +2698,9 @@ def transpose( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - } + input_prop_values = create_prop_dict( + data=data, + ) return ( _Transpose( _Transpose.Attributes( @@ -2760,10 +2760,10 @@ def unsqueeze( Type constraints: - T: `tensor(bfloat16)`, `tensor(bool)`, `tensor(complex128)`, `tensor(complex64)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(float8e4m3fn)`, `tensor(float8e4m3fnuz)`, `tensor(float8e5m2)`, `tensor(float8e5m2fnuz)`, `tensor(int16)`, `tensor(int32)`, `tensor(int4)`, `tensor(int64)`, `tensor(int8)`, `tensor(string)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint4)`, `tensor(uint64)`, `tensor(uint8)` """ - input_prop_values: PropDict = { - "data": get_value(data), - "axes": get_value(axes), - } + input_prop_values = create_prop_dict( + data=data, + axes=axes, + ) return ( _Unsqueeze( _Unsqueeze.Attributes(), diff --git a/tests/test_value_propagation.py b/tests/test_value_propagation.py index 19852b9c..9a7d3389 100644 --- a/tests/test_value_propagation.py +++ b/tests/test_value_propagation.py @@ -133,6 +133,13 @@ def test_sequence_append(): ) +def test_variadict_max(): + a = op.const([2, 1, 4]) + b = op.const(3) + c = op.const([0]) + assert_equal_value(op.max([a, b, c]), [3, 3, 4]) + + def test_with_reconstruct(): a, b = arguments( a=_type_system.Tensor(np.int64, ()), diff --git a/tools/templates/construct.jinja2 b/tools/templates/construct.jinja2 index c3c4e7eb..1d1cddd4 100644 --- a/tools/templates/construct.jinja2 +++ b/tools/templates/construct.jinja2 @@ -14,11 +14,11 @@ _{{ attr.name }}_subgraph: Graph = subgraph( ) {% endif %} {% endfor %} -input_prop_values:PropDict = { +input_prop_values = create_prop_dict( {% for param in schema.inputs - %}"{{param.name}}":get_value({{param.name}}), {% + %}{{param.name}}={{param.name}}, {% endfor %} - } + ) return _{{ schema.name }}( _{{ schema.name }}.Attributes( {% for attr in attributes %} diff --git a/tools/templates/preamble.jinja2 b/tools/templates/preamble.jinja2 index 8569252a..b0dd5d63 100644 --- a/tools/templates/preamble.jinja2 +++ b/tools/templates/preamble.jinja2 @@ -14,7 +14,7 @@ from typing import cast as typing_cast import numpy as np import numpy.typing as npt -from spox._var import Var, _VarInfo, result_type, unwrap_vars, get_value +from spox._var import Var, _VarInfo, result_type, unwrap_vars, get_value, create_prop_dict from spox._fields import BaseAttributes, BaseInputs, BaseOutputs from spox._attributes import ( AttrDtype, From 63be89bb8220293a0bc13afeb1e1efb2d245ec77 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Thu, 28 Nov 2024 02:00:28 +0200 Subject: [PATCH 26/29] Comments after code review --- src/spox/_adapt.py | 9 +---- src/spox/_function.py | 2 +- src/spox/_inline.py | 4 +- src/spox/_internal_op.py | 4 +- src/spox/_standard.py | 38 +++++++++---------- src/spox/_var.py | 38 ++----------------- src/spox/opset/ai/onnx/v17.py | 2 +- tests/test_custom_operator.py | 2 +- .../type_inference/compress11.jinja2 | 4 +- 9 files changed, 32 insertions(+), 71 deletions(-) diff --git a/src/spox/_adapt.py b/src/spox/_adapt.py index b6208ae8..8877e40e 100644 --- a/src/spox/_adapt.py +++ b/src/spox/_adapt.py @@ -9,11 +9,10 @@ from ._attributes import AttrGraph from ._inline import _Inline -from ._internal_op import _Initializer, _InternalNode +from ._internal_op import _InternalNode from ._node import Node from ._schemas import SCHEMAS from ._scope import Scope -from ._utils import from_array from ._var import _VarInfo @@ -42,11 +41,6 @@ def adapt_node( ) for key, var_info in node.outputs.get_var_infos().items() ] - initializers = [ - from_array(var_info._op.attrs.get_fields()["value"].value, name) # type: ignore - for name, var_info in node.inputs.get_var_infos().items() - if isinstance(var_info._op, _Initializer) - ] except ValueError: return None @@ -56,7 +50,6 @@ def adapt_node( "spox__singleton_adapter_graph", list(input_info.values()), output_info, - initializers, ), opset_imports=[onnx.helper.make_operatorsetid("", source_version)], ) diff --git a/src/spox/_function.py b/src/spox/_function.py index c4308d9f..8aa47917 100644 --- a/src/spox/_function.py +++ b/src/spox/_function.py @@ -61,7 +61,7 @@ def constructor(self, attrs: dict[str, _attributes.Attr], inputs: BaseVars): f"Function {type(self).__name__} does not implement a constructor." ) - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values) -> dict[str, Type]: from . import _graph func_args_var = _graph.arguments_dict( diff --git a/src/spox/_inline.py b/src/spox/_inline.py index 14dbb2aa..6fa01d71 100644 --- a/src/spox/_inline.py +++ b/src/spox/_inline.py @@ -111,7 +111,7 @@ def opset_req(self) -> set[tuple[str, int]]: ("", INTERNAL_MIN_OPSET) } - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values) -> dict[str, Type]: # First, type check that we match the ModelProto type requirements for i, var in zip(self.graph.input, self.inputs.inputs): if var.type is not None and not ( @@ -128,7 +128,7 @@ def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: } def propagate_values( - self, input_prop_values={} + self, input_prop_values ) -> dict[str, _value_prop.PropValueType]: if any( var_info.type is None or input_prop_values.get(var_info.name) is None diff --git a/src/spox/_internal_op.py b/src/spox/_internal_op.py index c22ca8ae..84fbc2b1 100644 --- a/src/spox/_internal_op.py +++ b/src/spox/_internal_op.py @@ -88,7 +88,7 @@ def post_init(self, **kwargs): if self.attrs.name is not None: self.outputs.arg._rename(self.attrs.name.value) - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values) -> dict[str, Type]: # Output type is based on the value of the type attribute return {"arg": self.attrs.type.value} @@ -161,7 +161,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values) -> dict[str, Type]: return { f"outputs_{i}": arr.type for i, arr in enumerate(self.inputs.inputs) diff --git a/src/spox/_standard.py b/src/spox/_standard.py index d1143f23..0dde0d34 100644 --- a/src/spox/_standard.py +++ b/src/spox/_standard.py @@ -3,7 +3,6 @@ """Module implementing a base for standard ONNX operators, which use the functionality of ONNX node-level inference.""" -from collections.abc import Iterable from typing import TYPE_CHECKING, Callable import onnx @@ -105,24 +104,25 @@ def out_value_info(curr_key, curr_var): # Initializers, passed in to allow partial data propagation # - used so that operators like Reshape are aware of constant shapes # TODO: fix this - initializers_from_array = [ - from_array(prop.value, name) # type: ignore - for name, prop in input_prop_values.items() - if isinstance(prop, PropValue) - and prop.value is not None - and not isinstance(prop.type, Sequence) - ] - - initializers_from_sequence = [ - from_array(prop.value, f"{name}_{i}") # type: ignore - for name, prop_list in input_prop_values.items() - if isinstance(prop_list, list) - for i, prop in enumerate(prop_list) - if prop is not None and not isinstance(prop.value, Iterable) - ] - initializers = initializers_from_array - initializers.extend(initializers_from_sequence) + initializers = [] + + for name, prop in input_prop_values.items(): + if prop is None: + continue + elif not isinstance(prop, PropValue) or prop.value is None: + continue + elif isinstance(prop.type, Sequence): + initializers.extend( + [ + from_array(elem.value, f"{name}_{i}") + for i, elem in enumerate(prop.value) # type: ignore + if elem is not None + ] + ) + else: + initializers.append(from_array(prop.value, name)) # type: ignore + continue # Graph and model graph = onnx.helper.make_graph( @@ -143,7 +143,7 @@ def out_value_info(curr_key, curr_var): ) return model, scope - def infer_output_types_onnx(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types_onnx(self, input_prop_values: PropDict) -> dict[str, Type]: """Execute type & shape inference with ``onnx.shape_inference.infer_node_outputs``.""" # Check that all (specified) inputs have known types, as otherwise we fail if any(var.type is None for var in self.inputs.get_var_infos().values()): diff --git a/src/spox/_var.py b/src/spox/_var.py index a0b1a082..655bff30 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -318,7 +318,7 @@ def wrap_vars(var_info): return Var(var_info) elif isinstance(var_info, dict): return {k: wrap_vars(v) for k, v in var_info.items()} - elif isinstance(var_info, (Sequence, Iterable)): + elif isinstance(var_info, (Iterable)): return [wrap_vars(v) for v in var_info] else: raise ValueError("Unsupported type for wrap_vars") @@ -337,7 +337,7 @@ def unwrap_vars(var: dict[T, Var]) -> dict[T, _VarInfo]: ... # type: ignore[mis @overload -def unwrap_vars(var: Union[Sequence[Var], Iterable[Var]]) -> list[_VarInfo]: ... +def unwrap_vars(var: Union[Iterable[Var]]) -> list[_VarInfo]: ... def unwrap_vars(var): @@ -347,44 +347,12 @@ def unwrap_vars(var): return var._var_info elif isinstance(var, dict): return {k: unwrap_vars(v) for k, v in var.items()} - elif isinstance(var, Sequence) or isinstance(var, Iterable): + elif isinstance(var, Iterable): return [unwrap_vars(v) for v in var] else: raise ValueError("Unsupported type for unwrap_vars") -@overload -def get_value(var: Var) -> Optional[_value_prop.PropValue]: ... - - -@overload -def get_value(var: Optional[Var]) -> Optional[_value_prop.PropValue]: ... - - -@overload -def get_value(var: dict[T, Var]) -> dict[T, Optional[_value_prop.PropValue]]: ... # type: ignore[misc] - - -@overload -def get_value( - var: Union[Sequence[Var], Iterable[Var]], -) -> Union[ - Sequence[Optional[_value_prop.PropValue]], Iterable[Optional[_value_prop.PropValue]] -]: ... - - -def get_value(var): - if var is None: - return None - if isinstance(var, Var): - return var._value - if isinstance(var, Sequence) or isinstance(var, Iterable): - return [v._value if v is not None else None for v in var] - if isinstance(var, dict): - return {k: v._value if v is not None else None for k, v in var.items()} - raise ValueError("Unsupported type for get_value") - - def result_type( *types: Union[_VarInfo, np.generic, int, float], ) -> type[np.generic]: diff --git a/src/spox/opset/ai/onnx/v17.py b/src/spox/opset/ai/onnx/v17.py index e4d57437..036c6f75 100644 --- a/src/spox/opset/ai/onnx/v17.py +++ b/src/spox/opset/ai/onnx/v17.py @@ -500,7 +500,7 @@ class Outputs(BaseOutputs): output: _VarInfo def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]: - self.infer_output_types_onnx() + self.infer_output_types_onnx(input_prop_values) inp, cond = ( self.inputs.input.unwrap_tensor(), self.inputs.condition.unwrap_tensor(), diff --git a/tests/test_custom_operator.py b/tests/test_custom_operator.py index a2eeb4c1..66b369d0 100644 --- a/tests/test_custom_operator.py +++ b/tests/test_custom_operator.py @@ -44,7 +44,7 @@ class Outputs(BaseOutputs): inputs: Inputs outputs: Outputs - def infer_output_types(self, input_prop_values={}) -> dict[str, Type]: + def infer_output_types(self, input_prop_values) -> dict[str, Type]: # This is technically optional, but using an operator without type inference may be inconvenient. if self.inputs.X.type is None: return {} diff --git a/tools/templates/type_inference/compress11.jinja2 b/tools/templates/type_inference/compress11.jinja2 index 4fe26383..a2f9b24f 100644 --- a/tools/templates/type_inference/compress11.jinja2 +++ b/tools/templates/type_inference/compress11.jinja2 @@ -1,4 +1,4 @@ -self.infer_output_types_onnx() +self.infer_output_types_onnx(input_prop_values) inp, cond = self.inputs.input.unwrap_tensor(), self.inputs.condition.unwrap_tensor() if not inp.shape: return {'output': Tensor(inp.dtype, None)} @@ -14,4 +14,4 @@ if self.attrs.axis is not None: shape[axis] = None else: shape = [None] -return {'output': Tensor(inp.dtype, tuple(shape))} \ No newline at end of file +return {'output': Tensor(inp.dtype, tuple(shape))} From 0d5e2c825b7c617d2f46bf5a266f4bc7ff8b9852 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Thu, 28 Nov 2024 02:26:07 +0200 Subject: [PATCH 27/29] Move validation to after propagation --- src/spox/_node.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/spox/_node.py b/src/spox/_node.py index 1e2d9107..bcd01d6f 100644 --- a/src/spox/_node.py +++ b/src/spox/_node.py @@ -85,6 +85,7 @@ class Node(ABC): out_variadic: Optional[int] _traceback: Union[list[str], None] + _validate: bool def __init__( self, @@ -130,13 +131,12 @@ def __init__( else: self.outputs = outputs + # Store validate for when the values are actually propagated + self._validate = validate + # Optionally store debug information about where this node was created self._traceback = traceback.format_stack() if STORE_TRACEBACK else None - # Performs type checking using known flags (like type_members) - # and warns if type inference failed (some types are None). - if validate: - self.validate_types() self.post_init(**kwargs) @property @@ -249,6 +249,12 @@ def get_output_vars( input_prop_values = {} # After typing everything, try to get values for outputs self.inference(infer_types=infer_types, input_prop_values=input_prop_values) + + # Performs type checking using known flags (like type_members) + # and warns if type inference failed (some types are None). + if self._validate: + self.validate_types() + out_values = self.propagate_values(input_prop_values) return self.outputs._propagate_vars(out_values) From d14e300a332330df623c2f61fa1e316e6a33b357 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Thu, 28 Nov 2024 14:04:39 +0200 Subject: [PATCH 28/29] Fix diff --- src/spox/_future.py | 2 +- src/spox/_graph.py | 40 ++++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/spox/_future.py b/src/spox/_future.py index e82a9809..76be31f3 100644 --- a/src/spox/_future.py +++ b/src/spox/_future.py @@ -48,7 +48,7 @@ def value_prop_backend(backend: ValuePropBackend): def initializer(value: npt.ArrayLike, dtype: npt.DTypeLike = None) -> Var: """ - Create a VarInfo with a constant value. + Create a Var with a constant value. Parameters ---------- diff --git a/src/spox/_graph.py b/src/spox/_graph.py index a61dca7a..ceab15f1 100644 --- a/src/spox/_graph.py +++ b/src/spox/_graph.py @@ -43,24 +43,32 @@ def arguments_dict(**kwargs: Optional[Union[Type, np.ndarray]]) -> dict[str, Var for name, info in kwargs.items(): attr_name = AttrString(value=name, name="dummy") if isinstance(info, Type): - result[name] = Argument( - Argument.Attributes( - name=attr_name, - type=AttrType(value=info, name="dummy"), - default=None, - ), - BaseInputs(), - ).get_output_vars()["arg"] + result[name] = ( + Argument( + Argument.Attributes( + name=attr_name, + type=AttrType(value=info, name="dummy"), + default=None, + ), + BaseInputs(), + ) + .get_output_vars() + .arg + ) elif isinstance(info, np.ndarray): ty = Tensor(info.dtype, info.shape) - result[name] = Argument( - Argument.Attributes( - name=attr_name, - type=AttrType(value=ty, name="dummy"), - default=AttrTensor(value=info, name="dummy"), - ), - BaseInputs(), - ).get_output_vars()["arg"] + result[name] = ( + Argument( + Argument.Attributes( + name=attr_name, + type=AttrType(value=ty, name="dummy"), + default=AttrTensor(value=info, name="dummy"), + ), + BaseInputs(), + ) + .get_output_vars() + .arg + ) else: raise TypeError(f"Cannot construct argument from {type(info)}.") return result From e33b00eccaeb7983382696d0090c11ed99669c71 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Thu, 28 Nov 2024 19:01:37 +0200 Subject: [PATCH 29/29] Fix diffs --- src/spox/_graph.py | 14 +++++++++----- src/spox/_public.py | 2 +- src/spox/_scope.py | 2 +- src/spox/_var.py | 24 ++++++++++-------------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/spox/_graph.py b/src/spox/_graph.py index ceab15f1..76bae2a9 100644 --- a/src/spox/_graph.py +++ b/src/spox/_graph.py @@ -118,10 +118,14 @@ def initializer(arr: np.ndarray) -> Var: ------- Var which is always equal to the respective value provided by `arr`. """ - return _Initializer( - _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), - BaseInputs(), - ).get_output_vars()["arg"] + return ( + _Initializer( + _Initializer.Attributes(value=AttrTensor(value=arr, name="dummy")), + BaseInputs(), + ) + .get_output_vars() + .arg + ) @dataclass(frozen=True, eq=False) @@ -447,7 +451,7 @@ def results(**kwargs: Var) -> Graph: Parameters ---------- kwargs - Var to be marked as results in the created Graph. + Vars to be marked as results in the created Graph. Returns ------- Graph diff --git a/src/spox/_public.py b/src/spox/_public.py index 7911c474..cc168f14 100644 --- a/src/spox/_public.py +++ b/src/spox/_public.py @@ -78,7 +78,7 @@ def build( Model inputs. Keys are names, values must be results of ``argument``. outputs - Model outputs. Keys are names, values may be any ``VarInfo``. + Model outputs. Keys are names, values may be any ``Var``. Building will resolve what nodes were used in the construction of output variables. drop_unused_inputs diff --git a/src/spox/_scope.py b/src/spox/_scope.py index fde170b2..a8179158 100644 --- a/src/spox/_scope.py +++ b/src/spox/_scope.py @@ -18,7 +18,7 @@ class ScopeError(Exception): class ScopeSpace(Generic[H]): """ - Represents the namespace of a scope for some type H, like Node or VarInfo. + Represents the namespace of a scope for some type H, like ``Node`` or ``_VarInfo``. Methods (and operators) on the namespace work both ways: both with names (str) and the named type (H). So ``__getitem__`` (``ScopeSpace[item]``) may be used for both the name of an object and the object of a name. diff --git a/src/spox/_var.py b/src/spox/_var.py index 655bff30..e5756712 100644 --- a/src/spox/_var.py +++ b/src/spox/_var.py @@ -120,12 +120,12 @@ class Var: The ``type`` field is inferred and checked by operators. It may be ``None`` if type inference failed, in which case it is unknown and should pass all type checks. - However, untyped ``VarInfo`` objects may not be used in some contexts. + However, untyped ``Var`` objects may not be used in some contexts. Keep in mind that the types themselves may have some information missing. For instance, tensors allow missing rank and shape information. There is an implicit value propagation mechanism, powered by the ONNX reference implementation. - Values may be propagated if a ``VarInfo`` always has a known and constant value at runtime. + Values may be propagated if a ``Var`` always has a known and constant value at runtime. This is used for type & shape inference. For instance, Reshape to a constant shape can have the shape inferred. ``Var`` should be treated as strictly immutable. @@ -134,7 +134,7 @@ class Var: Protected fields are to be treated as internal. Useful data is also shown by the string representation, but it should be treated as debug information. - Should not be constructed directly - the main source of ``VarInfo`` objects are operator constructors. + Should not be constructed directly - the main source of ``Var`` objects are operator constructors. """ _var_info: _VarInfo @@ -149,21 +149,19 @@ def __init__( ): """The initializer of ``Var`` is protected. Use operator constructors to construct them instead.""" if value is not None and not isinstance(value, _value_prop.PropValue): - raise TypeError( - "The propagated value field of a VarInfo must be a PropValue." - ) + raise TypeError("The propagated value field of a Var must be a PropValue.") if value is not None and value.type != var_info.type: raise ValueError( - f"The propagated value type ({value.type}) and actual VarInfo type ({var_info.type}) must be the same." + f"The propagated value type ({value.type}) and actual Var type ({var_info.type}) must be the same." ) self._var_info = var_info self._value = value def _get_value(self) -> "_value_prop.ORTValue": - """Get the propagated value in this VarInfo and convert it to the ORT format. Raises if value is missing.""" + """Get the propagated value in this Var and convert it to the ORT format. Raises if value is missing.""" if self._value is None: - raise ValueError("No propagated value associated with this VarInfo.") + raise ValueError("No propagated value associated with this Var.") return self._value.to_ort_value() def __repr__(self) -> str: @@ -184,17 +182,15 @@ def unwrap_type(self) -> _type_system.Type: Returns ------- _type_system.Type - The type of the VarInfo. + The type of the Var. Raises ------ TypeError - If ``type is None`` (the type of this ``VarInfo`` is unknown). + If ``type is None`` (the type of this ``Var`` is unknown). """ if self.type is None: - raise TypeError( - "Cannot unwrap requested type for VarInfo, as it is unknown." - ) + raise TypeError("Cannot unwrap requested type for Var, as it is unknown.") return self.type def unwrap_tensor(self) -> _type_system.Tensor: