12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178 |
- # -*- coding: utf-8 -*-
- # 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])
- """
|