# Xor#

## Xor - 7#

Version

• name: Xor (GitHub)

• domain: main

• since_version: 7

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 7.

Summary

Returns the tensor resulted from performing the xor logical operation elementwise on the input tensors A and B (with Numpy-style broadcasting support).

Inputs

• A (heterogeneous) - T: First input operand for the logical operator.

• B (heterogeneous) - T: Second input operand for the logical operator.

Outputs

• C (heterogeneous) - T1: Result tensor.

Type Constraints

• T in ( tensor(bool) ): Constrain input to boolean tensor.

• T1 in ( tensor(bool) ): Constrain output to boolean tensor.

Examples

default

node = onnx.helper.make_node(
"Xor",
inputs=["x", "y"],
outputs=["xor"],
)

# 2d
x = (np.random.randn(3, 4) > 0).astype(bool)
y = (np.random.randn(3, 4) > 0).astype(bool)
z = np.logical_xor(x, y)
expect(node, inputs=[x, y], outputs=[z], name="test_xor2d")

# 3d
x = (np.random.randn(3, 4, 5) > 0).astype(bool)
y = (np.random.randn(3, 4, 5) > 0).astype(bool)
z = np.logical_xor(x, y)
expect(node, inputs=[x, y], outputs=[z], name="test_xor3d")

# 4d
x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)
y = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)
z = np.logical_xor(x, y)
expect(node, inputs=[x, y], outputs=[z], name="test_xor4d")

node = onnx.helper.make_node(
"Xor",
inputs=["x", "y"],
outputs=["xor"],
)

# 3d vs 1d
x = (np.random.randn(3, 4, 5) > 0).astype(bool)
y = (np.random.randn(5) > 0).astype(bool)
z = np.logical_xor(x, y)
expect(node, inputs=[x, y], outputs=[z], name="test_xor_bcast3v1d")

# 3d vs 2d
x = (np.random.randn(3, 4, 5) > 0).astype(bool)
y = (np.random.randn(4, 5) > 0).astype(bool)
z = np.logical_xor(x, y)
expect(node, inputs=[x, y], outputs=[z], name="test_xor_bcast3v2d")

# 4d vs 2d
x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)
y = (np.random.randn(5, 6) > 0).astype(bool)
z = np.logical_xor(x, y)
expect(node, inputs=[x, y], outputs=[z], name="test_xor_bcast4v2d")

# 4d vs 3d
x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)
y = (np.random.randn(4, 5, 6) > 0).astype(bool)
z = np.logical_xor(x, y)
expect(node, inputs=[x, y], outputs=[z], name="test_xor_bcast4v3d")

# 4d vs 4d
x = (np.random.randn(1, 4, 1, 6) > 0).astype(bool)
y = (np.random.randn(3, 1, 5, 6) > 0).astype(bool)
z = np.logical_xor(x, y)
expect(node, inputs=[x, y], outputs=[z], name="test_xor_bcast4v4d")

Differences

## Xor - 1#

Version

• name: Xor (GitHub)

• domain: main

• since_version: 1

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 1.

Summary

Returns the tensor resulted from performing the xor logical operation elementwise on the input tensors A and B.

If broadcasting is enabled, the right-hand-side argument will be broadcasted to match the shape of left-hand-side argument. See the doc of Add for a detailed description of the broadcasting rules.

Attributes

• axis: If set, defines the broadcast dimensions.

Inputs

• A (heterogeneous) - T: Left input tensor for the logical operator.

• B (heterogeneous) - T: Right input tensor for the logical operator.

Outputs

• C (heterogeneous) - T1: Result tensor.

Type Constraints

• T in ( tensor(bool) ): Constrain input to boolean tensor.

• T1 in ( tensor(bool) ): Constrain output to boolean tensor.