Binary Operations

As you may have seen in the tutorial, MaskedTensor also has binary operations implemented with the caveat that the masks in two masked tensors must match or else an error will be raised. As noted in the error, if you need support for a particular operator or have proposed semantics for how they should be behave instead, please open an issue on Github. For now, we have decided to go with the most conservative implementation to ensure that users know exactly what is going on and are being intentional about their decisions with masked semantics.

The available binary operators are:

add

Adds other, scaled by alpha, to input.

atan2

Element-wise arctangent of \(\text{input}_{i} / \text{other}_{i}\) with consideration of the quadrant.

arctan2

Alias for torch.atan2().

bitwise_and

Computes the bitwise AND of input and other.

bitwise_or

Computes the bitwise OR of input and other.

bitwise_xor

Computes the bitwise XOR of input and other.

bitwise_left_shift

Computes the left arithmetic shift of input by other bits.

bitwise_right_shift

Computes the right arithmetic shift of input by other bits.

div

Divides each element of the input input by the corresponding element of other.

divide

Alias for torch.div().

floor_divide

fmod

Applies C++'s std::fmod entrywise.

logaddexp

Logarithm of the sum of exponentiations of the inputs.

logaddexp2

Logarithm of the sum of exponentiations of the inputs in base-2.

mul

Multiplies input by other.

multiply

Alias for torch.mul().

nextafter

Return the next floating-point value after input towards other, elementwise.

remainder

Computes Python's modulus operation entrywise.

sub

Subtracts other, scaled by alpha, from input.

subtract

Alias for torch.sub().

true_divide

Alias for torch.div() with rounding_mode=None.

eq

Computes element-wise equality

ne

Computes \(\text{input} \neq \text{other}\) element-wise.

le

Computes \(\text{input} \leq \text{other}\) element-wise.

ge

Computes \(\text{input} \geq \text{other}\) element-wise.

greater

Alias for torch.gt().

greater_equal

Alias for torch.ge().

gt

Computes \(\text{input} > \text{other}\) element-wise.

less_equal

Alias for torch.le().

lt

Computes \(\text{input} < \text{other}\) element-wise.

less

Alias for torch.lt().

maximum

Computes the element-wise maximum of input and other.

minimum

Computes the element-wise minimum of input and other.

fmax

Computes the element-wise maximum of input and other.

fmin

Computes the element-wise minimum of input and other.

not_equal

Alias for torch.ne().

The available inplace binary operators are all of the above except:

logaddexp

Logarithm of the sum of exponentiations of the inputs.

logaddexp2

Logarithm of the sum of exponentiations of the inputs in base-2.

equal

True if two tensors have the same size and elements, False otherwise.

fmin

Computes the element-wise minimum of input and other.

minimum

Computes the element-wise minimum of input and other.

fmax

Computes the element-wise maximum of input and other.

As always, if you have any feature requests, please file an issue on Github.