pypto.bitwise_xor

Applicable Products

  • Ascend 950PR/Ascend 950DT: Supported
  • Atlas A3 training products/Atlas A3 inference products: Supported
  • Atlas A2 training products/Atlas A2 inference products: Supported

Description

Performs a bitwise XOR operation on input and other element by element. The calculation formula is as follows:

resi=inputi⊕otherires_i = input_i \oplus other_i

Prototype

bitwise_xor(input: Tensor, other: Union[Tensor, int]) -> Tensor

Parameters

ParameterInput/OutputDescription
inputInputSource operand.
Supported type: Tensor. Supported data types vary by model. For details, see Constraints.
Empty tensors are not supported. The shape supports only 1 to 4 dimensions. Broadcasting to the same shape along a single dimension is supported. The shape size must not exceed 2147483647 (INT32_MAX).
otherInputSource operand.
Supported types: int and Tensor. Supported Tensor data types vary by model. For details, see Constraints.
Empty tensors are not supported. The shape supports only 1 to 4 dimensions. Broadcasting to the same shape along a single dimension is supported. The shape size must not exceed 2147483647 (INT32_MAX).

Return Value

Returns an output tensor with the same data type as input and other, and with a shape equal to the broadcast size of input and other.

Constraints

  1. When both input and other are tensors, their data types must be the same.
  2. Due to temporary memory usage, the TileShape size has additional constraints. Assuming the TileShape is [a,b,c,d], then a*b*c*d*sizeof(input) + a*b*c*d*sizeof(other) + a*b*c*d*sizeof(input) < UB.
  3. Tensor data type description:
    • Ascend 950PR/Ascend 950DT: DT_INT16, DT_UINT16, DT_INT8, and DT_UINT8, DT_INT32.
    • Atlas A3 training products/Atlas A3 inference products: DT_INT16, DT_UINT16, DT_INT8, and DT_UINT8.
    • Atlas A2 training products/Atlas A2 inference products: DT_INT16, DT_UINT16, DT_INT8, and DT_UINT8.
  4. Tensor inputs do not support the TileOpFormat.TILEOP_NZ format.

Examples

TileShape Setting Example

Before calling this operation API, set the TileShape through set_vec_tile_shapes.

The TileShape must have the same number of dimensions as the output.

In a non-broadcast scenario, if the input shape is [m, n], other is [m, n], the output is [m, n], and the TileShape is set to [m1, n1], then m1 and n1 are used to tile the m and n axes, respectively.

In a broadcast scenario, if the input shape is [m, n], other is [m, 1], the output is [m, n], and the TileShape is set to [m1, n1], then m1 and n1 are used to tile the m and n axes, respectively.

pypto.set_vec_tile_shapes(4, 16)

API Call Example

a = pypto.tensor([2], pypto.DT_INT16)
b = pypto.tensor([2], pypto.DT_INT16)
out = pypto.bitwise_xor(a, b)

The results are as follows:

Input data a:  [2, 5]
Input data b: [1, 7]
Output data out: [3, 2]