# tensorplay.masked API Source: https://www.tensorplay.cn/docs/api/tensorplay.masked.html ## Functions 22 [#](#api-tensorplay.masked.amax) ### amax function[Full reference ↗](/docs/generated/tensorplay.masked.amax.html) ```python tensorplay.masked.amax(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns maximum of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of maximum operation, which is used to start the reduction, depends on input dtype. For instance, for float32, uint8, and int32 dtypes, the identity values are tensor(-inf), tensor(Tensor(shape=tensorplay.Size(), dtype=UInt8, device=cpu), and tensor(-2147483648, dtype=Int32), respectively. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in maximum computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of maximum operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> input tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.amax(input, 1, mask=mask) tensor([-1, -9223372036854775808], dtype=Int64) ``` [#](#api-tensorplay.masked.amin) ### amin function[Full reference ↗](/docs/generated/tensorplay.masked.amin.html) ```python tensorplay.masked.amin(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns minimum of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of minimum operation, which is used to start the reduction, depends on input dtype. For instance, for float32, uint8, and int32 dtypes, the identity values are tensor(inf), tensor(Tensor(shape=tensorplay.Size(), dtype=UInt8, device=cpu), and tensor(2147483647, dtype=Int32), respectively. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in minimum computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of minimum operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> input tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.amin(input, 1, mask=mask) tensor([-3, -9223372036854775808], dtype=Int64) ``` [#](#api-tensorplay.masked.argmax) ### argmax function[Full reference ↗](/docs/generated/tensorplay.masked.argmax.html) ```python tensorplay.masked.argmax(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns argmax of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of argmax operation, which is used to start the reduction, depends on input dtype. For instance, for float32, uint8, and int32 dtypes, the identity values are tensor(-inf), tensor(Tensor(shape=tensorplay.Size(), dtype=UInt8, device=cpu), and tensor(-2147483648, dtype=Int32), respectively. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in argmax computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of argmax operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> input tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.argmax(input, 1, mask=mask) tensor([2, 0], dtype=Int64) ``` [#](#api-tensorplay.masked.argmin) ### argmin function[Full reference ↗](/docs/generated/tensorplay.masked.argmin.html) ```python tensorplay.masked.argmin(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns argmin of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of argmin operation, which is used to start the reduction, depends on input dtype. For instance, for float32, uint8, and int32 dtypes, the identity values are tensor(inf), tensor(Tensor(shape=tensorplay.Size(), dtype=UInt8, device=cpu), and tensor(2147483647, dtype=Int32), respectively. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in argmin computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of argmin operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> input tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.argmin(input, 1, mask=mask) tensor([0, 0], dtype=Int64) ``` [#](#api-tensorplay.masked.as_masked_tensor) ### as_masked_tensor function[Full reference ↗](/docs/generated/tensorplay.masked.as_masked_tensor.html) ```python tensorplay.masked.as_masked_tensor(data: object, mask: object) → MaskedTensor ``` [#](#api-tensorplay.masked.cumprod) ### cumprod function[Full reference ↗](/docs/generated/tensorplay.masked.cumprod.html) ```python tensorplay.masked.cumprod(input, dim, *, dtype=None, mask=None) → Tensor ``` Returns cumulative_prod of all the slices in the input tensor along dim while the input elements are masked out according to the boolean tensor mask. Let x be a sequence of unmasked elements of one-dimensional slice of the input tensor. Cumsum of i-th element in x is defined as prod(x[:i]). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in cumulative_prod computation, otherwise the element is ignored. The values of masked-out elements of the output tensor have undefined value: it may or may not be set to zero or nan; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the cumulative_prod output tensor can be computed as tensorplay.broadcast_to(mask, input.shape). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.cumprod(input, 1, mask=mask) tensor([[-3., -3., 3.], [1., 1., 1.]]) ``` [#](#api-tensorplay.masked.cumsum) ### cumsum function[Full reference ↗](/docs/generated/tensorplay.masked.cumsum.html) ```python tensorplay.masked.cumsum(input, dim, *, dtype=None, mask=None) → Tensor ``` Returns cumulative_sum of all the slices in the input tensor along dim while the input elements are masked out according to the boolean tensor mask. Let x be a sequence of unmasked elements of one-dimensional slice of the input tensor. Cumsum of i-th element in x is defined as sum(x[:i]). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in cumulative_sum computation, otherwise the element is ignored. The values of masked-out elements of the output tensor have undefined value: it may or may not be set to zero or nan; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the cumulative_sum output tensor can be computed as tensorplay.broadcast_to(mask, input.shape). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.cumsum(input, 1, mask=mask) tensor([[-3., -3., -4.], [0., 0., 0.]]) ``` [#](#api-tensorplay.masked.is_masked_tensor) ### is_masked_tensor function[Full reference ↗](/docs/generated/tensorplay.masked.is_masked_tensor.html) ```python tensorplay.masked.is_masked_tensor(obj: Any, /) → bool ``` Return True if the input is a MaskedTensor, else False. Parameters: obj – any input Examples ``` >>> # xdoctest: +SKIP >>> from tensorplay.masked import MaskedTensor >>> data = tensorplay.arange(6).reshape(2, 3) >>> mask = tp.tensor([[True, False, False], [True, True, False]]) >>> mt = MaskedTensor(data, mask) >>> is_masked_tensor(mt) True ``` [#](#api-tensorplay.masked.log_softmax) ### log_softmax function[Full reference ↗](/docs/generated/tensorplay.masked.log_softmax.html) ```python tensorplay.masked.log_softmax(input, dim, *, dtype=None, mask=None) → Tensor ``` Returns log_softmax of all the slices in the input tensor along dim while the input elements are masked out according to the boolean tensor mask. Let x be a sequence of unmasked elements of one-dimensional slice of the input tensor. LogSoftmax of i-th element in x is defined as log(exp(x[i])/sum(exp(x))). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in log_softmax computation, otherwise the element is ignored. The values of masked-out elements of the output tensor have undefined value: it may or may not be set to zero or nan; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the log_softmax output tensor can be computed as tensorplay.broadcast_to(mask, input.shape). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.log_softmax(input, 1, mask=mask) tensor([[-2.1269, -inf, -0.1269], [-nan, -nan, -nan]]) ``` [#](#api-tensorplay.masked.logaddexp) ### logaddexp function[Full reference ↗](/docs/generated/tensorplay.masked.logaddexp.html) ```python tensorplay.masked.logaddexp(input, other, *, dtype=None, input_mask=None, other_mask=None) → Tensor ``` Returns logaddexp of all the elements in the input and the other tensor. The input elements are masked out according to the boolean tensor input_mask and the attr:other elements are masked out according to the boolean tensor other_mask. The shapes of a mask tensor and the tensor to be masked don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the tensor to be masked. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the second input tensor Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. If specified, the output tensor is casted to dtype after the operation is performed. Default: None. - input_mask ([tensorplay.Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the boolean tensor containing the binary mask of validity of input tensor elements. Default: None that is equivalent to tensorplay.ones(input.shape, dtype=tensorplay.bool). - other_mask ([tensorplay.Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the boolean tensor containing the binary mask of validity of other tensor elements. Default: None that is equivalent to tensorplay.ones(other.shape, dtype=tensorplay.bool). Example: ``` >>> input = tensorplay.tensor([-100.0, -200, -300]) >>> input tensor([-100., -200., -300.]) >>> other = tensorplay.tensor([-1.0, -2, -3]) >>> other tensor([-1., -2., -3.]) >>> mask = tensorplay.tensor([True, False, True]) >>> mask tensor([ True, False, True]) >>> tensorplay.masked._ops.logaddexp(input, other, input_mask=mask, other_mask=mask) tensor([-1., -inf, -3.]) ``` [#](#api-tensorplay.masked.logsumexp) ### logsumexp function[Full reference ↗](/docs/generated/tensorplay.masked.logsumexp.html) ```python tensorplay.masked.logsumexp(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns logsumexp of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of logsumexp operation, which is used to start the reduction, is tensor(-2147483648, dtype=Int32). If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in logsumexp computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of logsumexp operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.logsumexp(input, 1, mask=mask) tensor([-0.8731, -inf]) ``` [#](#api-tensorplay.masked.masked_tensor) ### masked_tensor function[Full reference ↗](/docs/generated/tensorplay.masked.masked_tensor.html) ```python tensorplay.masked.masked_tensor(data: object, mask: object, requires_grad: bool = False) → MaskedTensor ``` [#](#api-tensorplay.masked.mean) ### mean function[Full reference ↗](/docs/generated/tensorplay.masked.mean.html) ```python tensorplay.masked.mean(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns mean of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. By definition, the identity value of a mean operation is the mean value of the tensor. If all elements of the input tensor along given dimension(s) dim are masked-out, the identity value of the mean is undefined. Due to this ambiguity, the elements of output tensor with strided layout, that correspond to fully masked-out elements, have nan values. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in mean computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of mean operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.mean(input, 1, mask=mask) tensor([-2., -nan]) ``` [#](#api-tensorplay.masked.median) ### median function[Full reference ↗](/docs/generated/tensorplay.masked.median.html) ```python tensorplay.masked.median(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns median of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. By definition, the identity value of a median operation is the median value of the tensor. If all elements of the input tensor along given dimension(s) dim are masked-out, the identity value of the median is undefined. Due to this ambiguity, the elements of output tensor with strided layout, that correspond to fully masked-out elements, have nan values. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in median computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of median operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.median(input, 1, mask=mask) tensor([-3., nan]) ``` [#](#api-tensorplay.masked.norm) ### norm function[Full reference ↗](/docs/generated/tensorplay.masked.norm.html) ```python tensorplay.masked.norm(input, ord, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns norm of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of norm operation, which is used to start the reduction, is tensor(0.), except for ord=-inf it is tensor(inf). If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in norm computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of norm operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.norm(input, 2.0, 1, mask=mask) tensor([3.1623, 0.]) ``` [#](#api-tensorplay.masked.normalize) ### normalize function[Full reference ↗](/docs/generated/tensorplay.masked.normalize.html) ```python tensorplay.masked.normalize(input, ord, dim, *, eps=1e-12, dtype=None, mask=None) → Tensor ``` Returns normalize of all the slices in the input tensor along dim while the input elements are masked out according to the boolean tensor mask. Let x be a sequence of unmasked elements of one-dimensional slice of the input tensor. Normalize of i-th element in x is defined as x[i]/max(norm(x, p), eps). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in normalize computation, otherwise the element is ignored. The values of masked-out elements of the output tensor have undefined value: it may or may not be set to zero or nan; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the normalize output tensor can be computed as tensorplay.broadcast_to(mask, input.shape). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.normalize(input, 2.0, 1, mask=mask) tensor([[-0.9487, 0., -0.3162], [0., 0., 0.]]) ``` [#](#api-tensorplay.masked.prod) ### prod function[Full reference ↗](/docs/generated/tensorplay.masked.prod.html) ```python tensorplay.masked.prod(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns product of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of product operation, which is used to start the reduction, is tensor(1, dtype=Int32). If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in product computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of product operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> input tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.prod(input, 1, mask=mask) tensor([3, 1], dtype=Int64) ``` [#](#api-tensorplay.masked.softmax) ### softmax function[Full reference ↗](/docs/generated/tensorplay.masked.softmax.html) ```python tensorplay.masked.softmax(input, dim, *, dtype=None, mask=None) → Tensor ``` Returns softmax of all the slices in the input tensor along dim while the input elements are masked out according to the boolean tensor mask. Let x be a sequence of unmasked elements of one-dimensional slice of the input tensor. Softmax of i-th element in x is defined as exp(x[i])/sum(exp(x)). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in softmax computation, otherwise the element is ignored. The values of masked-out elements of the output tensor have undefined value: it may or may not be set to zero or nan; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the softmax output tensor can be computed as tensorplay.broadcast_to(mask, input.shape). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.softmax(input, 1, mask=mask) tensor([[0.1192, 0., 0.8808], [-nan, -nan, -nan]]) ``` [#](#api-tensorplay.masked.softmin) ### softmin function[Full reference ↗](/docs/generated/tensorplay.masked.softmin.html) ```python tensorplay.masked.softmin(input, dim, *, dtype=None, mask=None) → Tensor ``` Returns softmin of all the slices in the input tensor along dim while the input elements are masked out according to the boolean tensor mask. Let x be a sequence of unmasked elements of one-dimensional slice of the input tensor. Softmin of i-th element in x is defined as exp(-x[i])/sum(exp(-x)). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in softmin computation, otherwise the element is ignored. The values of masked-out elements of the output tensor have undefined value: it may or may not be set to zero or nan; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the softmin output tensor can be computed as tensorplay.broadcast_to(mask, input.shape). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> input tensor([[-3., -2., -1.], [0., 1., 2.]]) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.softmin(input, 1, mask=mask) tensor([[0.8808, 0., 0.1192], [-nan, -nan, -nan]]) ``` [#](#api-tensorplay.masked.std) ### std function[Full reference ↗](/docs/generated/tensorplay.masked.std.html) ```python tensorplay.masked.std(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns standard_deviation of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of sample standard deviation operation is undefined. The elements of output tensor with strided layout, that correspond to fully masked-out elements, have nan values. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in standard_deviation computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of standard_deviation operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> input tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.std(input, 1, False, mask=mask) tensor([1., -nan]) ``` [#](#api-tensorplay.masked.sum) ### sum function[Full reference ↗](/docs/generated/tensorplay.masked.sum.html) ```python tensorplay.masked.sum(input, dim, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns sum of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of sum operation, which is used to start the reduction, is tensor(0, dtype=Int32). If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in sum computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of sum operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> input tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.sum(input, 1, mask=mask) tensor([-4, 0], dtype=Int64) ``` [#](#api-tensorplay.masked.var) ### var function[Full reference ↗](/docs/generated/tensorplay.masked.var.html) ```python tensorplay.masked.var(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) → Tensor ``` Returns variance of all the elements in the input tensor along the given dimension(s) dim while the input elements are masked out according to the boolean tensor mask. The identity value of sample variance operation is undefined. The elements of output tensor with strided layout, that correspond to fully masked-out elements, have nan values. If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s). The boolean tensor mask defines the “validity” of input tensor elements: if mask element is True then the corresponding element in input tensor will be included in variance computation, otherwise the element is ignored. When all elements of input along the given dimension dim are ignored (fully masked-out), the corresponding element of the output tensor will have undefined value: it may or may not correspond to the identity value of variance operation; the choice may correspond to the value that leads to the most efficient storage of output tensor. The mask of the output tensor can be computed as tensorplay.any(tensorplay.broadcast_to(mask, input.shape), dim, keepdim=keepdim, dtype=tensorplay.bool). The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of the mask tensor must not be greater than of the input tensor. Example: ``` >>> input = tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> input tensor([[-3, -2, -1], [0, 1, 2]], dtype=Int64) >>> mask = tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> mask tensor([[True, False, True], [False, False, False]], dtype=Bool) >>> tensorplay.masked._ops.var(input, 1, False, mask=mask) tensor([1., -nan]) ``` ## Classes 1 [#](#api-tensorplay.masked.MaskedTensor) ### MaskedTensor class[Full reference ↗](/docs/generated/tensorplay.masked.MaskedTensor.html) ```python class tensorplay.masked.MaskedTensor(data, mask, requires_grad=False) ``` A pair of plain tensors data and mask presented as a single value. mask is boolean and has the same shape as data. An element of data participates in computations only where the corresponding element of mask is True; positions where the mask is False are rendered as -- in the string representation and are replaced by a caller-supplied fill value by to_tensor(). The mask is always the source of truth for validity: masked-out entries of data may hold arbitrary values and are never read semantically. This class is not a tensor subclass and does not hook into a dispatcher. Operations are applied through explicit methods (elementwise ops, reductions and structural ops) or through the masking-aware functions in tensorplay.masked, which accept both plain tensors and MaskedTensor inputs. ```python abs(*args, **kwargs) ``` ```python abs_(*args, **kwargs) ``` ```python absolute(*args, **kwargs) ``` ```python absolute_(*args, **kwargs) ``` ```python acos(*args, **kwargs) ``` ```python acos_(*args, **kwargs) ``` ```python acosh(*args, **kwargs) ``` ```python acosh_(*args, **kwargs) ``` ```python add(*args, **kwargs) ``` ```python add_(*args, **kwargs) ``` ```python all(*args, **kwargs) ``` ```python amax(*args, **kwargs) ``` ```python amin(*args, **kwargs) ``` ```python angle(*args, **kwargs) ``` ```python any(*args, **kwargs) ``` ```python arccos(*args, **kwargs) ``` ```python arccos_(*args, **kwargs) ``` ```python arccosh(*args, **kwargs) ``` ```python arccosh_(*args, **kwargs) ``` ```python arcsin(*args, **kwargs) ``` ```python arcsin_(*args, **kwargs) ``` ```python arcsinh(*args, **kwargs) ``` ```python arcsinh_(*args, **kwargs) ``` ```python arctan(*args, **kwargs) ``` ```python arctan2(*args, **kwargs) ``` ```python arctan2_(*args, **kwargs) ``` ```python arctan_(*args, **kwargs) ``` ```python arctanh(*args, **kwargs) ``` ```python arctanh_(*args, **kwargs) ``` ```python argmax(*args, **kwargs) ``` ```python argmin(*args, **kwargs) ``` ```python asin(*args, **kwargs) ``` ```python asin_(*args, **kwargs) ``` ```python asinh(*args, **kwargs) ``` ```python asinh_(*args, **kwargs) ``` ```python atan(*args, **kwargs) ``` ```python atan2(*args, **kwargs) ``` ```python atan2_(*args, **kwargs) ``` ```python atan_(*args, **kwargs) ``` ```python atanh(*args, **kwargs) ``` ```python atanh_(*args, **kwargs) ``` ```python bitwise_and(*args, **kwargs) ``` ```python bitwise_and_(*args, **kwargs) ``` ```python bitwise_left_shift(*args, **kwargs) ``` ```python bitwise_left_shift_(*args, **kwargs) ``` ```python bitwise_not(*args, **kwargs) ``` ```python bitwise_not_(*args, **kwargs) ``` ```python bitwise_or(*args, **kwargs) ``` ```python bitwise_or_(*args, **kwargs) ``` ```python bitwise_right_shift(*args, **kwargs) ``` ```python bitwise_right_shift_(*args, **kwargs) ``` ```python bitwise_xor(*args, **kwargs) ``` ```python bitwise_xor_(*args, **kwargs) ``` ```python cat(*args, **kwargs) ``` ```python ceil(*args, **kwargs) ``` ```python ceil_(*args, **kwargs) ``` ```python clamp(*args, **kwargs) ``` ```python clamp_(*args, **kwargs) ``` ```python clip(*args, **kwargs) ``` ```python clip_(*args, **kwargs) ``` ```python clone(*args, **kwargs) ``` ```python col2im(*args, **kwargs) ``` ```python conj(*args, **kwargs) ``` ```python conj_physical(*args, **kwargs) ``` ```python conj_physical_(*args, **kwargs) ``` ```python contiguous(*args, **kwargs) ``` ```python copy_(*args, **kwargs) ``` ```python cos(*args, **kwargs) ``` ```python cos_(*args, **kwargs) ``` ```python cosh(*args, **kwargs) ``` ```python cosh_(*args, **kwargs) ``` ```python deg2rad(*args, **kwargs) ``` ```python deg2rad_(*args, **kwargs) ``` ```python detach(*args, **kwargs) ``` ```python digamma(*args, **kwargs) ``` ```python digamma_(*args, **kwargs) ``` ```python div(*args, **kwargs) ``` ```python div_(*args, **kwargs) ``` ```python divide(*args, **kwargs) ``` ```python divide_(*args, **kwargs) ``` ```python eq(*args, **kwargs) ``` ```python eq_(*args, **kwargs) ``` ```python erf(*args, **kwargs) ``` ```python erf_(*args, **kwargs) ``` ```python erfc(*args, **kwargs) ``` ```python erfc_(*args, **kwargs) ``` ```python erfinv(*args, **kwargs) ``` ```python erfinv_(*args, **kwargs) ``` ```python exp(*args, **kwargs) ``` ```python exp2(*args, **kwargs) ``` ```python exp2_(*args, **kwargs) ``` ```python exp_(*args, **kwargs) ``` ```python expand(*args, **kwargs) ``` ```python expm1(*args, **kwargs) ``` ```python expm1_(*args, **kwargs) ``` ```python fix(*args, **kwargs) ``` ```python fix_(*args, **kwargs) ``` ```python floor(*args, **kwargs) ``` ```python floor_(*args, **kwargs) ``` ```python floor_divide(*args, **kwargs) ``` ```python floor_divide_(*args, **kwargs) ``` ```python fmax(*args, **kwargs) ``` ```python fmin(*args, **kwargs) ``` ```python fmod(*args, **kwargs) ``` ```python fmod_(*args, **kwargs) ``` ```python frac(*args, **kwargs) ``` ```python frac_(*args, **kwargs) ``` ```python ge(*args, **kwargs) ``` ```python ge_(*args, **kwargs) ``` ```python greater(*args, **kwargs) ``` ```python greater_(*args, **kwargs) ``` ```python greater_equal(*args, **kwargs) ``` ```python greater_equal_(*args, **kwargs) ``` ```python gt(*args, **kwargs) ``` ```python gt_(*args, **kwargs) ``` ```python i0(*args, **kwargs) ``` ```python i0_(*args, **kwargs) ``` ```python im2col(*args, **kwargs) ``` ```python index(*args, **kwargs) ``` ```python indices(*args, **kwargs) ``` ```python is_contiguous(*args, **kwargs) ``` ```python is_same_size(*args, **kwargs) ``` ```python isnan(*args, **kwargs) ``` ```python item(*args, **kwargs) ``` ```python le(*args, **kwargs) ``` ```python le_(*args, **kwargs) ``` ```python less(*args, **kwargs) ``` ```python less_(*args, **kwargs) ``` ```python less_equal(*args, **kwargs) ``` ```python less_equal_(*args, **kwargs) ``` ```python lgamma(*args, **kwargs) ``` ```python lgamma_(*args, **kwargs) ``` ```python log(*args, **kwargs) ``` ```python log10(*args, **kwargs) ``` ```python log10_(*args, **kwargs) ``` ```python log1p(*args, **kwargs) ``` ```python log1p_(*args, **kwargs) ``` ```python log2(*args, **kwargs) ``` ```python log2_(*args, **kwargs) ``` ```python log_(*args, **kwargs) ``` ```python logaddexp(*args, **kwargs) ``` ```python logaddexp2(*args, **kwargs) ``` ```python logit(*args, **kwargs) ``` ```python logit_(*args, **kwargs) ``` ```python lt(*args, **kwargs) ``` ```python lt_(*args, **kwargs) ``` ```python maximum(*args, **kwargs) ``` ```python mean(*args, **kwargs) ``` ```python minimum(*args, **kwargs) ``` ```python mul(*args, **kwargs) ``` ```python mul_(*args, **kwargs) ``` ```python multiply(*args, **kwargs) ``` ```python multiply_(*args, **kwargs) ``` ```python nan_to_num(*args, **kwargs) ``` ```python nan_to_num_(*args, **kwargs) ``` ```python ne(*args, **kwargs) ``` ```python ne_(*args, **kwargs) ``` ```python neg(*args, **kwargs) ``` ```python neg_(*args, **kwargs) ``` ```python negative(*args, **kwargs) ``` ```python negative_(*args, **kwargs) ``` ```python new_empty_strided(*args, **kwargs) ``` ```python nextafter(*args, **kwargs) ``` ```python nextafter_(*args, **kwargs) ``` ```python norm(*args, **kwargs) ``` ```python not_equal(*args, **kwargs) ``` ```python not_equal_(*args, **kwargs) ``` ```python ones_like(*args, **kwargs) ``` ```python positive(*args, **kwargs) ``` ```python pow(*args, **kwargs) ``` ```python pow_(*args, **kwargs) ``` ```python prod(*args, **kwargs) ``` ```python rad2deg(*args, **kwargs) ``` ```python rad2deg_(*args, **kwargs) ``` ```python reciprocal(*args, **kwargs) ``` ```python reciprocal_(*args, **kwargs) ``` ```python remainder(*args, **kwargs) ``` ```python remainder_(*args, **kwargs) ``` ```python round(*args, **kwargs) ``` ```python round_(*args, **kwargs) ``` ```python rsqrt(*args, **kwargs) ``` ```python rsqrt_(*args, **kwargs) ``` ```python select(*args, **kwargs) ``` ```python select_backward(*args, **kwargs) ``` ```python sgn(*args, **kwargs) ``` ```python sgn_(*args, **kwargs) ``` ```python sigmoid(*args, **kwargs) ``` ```python sigmoid_(*args, **kwargs) ``` ```python sign(*args, **kwargs) ``` ```python sign_(*args, **kwargs) ``` ```python signbit(*args, **kwargs) ``` ```python sin(*args, **kwargs) ``` ```python sin_(*args, **kwargs) ``` ```python sinc(*args, **kwargs) ``` ```python sinc_(*args, **kwargs) ``` ```python sinh(*args, **kwargs) ``` ```python sinh_(*args, **kwargs) ``` ```python slice(*args, **kwargs) ``` ```python slice_backward(*args, **kwargs) ``` ```python softmax(*args, **kwargs) ``` ```python split(*args, **kwargs) ``` ```python sqrt(*args, **kwargs) ``` ```python sqrt_(*args, **kwargs) ``` ```python square(*args, **kwargs) ``` ```python square_(*args, **kwargs) ``` ```python stack(*args, **kwargs) ``` ```python std(*args, **kwargs) ``` ```python stride(*args, **kwargs) ``` ```python sub(*args, **kwargs) ``` ```python sub_(*args, **kwargs) ``` ```python subtract(*args, **kwargs) ``` ```python subtract_(*args, **kwargs) ``` ```python sum(*args, **kwargs) ``` ```python t(*args, **kwargs) ``` ```python tan(*args, **kwargs) ``` ```python tan_(*args, **kwargs) ``` ```python tanh(*args, **kwargs) ``` ```python tanh_(*args, **kwargs) ``` ```python to(*args, **kwargs) ``` ```python to_dense(*args, **kwargs) ``` ```python to_sparse(*args, **kwargs) ``` ```python to_sparse_csr(*args, **kwargs) ``` ```python transpose(*args, **kwargs) ``` ```python true_divide(*args, **kwargs) ``` ```python true_divide_(*args, **kwargs) ``` ```python trunc(*args, **kwargs) ``` ```python trunc_(*args, **kwargs) ``` ```python unfold(*args, **kwargs) ``` ```python unfold_backward(*args, **kwargs) ``` ```python unsqueeze(*args, **kwargs) ``` ```python values(*args, **kwargs) ``` ```python var(*args, **kwargs) ``` ```python view(*args, **kwargs) ```