| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177 |
- # This file is generated, do not modify it!
- #
- # To update this file, run the update masked docs script as follows:
- #
- # python tools/update_masked_docs.py
- #
- # The script must be called from an environment where the development
- # version of torch package can be imported and is functional.
- #
- amax_docstring = """amax(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns maximum of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`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 ``-inf``, ``0``, and ``-2147483648``, respectively.
- If :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in maximum computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.amax(input, 1, mask=mask)
- tensor([ -1, -9223372036854775808])
- """
- amin_docstring = """amin(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns minimum of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`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 ``inf``, ``255``, and ``2147483647``, respectively.
- If :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in minimum computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.amin(input, 1, mask=mask)
- tensor([ -3, 9223372036854775807])
- """
- argmax_docstring = """argmax(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns argmax of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`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 ``-inf``, ``0``, and ``-2147483648``, respectively.
- If :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in argmax computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int): the dimension along which argmax is computed.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.argmax(input, 1, mask=mask)
- tensor([2, 0])
- """
- argmin_docstring = """argmin(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns argmin of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`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 ``inf``, ``255``, and ``2147483647``, respectively.
- If :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in argmin computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int): the dimension along which argmin is computed.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.argmin(input, 1, mask=mask)
- tensor([0, 0])
- """
- cumprod_docstring = """cumprod(input, dim, *, dtype=None, mask=None) -> Tensor
- Returns cumulative_prod of all the slices in the :attr:`input` tensor
- along :attr:`dim` while the :attr:`input` elements are masked out
- according to the boolean tensor :attr:`mask`.
- Let ``x`` be a sequence of unmasked elements of one-dimensional slice
- of the :attr:`input` tensor. Cumsum of i-th element in ``x`` is
- defined as ``prod(x[:i])``.
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True then
- the corresponding element in :attr:`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 :attr:`output`
- tensor.
- The mask of the cumulative_prod output tensor can be computed as
- ``torch.broadcast_to(mask, input.shape)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int): the dimension along which cumulative_prod is computed.
- Keyword args:
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.cumprod(input, 1, mask=mask)
- tensor([[-3., -3., 3.],
- [ 1., 1., 1.]])
- """
- cumsum_docstring = """cumsum(input, dim, *, dtype=None, mask=None) -> Tensor
- Returns cumulative_sum of all the slices in the :attr:`input` tensor
- along :attr:`dim` while the :attr:`input` elements are masked out
- according to the boolean tensor :attr:`mask`.
- Let ``x`` be a sequence of unmasked elements of one-dimensional slice
- of the :attr:`input` tensor. Cumsum of i-th element in ``x`` is
- defined as ``sum(x[:i])``.
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True then
- the corresponding element in :attr:`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 :attr:`output`
- tensor.
- The mask of the cumulative_sum output tensor can be computed as
- ``torch.broadcast_to(mask, input.shape)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int): the dimension along which cumulative_sum is computed.
- Keyword args:
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.cumsum(input, 1, mask=mask)
- tensor([[-3., -3., -4.],
- [ 0., 0., 0.]])
- """
- log_softmax_docstring = """log_softmax(input, dim, *, dtype=None, mask=None) -> Tensor
- Returns log_softmax of all the slices in the :attr:`input` tensor
- along :attr:`dim` while the :attr:`input` elements are masked out
- according to the boolean tensor :attr:`mask`.
- Let ``x`` be a sequence of unmasked elements of one-dimensional slice
- of the :attr:`input` tensor. LogSoftmax of i-th element in ``x`` is
- defined as ``log(exp(x[i])/sum(exp(x)))``.
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True then
- the corresponding element in :attr:`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 :attr:`output`
- tensor.
- The mask of the log_softmax output tensor can be computed as
- ``torch.broadcast_to(mask, input.shape)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int): the dimension along which log_softmax is computed.
- Keyword args:
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.log_softmax(input, 1, mask=mask)
- tensor([[-2.1269, -inf, -0.1269],
- [ nan, nan, nan]])
- """
- logsumexp_docstring = """logsumexp(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns logsumexp of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`mask`.
- The identity value of logsumexp operation, which is used to start the reduction, is ``-2147483648``.
- If :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in logsumexp computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.logsumexp(input, 1, mask=mask)
- tensor([ 0, -9223372036854775808])
- """
- mean_docstring = """mean(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns mean of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`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) :attr:`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 :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in mean computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.mean(input, 1, mask=mask)
- tensor([-2., nan])
- """
- median_docstring = """median(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns median of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`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) :attr:`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 :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in median computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int): the dimension along which median is computed.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.median(input, 1, mask=mask)
- tensor([-3., nan])
- """
- norm_docstring = """norm(input, ord, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns norm of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`mask`.
- The identity value of norm operation, which is used to start the
- reduction, is ``0.0``, except for ``ord=-inf`` it is
- ``inf``.
- If :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in norm computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- ord (int, float, optional): the order of vector norm. Default: 2.
- See :func:`torch.linalg.vector_norm` for a list of supported norms.
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.norm(input, 2.0, 1, mask=mask)
- tensor([3.1623, 0.0000])
- """
- normalize_docstring = """normalize(input, ord, dim, *, eps=1e-12, dtype=None, mask=None) -> Tensor
- Returns normalize of all the slices in the :attr:`input` tensor
- along :attr:`dim` while the :attr:`input` elements are masked out
- according to the boolean tensor :attr:`mask`.
- Let ``x`` be a sequence of unmasked elements of one-dimensional slice
- of the :attr:`input` tensor. Normalize of i-th element in ``x`` is
- defined as ``x[i]/max(norm(x, p), eps)``.
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True then
- the corresponding element in :attr:`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 :attr:`output`
- tensor.
- The mask of the normalize output tensor can be computed as
- ``torch.broadcast_to(mask, input.shape)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- ord (int, float): the order of vector norm. Default: 2.
- See :func:`torch.linalg.vector_norm` for a list of supported norms.
- dim (int): the dimension along which normalize is computed.
- Keyword args:
- eps (float, optional): small value to avoid division by zero. Default: 1e-12.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.normalize(input, 2.0, 1, mask=mask)
- tensor([[-0.9487, 0.0000, -0.3162],
- [ 0.0000, 0.0000, 0.0000]])
- """
- prod_docstring = """prod(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns product of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`mask`.
- The identity value of product operation, which is used to start the reduction, is ``1``.
- If :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in product computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.prod(input, 1, mask=mask)
- tensor([3, 1])
- """
- softmax_docstring = """softmax(input, dim, *, dtype=None, mask=None) -> Tensor
- Returns softmax of all the slices in the :attr:`input` tensor
- along :attr:`dim` while the :attr:`input` elements are masked out
- according to the boolean tensor :attr:`mask`.
- Let ``x`` be a sequence of unmasked elements of one-dimensional slice
- of the :attr:`input` tensor. Softmax of i-th element in ``x`` is
- defined as ``exp(x[i])/sum(exp(x))``.
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True then
- the corresponding element in :attr:`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 :attr:`output`
- tensor.
- The mask of the softmax output tensor can be computed as
- ``torch.broadcast_to(mask, input.shape)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int): the dimension along which softmax is computed.
- Keyword args:
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.softmax(input, 1, mask=mask)
- tensor([[0.1192, 0.0000, 0.8808],
- [ nan, nan, nan]])
- """
- softmin_docstring = """softmin(input, dim, *, dtype=None, mask=None) -> Tensor
- Returns softmin of all the slices in the :attr:`input` tensor
- along :attr:`dim` while the :attr:`input` elements are masked out
- according to the boolean tensor :attr:`mask`.
- Let ``x`` be a sequence of unmasked elements of one-dimensional slice
- of the :attr:`input` tensor. Softmin of i-th element in ``x`` is
- defined as ``exp(-x[i])/sum(exp(-x))``.
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True then
- the corresponding element in :attr:`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 :attr:`output`
- tensor.
- The mask of the softmin output tensor can be computed as
- ``torch.broadcast_to(mask, input.shape)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int): the dimension along which softmin is computed.
- Keyword args:
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.softmin(input, 1, mask=mask)
- tensor([[0.8808, 0.0000, 0.1192],
- [ nan, nan, nan]])
- """
- std_docstring = """std(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns standard_deviation of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`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 :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in standard_deviation computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- unbiased (bool): when True, use Bessel's correction, otherwise, compute
- the uncorrected sample variance.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.std(input, 1, False, mask=mask)
- tensor([1., nan])
- """
- sum_docstring = """sum(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns sum of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`mask`.
- The identity value of sum operation, which is used to start the reduction, is ``0``.
- If :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in sum computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.sum(input, 1, mask=mask)
- tensor([-4, 0])
- """
- var_docstring = """var(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) -> Tensor
- Returns variance of all the elements in the :attr:`input`
- tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
- elements are masked out according to the boolean tensor
- :attr:`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 :attr:`keepdim` is ``True``, the output tensor is of the same size
- as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
- size 1. Otherwise, :attr:`dim` is squeezed (see
- :func:`torch.squeeze`), resulting in the output tensor having 1 (or
- ``len(dim)``) fewer dimension(s).
- The boolean tensor :attr:`mask` defines the "validity" of
- :attr:`input` tensor elements: if :attr:`mask` element is True
- then the corresponding element in :attr:`input` tensor will be
- included in variance computation, otherwise the element is
- ignored.
- When all elements of :attr:`input` along the given dimension
- :attr:`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 :attr:`output` tensor.
- The mask of the output tensor can be computed as
- ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
- dtype=torch.bool)``.
- The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
- don't need to match, but they must be :ref:`broadcastable
- <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
- tensor must not be greater than of the :attr:`input` tensor.
- Args:
- input (Tensor): the input tensor
- dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
- Default: None that is equivalent to ``tuple(range(input.ndim))``.
- unbiased (bool): when True, use Bessel's correction, otherwise, compute
- the uncorrected sample variance.
- Keyword args:
- keepdim (bool, optional): whether the output tensor has
- :attr:`dim` retained or not. Default: False.
- dtype (:class:`torch.dtype`, optional): the desired data type
- of returned tensor. If specified, the input tensor is
- casted to :attr:`dtype` before the operation is
- performed. Default: None.
- mask (:class:`torch.Tensor`, optional): the boolean tensor
- containing the binary mask of validity of input tensor
- elements.
- Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
- 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]])
- >>> mask
- tensor([[ True, False, True],
- [False, False, False]])
- >>> torch.masked._ops.var(input, 1, False, mask=mask)
- tensor([1., nan])
- """
|