:nosearch: .. _op_ai_onnx_Optional-15: Optional - version 15 ===================== This page documents version **15** of operator **Optional**. See :doc:`Optional` for the latest version (since version 28). - **Domain**: ``ai.onnx`` - **Since version**: 15 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. **Inputs** - **input** (*V*): The input element. **Outputs** - **output** (*O*): The optional output enclosing the input element. **Type Constraints** - **V**: Constrain input type to all tensor and sequence types. Allowed types: 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**: Constrain output type to all optional tensor or optional sequence types. Allowed types: 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)). Examples -------- **test_cc_optional** .. code-block:: text Node: Optional(input) -> (output) Attributes: type = .. code-block:: text Inputs: input: shape=(2, 3), dtype=float32 [[-1. , 0. , 1.5 ], [-2.25, 3.5 , -4.75]] Outputs: output: shape=(2, 3), dtype=float32 [[-1. , 0. , 1.5 ], [-2.25, 3.5 , -4.75]] **test_cc_optional_get_element_optional_sequence** .. code-block:: text Node: Optional(seq) -> (opt_seq) Attributes: type = .. code-block:: text Inputs: seq: shape=(4,), dtype=int32 [1, 2, 3, 4] Outputs: opt_seq: sequence(len=1), element_shape=(4,), element_dtype=int32 [ [0] [1, 2, 3, 4] ] **test_cc_optional_get_element_optional_tensor** .. code-block:: text Node: Optional(input) -> (opt_value) Attributes: type = .. code-block:: text Inputs: input: shape=(2, 3), dtype=float32 [[-1. , 0. , 1.5 ], [-2.25, 3.5 , -4.75]] Outputs: opt_value: shape=(2, 3), dtype=float32 [[-1. , 0. , 1.5 ], [-2.25, 3.5 , -4.75]] **test_cc_optional_has_element_optional_input** .. code-block:: text Node: Optional(input) -> (opt_value) Attributes: type = .. code-block:: text Inputs: input: shape=(2, 3), dtype=float32 [[-1. , 0. , 1.5 ], [-2.25, 3.5 , -4.75]] Outputs: opt_value: shape=(), dtype=bool True