OptionalGetElement#

OptionalGetElement - 18#

Version

  • name: OptionalGetElement (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

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.

Inputs

  • input (heterogeneous) - O: The optional input.

Outputs

  • output (heterogeneous) - V: Output element in the optional input.

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.

  • V in ( 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 output type to all tensor or sequence types.

Examples

_get_element_tensor

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)

node = onnx.helper.make_node(
    "OptionalGetElement", inputs=["optional_input"], outputs=["output"]
)
output = optional_get_element_reference_implementation(optional)
expect(
    node,
    inputs=[optional],
    outputs=[output],
    input_type_protos=[optional_type_proto],
    name="test_optional_get_element_optional_tensor",
)
expect(
    node,
    inputs=[optional],
    outputs=[output],
    input_type_protos=[tensor_type_proto],
    name="test_optional_get_element_tensor",
)

_get_element_sequence

optional = [np.array([1, 2, 3, 4]).astype(np.int32)]
tensor_type_proto = onnx.helper.make_tensor_type_proto(
    elem_type=onnx.TensorProto.INT32,
    shape=[
        4,
    ],
)
seq_type_proto = onnx.helper.make_sequence_type_proto(tensor_type_proto)
optional_type_proto = onnx.helper.make_optional_type_proto(seq_type_proto)

node = onnx.helper.make_node(
    "OptionalGetElement", inputs=["optional_input"], outputs=["output"]
)
output = optional_get_element_reference_implementation(optional)
expect(
    node,
    inputs=[optional],
    outputs=[output],
    input_type_protos=[optional_type_proto],
    name="test_optional_get_element_optional_sequence",
)
expect(
    node,
    inputs=[optional],
    outputs=[output],
    input_type_protos=[seq_type_proto],
    name="test_optional_get_element_sequence",
)

Differences

0If the input is a tensor or sequence type, it returns the input.
01Outputs the element in the optional-type input. It is an error if the input value does not have an elementIf the input is an optional type, it outputs the element in the input.
12and the behavior is undefined in this case.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.
23
34**Inputs****Inputs**
45
56* **input** (heterogeneous) - **O**:* **input** (heterogeneous) - **O**:
67 The optional input. The optional input.
78
89**Outputs****Outputs**
910
1011* **output** (heterogeneous) - **V**:* **output** (heterogeneous) - **V**:
1112 Output element in the optional input. Output element in the optional input.
1213
1314**Type Constraints****Type Constraints**
1415
1516* **O** in (* **O** in (
1617 optional(seq(tensor(bool))), optional(seq(tensor(bool))),
1718 optional(seq(tensor(complex128))), optional(seq(tensor(complex128))),
1819 optional(seq(tensor(complex64))), optional(seq(tensor(complex64))),
1920 optional(seq(tensor(double))), optional(seq(tensor(double))),
2021 optional(seq(tensor(float))), optional(seq(tensor(float))),
2122 optional(seq(tensor(float16))), optional(seq(tensor(float16))),
2223 optional(seq(tensor(int16))), optional(seq(tensor(int16))),
2324 optional(seq(tensor(int32))), optional(seq(tensor(int32))),
2425 optional(seq(tensor(int64))), optional(seq(tensor(int64))),
2526 optional(seq(tensor(int8))), optional(seq(tensor(int8))),
2627 optional(seq(tensor(string))), optional(seq(tensor(string))),
2728 optional(seq(tensor(uint16))), optional(seq(tensor(uint16))),
2829 optional(seq(tensor(uint32))), optional(seq(tensor(uint32))),
2930 optional(seq(tensor(uint64))), optional(seq(tensor(uint64))),
3031 optional(seq(tensor(uint8))), optional(seq(tensor(uint8))),
3132 optional(tensor(bool)), optional(tensor(bool)),
3233 optional(tensor(complex128)), optional(tensor(complex128)),
3334 optional(tensor(complex64)), optional(tensor(complex64)),
3435 optional(tensor(double)), optional(tensor(double)),
3536 optional(tensor(float)), optional(tensor(float)),
3637 optional(tensor(float16)), optional(tensor(float16)),
3738 optional(tensor(int16)), optional(tensor(int16)),
3839 optional(tensor(int32)), optional(tensor(int32)),
3940 optional(tensor(int64)), optional(tensor(int64)),
4041 optional(tensor(int8)), optional(tensor(int8)),
4142 optional(tensor(string)), optional(tensor(string)),
4243 optional(tensor(uint16)), optional(tensor(uint16)),
4344 optional(tensor(uint32)), optional(tensor(uint32)),
4445 optional(tensor(uint64)), optional(tensor(uint64)),
4546 optional(tensor(uint8)) optional(tensor(uint8)),
47 seq(tensor(bool)),
48 seq(tensor(complex128)),
49 seq(tensor(complex64)),
50 seq(tensor(double)),
51 seq(tensor(float)),
52 seq(tensor(float16)),
53 seq(tensor(int16)),
54 seq(tensor(int32)),
55 seq(tensor(int64)),
56 seq(tensor(int8)),
57 seq(tensor(string)),
58 seq(tensor(uint16)),
59 seq(tensor(uint32)),
60 seq(tensor(uint64)),
61 seq(tensor(uint8)),
62 tensor(bool),
63 tensor(complex128),
64 tensor(complex64),
65 tensor(double),
66 tensor(float),
67 tensor(float16),
68 tensor(int16),
69 tensor(int32),
70 tensor(int64),
71 tensor(int8),
72 tensor(string),
73 tensor(uint16),
74 tensor(uint32),
75 tensor(uint64),
76 tensor(uint8)
4677 ): ):
4778 Constrain input type to optional tensor and optional sequence types. Constrain input type to optional tensor and optional sequence types.
4879* **V** in (* **V** in (
4980 seq(tensor(bool)), seq(tensor(bool)),
5081 seq(tensor(complex128)), seq(tensor(complex128)),
5182 seq(tensor(complex64)), seq(tensor(complex64)),
5283 seq(tensor(double)), seq(tensor(double)),
5384 seq(tensor(float)), seq(tensor(float)),
5485 seq(tensor(float16)), seq(tensor(float16)),
5586 seq(tensor(int16)), seq(tensor(int16)),
5687 seq(tensor(int32)), seq(tensor(int32)),
5788 seq(tensor(int64)), seq(tensor(int64)),
5889 seq(tensor(int8)), seq(tensor(int8)),
5990 seq(tensor(string)), seq(tensor(string)),
6091 seq(tensor(uint16)), seq(tensor(uint16)),
6192 seq(tensor(uint32)), seq(tensor(uint32)),
6293 seq(tensor(uint64)), seq(tensor(uint64)),
6394 seq(tensor(uint8)), seq(tensor(uint8)),
6495 tensor(bool), tensor(bool),
6596 tensor(complex128), tensor(complex128),
6697 tensor(complex64), tensor(complex64),
6798 tensor(double), tensor(double),
6899 tensor(float), tensor(float),
69100 tensor(float16), tensor(float16),
70101 tensor(int16), tensor(int16),
71102 tensor(int32), tensor(int32),
72103 tensor(int64), tensor(int64),
73104 tensor(int8), tensor(int8),
74105 tensor(string), tensor(string),
75106 tensor(uint16), tensor(uint16),
76107 tensor(uint32), tensor(uint32),
77108 tensor(uint64), tensor(uint64),
78109 tensor(uint8) tensor(uint8)
79110 ): ):
80111 Constrain output type to all tensor or sequence types. Constrain output type to all tensor or sequence types.

OptionalGetElement - 15#

Version

  • name: OptionalGetElement (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

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.

Inputs

  • input (heterogeneous) - O: The optional input.

Outputs

  • output (heterogeneous) - V: Output element in the optional input.

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.

  • V in ( 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 output type to all tensor or sequence types.