latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.masked API
Functions 22
amax
functionFull reference ↗- tensorplay.masked.amax(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns maximum of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask.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), andtensor(-2147483648, dtype=Int32), respectively.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in maximum computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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)
amin
functionFull reference ↗- tensorplay.masked.amin(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns minimum of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask.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), andtensor(2147483647, dtype=Int32), respectively.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in minimum computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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)
argmax
functionFull reference ↗- tensorplay.masked.argmax(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns argmax of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask. 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 aretensor(-inf),tensor(Tensor(shape=tensorplay.Size(), dtype=UInt8, device=cpu), andtensor(-2147483648, dtype=Int32), respectively. IfkeepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in argmax computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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)
argmin
functionFull reference ↗- tensorplay.masked.argmin(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns argmin of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask. 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 aretensor(inf),tensor(Tensor(shape=tensorplay.Size(), dtype=UInt8, device=cpu), andtensor(2147483647, dtype=Int32), respectively. IfkeepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in argmin computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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)
as_masked_tensor
functionFull reference ↗- tensorplay.masked.as_masked_tensor(data: object, mask: object) MaskedTensor[source]
cumprod
functionFull reference ↗- tensorplay.masked.cumprod(input, dim, *, dtype=None, mask=None) Tensor[source]
Returns cumulative_prod of all the slices in the
inputtensor alongdimwhile theinputelements are masked out according to the boolean tensormask.Let
xbe a sequence of unmasked elements of one-dimensional slice of theinputtensor. Cumsum of i-th element inxis defined asprod(x[:i]).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor 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
outputtensor.The mask of the cumulative_prod output tensor can be computed as
tensorplay.broadcast_to(mask, input.shape).The shapes of the
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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.]])
cumsum
functionFull reference ↗- tensorplay.masked.cumsum(input, dim, *, dtype=None, mask=None) Tensor[source]
Returns cumulative_sum of all the slices in the
inputtensor alongdimwhile theinputelements are masked out according to the boolean tensormask.Let
xbe a sequence of unmasked elements of one-dimensional slice of theinputtensor. Cumsum of i-th element inxis defined assum(x[:i]).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor 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
outputtensor.The mask of the cumulative_sum output tensor can be computed as
tensorplay.broadcast_to(mask, input.shape).The shapes of the
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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.]])
is_masked_tensor
functionFull reference ↗- tensorplay.masked.is_masked_tensor(obj: Any, /) bool[source]
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
log_softmax
functionFull reference ↗- tensorplay.masked.log_softmax(input, dim, *, dtype=None, mask=None) Tensor[source]
Returns log_softmax of all the slices in the
inputtensor alongdimwhile theinputelements are masked out according to the boolean tensormask.Let
xbe a sequence of unmasked elements of one-dimensional slice of theinputtensor. LogSoftmax of i-th element inxis defined aslog(exp(x[i])/sum(exp(x))).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor 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
outputtensor.The mask of the log_softmax output tensor can be computed as
tensorplay.broadcast_to(mask, input.shape).The shapes of the
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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]])
logaddexp
functionFull reference ↗- tensorplay.masked.logaddexp(input, other, *, dtype=None, input_mask=None, other_mask=None) Tensor[source]
Returns logaddexp of all the elements in the
inputand theothertensor. Theinputelements are masked out according to the boolean tensorinput_maskand the attr:other elements are masked out according to the boolean tensorother_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:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. If specified, the output tensor is casted todtypeafter the operation is performed. Default: None.input_mask (
tensorplay.Tensor, optional) – the boolean tensor containing the binary mask of validity ofinputtensor elements. Default: None that is equivalent totensorplay.ones(input.shape, dtype=tensorplay.bool).other_mask (
tensorplay.Tensor, optional) – the boolean tensor containing the binary mask of validity ofothertensor elements. Default: None that is equivalent totensorplay.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.])
logsumexp
functionFull reference ↗- tensorplay.masked.logsumexp(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns logsumexp of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask.The identity value of logsumexp operation, which is used to start the reduction, is
tensor(-2147483648, dtype=Int32).If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in logsumexp computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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])
masked_tensor
functionFull reference ↗- tensorplay.masked.masked_tensor(data: object, mask: object, requires_grad: bool = False) MaskedTensor[source]
mean
functionFull reference ↗- tensorplay.masked.mean(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns mean of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask.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)
dimare 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, havenanvalues.If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in mean computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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])
median
functionFull reference ↗- tensorplay.masked.median(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns median of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask. 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)dimare 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, havenanvalues. IfkeepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in median computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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])
norm
functionFull reference ↗- tensorplay.masked.norm(input, ord, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns norm of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask.The identity value of norm operation, which is used to start the reduction, is
tensor(0.), except forord=-infit istensor(inf).If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in norm computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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.])
normalize
functionFull reference ↗- tensorplay.masked.normalize(input, ord, dim, *, eps=1e-12, dtype=None, mask=None) Tensor[source]
Returns normalize of all the slices in the
inputtensor alongdimwhile theinputelements are masked out according to the boolean tensormask.Let
xbe a sequence of unmasked elements of one-dimensional slice of theinputtensor. Normalize of i-th element inxis defined asx[i]/max(norm(x, p), eps).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor 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
outputtensor.The mask of the normalize output tensor can be computed as
tensorplay.broadcast_to(mask, input.shape).The shapes of the
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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.]])
prod
functionFull reference ↗- tensorplay.masked.prod(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns product of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask.The identity value of product operation, which is used to start the reduction, is
tensor(1, dtype=Int32).If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in product computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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)
softmax
functionFull reference ↗- tensorplay.masked.softmax(input, dim, *, dtype=None, mask=None) Tensor[source]
Returns softmax of all the slices in the
inputtensor alongdimwhile theinputelements are masked out according to the boolean tensormask.Let
xbe a sequence of unmasked elements of one-dimensional slice of theinputtensor. Softmax of i-th element inxis defined asexp(x[i])/sum(exp(x)).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor 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
outputtensor.The mask of the softmax output tensor can be computed as
tensorplay.broadcast_to(mask, input.shape).The shapes of the
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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]])
softmin
functionFull reference ↗- tensorplay.masked.softmin(input, dim, *, dtype=None, mask=None) Tensor[source]
Returns softmin of all the slices in the
inputtensor alongdimwhile theinputelements are masked out according to the boolean tensormask.Let
xbe a sequence of unmasked elements of one-dimensional slice of theinputtensor. Softmin of i-th element inxis defined asexp(-x[i])/sum(exp(-x)).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor 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
outputtensor.The mask of the softmin output tensor can be computed as
tensorplay.broadcast_to(mask, input.shape).The shapes of the
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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]])
std
functionFull reference ↗- tensorplay.masked.std(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns standard_deviation of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask. 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, havenanvalues. IfkeepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in standard_deviation computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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])
sum
functionFull reference ↗- tensorplay.masked.sum(input, dim, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns sum of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask.The identity value of sum operation, which is used to start the reduction, is
tensor(0, dtype=Int32).If
keepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in sum computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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)
var
functionFull reference ↗- tensorplay.masked.var(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) Tensor[source]
Returns variance of all the elements in the
inputtensor along the given dimension(s)dimwhile theinputelements are masked out according to the boolean tensormask. The identity value of sample variance operation is undefined. The elements of output tensor with strided layout, that correspond to fully masked-out elements, havenanvalues. IfkeepdimisTrue, the output tensor is of the same size asinputexcept in the dimension(s)dimwhere it is of size 1. Otherwise,dimis squeezed (seetensorplay.squeeze()), resulting in the output tensor having 1 (orlen(dim)) fewer dimension(s).The boolean tensor
maskdefines the “validity” ofinputtensor elements: ifmaskelement is True then the corresponding element ininputtensor will be included in variance computation, otherwise the element is ignored.When all elements of
inputalong the given dimensiondimare 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 ofoutputtensor.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
masktensor and theinputtensor don’t need to match, but they must be broadcastable under the standard broadcasting rules and the dimensionality of themasktensor must not be greater than of theinputtensor.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
MaskedTensor
classFull reference ↗- class tensorplay.masked.MaskedTensor(data, mask, requires_grad=False)[source]
A pair of plain tensors
dataandmaskpresented as a single value.maskis boolean and has the same shape asdata. An element ofdataparticipates in computations only where the corresponding element ofmaskis True; positions where the mask is False are rendered as--in the string representation and are replaced by a caller-supplied fill value byto_tensor().The mask is always the source of truth for validity: masked-out entries of
datamay 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.- abs(*args, **kwargs)
- abs_(*args, **kwargs)
- absolute(*args, **kwargs)
- absolute_(*args, **kwargs)
- acos(*args, **kwargs)
- acos_(*args, **kwargs)
- acosh(*args, **kwargs)
- acosh_(*args, **kwargs)
- add(*args, **kwargs)
- add_(*args, **kwargs)
- all(*args, **kwargs)
- amax(*args, **kwargs)
- amin(*args, **kwargs)
- angle(*args, **kwargs)
- any(*args, **kwargs)
- arccos(*args, **kwargs)
- arccos_(*args, **kwargs)
- arccosh(*args, **kwargs)
- arccosh_(*args, **kwargs)
- arcsin(*args, **kwargs)
- arcsin_(*args, **kwargs)
- arcsinh(*args, **kwargs)
- arcsinh_(*args, **kwargs)
- arctan(*args, **kwargs)
- arctan2(*args, **kwargs)
- arctan2_(*args, **kwargs)
- arctan_(*args, **kwargs)
- arctanh(*args, **kwargs)
- arctanh_(*args, **kwargs)
- argmax(*args, **kwargs)
- argmin(*args, **kwargs)
- asin(*args, **kwargs)
- asin_(*args, **kwargs)
- asinh(*args, **kwargs)
- asinh_(*args, **kwargs)
- atan(*args, **kwargs)
- atan2(*args, **kwargs)
- atan2_(*args, **kwargs)
- atan_(*args, **kwargs)
- atanh(*args, **kwargs)
- atanh_(*args, **kwargs)
- bitwise_and(*args, **kwargs)
- bitwise_and_(*args, **kwargs)
- bitwise_left_shift(*args, **kwargs)
- bitwise_left_shift_(*args, **kwargs)
- bitwise_not(*args, **kwargs)
- bitwise_not_(*args, **kwargs)
- bitwise_or(*args, **kwargs)
- bitwise_or_(*args, **kwargs)
- bitwise_right_shift(*args, **kwargs)
- bitwise_right_shift_(*args, **kwargs)
- bitwise_xor(*args, **kwargs)
- bitwise_xor_(*args, **kwargs)
- cat(*args, **kwargs)
- ceil(*args, **kwargs)
- ceil_(*args, **kwargs)
- clamp(*args, **kwargs)
- clamp_(*args, **kwargs)
- clip(*args, **kwargs)
- clip_(*args, **kwargs)
- clone(*args, **kwargs)
- col2im(*args, **kwargs)
- conj(*args, **kwargs)
- conj_physical(*args, **kwargs)
- conj_physical_(*args, **kwargs)
- contiguous(*args, **kwargs)
- copy_(*args, **kwargs)
- cos(*args, **kwargs)
- cos_(*args, **kwargs)
- cosh(*args, **kwargs)
- cosh_(*args, **kwargs)
- deg2rad(*args, **kwargs)
- deg2rad_(*args, **kwargs)
- detach(*args, **kwargs)
- digamma(*args, **kwargs)
- digamma_(*args, **kwargs)
- div(*args, **kwargs)
- div_(*args, **kwargs)
- divide(*args, **kwargs)
- divide_(*args, **kwargs)
- eq(*args, **kwargs)
- eq_(*args, **kwargs)
- erf(*args, **kwargs)
- erf_(*args, **kwargs)
- erfc(*args, **kwargs)
- erfc_(*args, **kwargs)
- erfinv(*args, **kwargs)
- erfinv_(*args, **kwargs)
- exp(*args, **kwargs)
- exp2(*args, **kwargs)
- exp2_(*args, **kwargs)
- exp_(*args, **kwargs)
- expand(*args, **kwargs)
- expm1(*args, **kwargs)
- expm1_(*args, **kwargs)
- fix(*args, **kwargs)
- fix_(*args, **kwargs)
- floor(*args, **kwargs)
- floor_(*args, **kwargs)
- floor_divide(*args, **kwargs)
- floor_divide_(*args, **kwargs)
- fmax(*args, **kwargs)
- fmin(*args, **kwargs)
- fmod(*args, **kwargs)
- fmod_(*args, **kwargs)
- frac(*args, **kwargs)
- frac_(*args, **kwargs)
- ge(*args, **kwargs)
- ge_(*args, **kwargs)
- greater(*args, **kwargs)
- greater_(*args, **kwargs)
- greater_equal(*args, **kwargs)
- greater_equal_(*args, **kwargs)
- gt(*args, **kwargs)
- gt_(*args, **kwargs)
- i0(*args, **kwargs)
- i0_(*args, **kwargs)
- im2col(*args, **kwargs)
- index(*args, **kwargs)
- indices(*args, **kwargs)
- is_contiguous(*args, **kwargs)
- is_same_size(*args, **kwargs)
- isnan(*args, **kwargs)
- item(*args, **kwargs)
- le(*args, **kwargs)
- le_(*args, **kwargs)
- less(*args, **kwargs)
- less_(*args, **kwargs)
- less_equal(*args, **kwargs)
- less_equal_(*args, **kwargs)
- lgamma(*args, **kwargs)
- lgamma_(*args, **kwargs)
- log(*args, **kwargs)
- log10(*args, **kwargs)
- log10_(*args, **kwargs)
- log1p(*args, **kwargs)
- log1p_(*args, **kwargs)
- log2(*args, **kwargs)
- log2_(*args, **kwargs)
- log_(*args, **kwargs)
- logaddexp(*args, **kwargs)
- logaddexp2(*args, **kwargs)
- logit(*args, **kwargs)
- logit_(*args, **kwargs)
- lt(*args, **kwargs)
- lt_(*args, **kwargs)
- maximum(*args, **kwargs)
- mean(*args, **kwargs)
- minimum(*args, **kwargs)
- mul(*args, **kwargs)
- mul_(*args, **kwargs)
- multiply(*args, **kwargs)
- multiply_(*args, **kwargs)
- nan_to_num(*args, **kwargs)
- nan_to_num_(*args, **kwargs)
- ne(*args, **kwargs)
- ne_(*args, **kwargs)
- neg(*args, **kwargs)
- neg_(*args, **kwargs)
- negative(*args, **kwargs)
- negative_(*args, **kwargs)
- new_empty_strided(*args, **kwargs)
- nextafter(*args, **kwargs)
- nextafter_(*args, **kwargs)
- norm(*args, **kwargs)
- not_equal(*args, **kwargs)
- not_equal_(*args, **kwargs)
- ones_like(*args, **kwargs)
- positive(*args, **kwargs)
- pow(*args, **kwargs)
- pow_(*args, **kwargs)
- prod(*args, **kwargs)
- rad2deg(*args, **kwargs)
- rad2deg_(*args, **kwargs)
- reciprocal(*args, **kwargs)
- reciprocal_(*args, **kwargs)
- remainder(*args, **kwargs)
- remainder_(*args, **kwargs)
- round(*args, **kwargs)
- round_(*args, **kwargs)
- rsqrt(*args, **kwargs)
- rsqrt_(*args, **kwargs)
- select(*args, **kwargs)
- select_backward(*args, **kwargs)
- sgn(*args, **kwargs)
- sgn_(*args, **kwargs)
- sigmoid(*args, **kwargs)
- sigmoid_(*args, **kwargs)
- sign(*args, **kwargs)
- sign_(*args, **kwargs)
- signbit(*args, **kwargs)
- sin(*args, **kwargs)
- sin_(*args, **kwargs)
- sinc(*args, **kwargs)
- sinc_(*args, **kwargs)
- sinh(*args, **kwargs)
- sinh_(*args, **kwargs)
- slice(*args, **kwargs)
- slice_backward(*args, **kwargs)
- softmax(*args, **kwargs)
- split(*args, **kwargs)
- sqrt(*args, **kwargs)
- sqrt_(*args, **kwargs)
- square(*args, **kwargs)
- square_(*args, **kwargs)
- stack(*args, **kwargs)
- std(*args, **kwargs)
- stride(*args, **kwargs)
- sub(*args, **kwargs)
- sub_(*args, **kwargs)
- subtract(*args, **kwargs)
- subtract_(*args, **kwargs)
- sum(*args, **kwargs)
- t(*args, **kwargs)
- tan(*args, **kwargs)
- tan_(*args, **kwargs)
- tanh(*args, **kwargs)
- tanh_(*args, **kwargs)
- to(*args, **kwargs)
- to_dense(*args, **kwargs)
- to_sparse(*args, **kwargs)
- to_sparse_csr(*args, **kwargs)
- transpose(*args, **kwargs)
- true_divide(*args, **kwargs)
- true_divide_(*args, **kwargs)
- trunc(*args, **kwargs)
- trunc_(*args, **kwargs)
- unfold(*args, **kwargs)
- unfold_backward(*args, **kwargs)
- unsqueeze(*args, **kwargs)
- values(*args, **kwargs)
- var(*args, **kwargs)
- view(*args, **kwargs)
Help improve this page
Found an error, an unclear step, or a missing example?

