.. _l-onnx-doc-OptionalHasElement: ================== OptionalHasElement ================== .. contents:: :local: .. _l-onnx-op-optionalhaselement-18: OptionalHasElement - 18 ======================= **Version** * **name**: `OptionalHasElement (GitHub) `_ * **domain**: **main** * **since_version**: **18** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 18**. **Summary** 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. **Inputs** Between 0 and 1 inputs. * **input** (optional, heterogeneous) - **O**: The optional input. **Outputs** * **output** (heterogeneous) - **B**: A scalar boolean tensor. If true, it indicates that optional-type input contains an element. Otherwise, it is empty. **Type Constraints** * **O** in ( 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) ): Constrain input type to optional tensor and optional sequence types. * **B** in ( tensor(bool) ): Constrain output to a boolean tensor. **Examples** **default** :: optional = np.array([1, 2, 3, 4]).astype(np.float32) tensor_type_proto = onnx.helper.make_tensor_type_proto( elem_type=onnx.TensorProto.FLOAT, shape=[ 4, ], ) optional_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto) # OptionalHasElement takes a tensor or optional as input for input_type_protos in [tensor_type_proto, optional_type_proto]: node = onnx.helper.make_node( "OptionalHasElement", inputs=["optional_input"], outputs=["output"] ) output = optional_has_element_reference_implementation(optional) test_name = "test_optional_has_element_" + ( "optional_input" if input_type_protos == optional_type_proto else "tensor_input" ) expect( node, inputs=[optional], outputs=[output], input_type_protos=[optional_type_proto], name=test_name, ) **_empty** :: optional = None tensor_type_proto = onnx.helper.make_tensor_type_proto( elem_type=onnx.TensorProto.INT32, shape=[] ) optional_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto) # OptionalHasElement takes a tensor or optional as input for input_type_proto in [tensor_type_proto, optional_type_proto]: input_name_options = { "empty": "optional_input", "empty_no_input_name": "", "empty_no_input": None, } for test_name_surfix, input_name in input_name_options.items(): if input_type_proto == tensor_type_proto and input_name: # the input tensor cannot be empty if input name is provided. continue node = onnx.helper.make_node( "OptionalHasElement", inputs=[] if input_name is None else [input_name], outputs=["output"], ) output = optional_has_element_reference_implementation(optional) test_name = ( "test_optional_has_element_" + test_name_surfix + ( "_optional_input" if input_type_proto == optional_type_proto else "_tensor_input" ) ) expect( node, inputs=[optional] if input_name else [], outputs=[output], input_type_protos=[input_type_proto] if input_name else [], name=test_name, ) **Differences** .. raw:: html
0Returns true if (1) the input is an optional-type and contains an element,
01Returns true if the optional-type input contains an element. If it is an empty optional-type, this op returns false.or, (2) the input is a tensor or sequence type.
2If the input is not provided or is an empty optional-type, this op returns false.
13
24**Inputs****Inputs**
35
6Between 0 and 1 inputs.
7
48* **input** (heterogeneous) - **O**:* **input** (optional, heterogeneous) - **O**:
59 The optional input. The optional input.
610
711**Outputs****Outputs**
812
913* **output** (heterogeneous) - **B**:* **output** (heterogeneous) - **B**:
1014 A scalar boolean tensor. If true, it indicates that optional-type A scalar boolean tensor. If true, it indicates that optional-type
1115 input contains an element. Otherwise, it is empty. input contains an element. Otherwise, it is empty.
1216
1317**Type Constraints****Type Constraints**
1418
1519* **O** in (* **O** in (
1620 optional(seq(tensor(bool))), optional(seq(tensor(bool))),
1721 optional(seq(tensor(complex128))), optional(seq(tensor(complex128))),
1822 optional(seq(tensor(complex64))), optional(seq(tensor(complex64))),
1923 optional(seq(tensor(double))), optional(seq(tensor(double))),
2024 optional(seq(tensor(float))), optional(seq(tensor(float))),
2125 optional(seq(tensor(float16))), optional(seq(tensor(float16))),
2226 optional(seq(tensor(int16))), optional(seq(tensor(int16))),
2327 optional(seq(tensor(int32))), optional(seq(tensor(int32))),
2428 optional(seq(tensor(int64))), optional(seq(tensor(int64))),
2529 optional(seq(tensor(int8))), optional(seq(tensor(int8))),
2630 optional(seq(tensor(string))), optional(seq(tensor(string))),
2731 optional(seq(tensor(uint16))), optional(seq(tensor(uint16))),
2832 optional(seq(tensor(uint32))), optional(seq(tensor(uint32))),
2933 optional(seq(tensor(uint64))), optional(seq(tensor(uint64))),
3034 optional(seq(tensor(uint8))), optional(seq(tensor(uint8))),
3135 optional(tensor(bool)), optional(tensor(bool)),
3236 optional(tensor(complex128)), optional(tensor(complex128)),
3337 optional(tensor(complex64)), optional(tensor(complex64)),
3438 optional(tensor(double)), optional(tensor(double)),
3539 optional(tensor(float)), optional(tensor(float)),
3640 optional(tensor(float16)), optional(tensor(float16)),
3741 optional(tensor(int16)), optional(tensor(int16)),
3842 optional(tensor(int32)), optional(tensor(int32)),
3943 optional(tensor(int64)), optional(tensor(int64)),
4044 optional(tensor(int8)), optional(tensor(int8)),
4145 optional(tensor(string)), optional(tensor(string)),
4246 optional(tensor(uint16)), optional(tensor(uint16)),
4347 optional(tensor(uint32)), optional(tensor(uint32)),
4448 optional(tensor(uint64)), optional(tensor(uint64)),
4549 optional(tensor(uint8)) optional(tensor(uint8)),
50 seq(tensor(bool)),
51 seq(tensor(complex128)),
52 seq(tensor(complex64)),
53 seq(tensor(double)),
54 seq(tensor(float)),
55 seq(tensor(float16)),
56 seq(tensor(int16)),
57 seq(tensor(int32)),
58 seq(tensor(int64)),
59 seq(tensor(int8)),
60 seq(tensor(string)),
61 seq(tensor(uint16)),
62 seq(tensor(uint32)),
63 seq(tensor(uint64)),
64 seq(tensor(uint8)),
65 tensor(bool),
66 tensor(complex128),
67 tensor(complex64),
68 tensor(double),
69 tensor(float),
70 tensor(float16),
71 tensor(int16),
72 tensor(int32),
73 tensor(int64),
74 tensor(int8),
75 tensor(string),
76 tensor(uint16),
77 tensor(uint32),
78 tensor(uint64),
79 tensor(uint8)
4680 ): ):
4781 Constrain input type to optional tensor and optional sequence types. Constrain input type to optional tensor and optional sequence types.
4882* **B** in (* **B** in (
4983 tensor(bool) tensor(bool)
5084 ): ):
5185 Constrain output to a boolean tensor. Constrain output to a boolean tensor.
.. _l-onnx-op-optionalhaselement-15: OptionalHasElement - 15 ======================= **Version** * **name**: `OptionalHasElement (GitHub) `_ * **domain**: **main** * **since_version**: **15** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 15**. **Summary** Returns true if the optional-type input contains an element. If it is an empty optional-type, this op returns false. **Inputs** * **input** (heterogeneous) - **O**: The optional input. **Outputs** * **output** (heterogeneous) - **B**: A scalar boolean tensor. If true, it indicates that optional-type input contains an element. Otherwise, it is empty. **Type Constraints** * **O** in ( 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)) ): Constrain input type to optional tensor and optional sequence types. * **B** in ( tensor(bool) ): Constrain output to a boolean tensor.