_docs.py 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  1. # This file is generated, do not modify it!
  2. #
  3. # To update this file, run the update masked docs script as follows:
  4. #
  5. # python tools/update_masked_docs.py
  6. #
  7. # The script must be called from an environment where the development
  8. # version of torch package can be imported and is functional.
  9. #
  10. amax_docstring = """amax(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  11. Returns maximum of all the elements in the :attr:`input`
  12. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  13. elements are masked out according to the boolean tensor
  14. :attr:`mask`.
  15. The identity value of maximum operation, which is used to start the
  16. reduction, depends on input dtype. For instance, for float32, uint8,
  17. and int32 dtypes, the identity values are ``-inf``, ``0``, and ``-2147483648``, respectively.
  18. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  19. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  20. size 1. Otherwise, :attr:`dim` is squeezed (see
  21. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  22. ``len(dim)``) fewer dimension(s).
  23. The boolean tensor :attr:`mask` defines the "validity" of
  24. :attr:`input` tensor elements: if :attr:`mask` element is True
  25. then the corresponding element in :attr:`input` tensor will be
  26. included in maximum computation, otherwise the element is
  27. ignored.
  28. When all elements of :attr:`input` along the given dimension
  29. :attr:`dim` are ignored (fully masked-out), the corresponding element
  30. of the output tensor will have undefined value: it may or may not
  31. correspond to the identity value of maximum operation; the
  32. choice may correspond to the value that leads to the most efficient
  33. storage of :attr:`output` tensor.
  34. The mask of the output tensor can be computed as
  35. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  36. dtype=torch.bool)``.
  37. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  38. don't need to match, but they must be :ref:`broadcastable
  39. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  40. tensor must not be greater than of the :attr:`input` tensor.
  41. Args:
  42. input (Tensor): the input tensor
  43. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  44. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  45. Keyword args:
  46. keepdim (bool, optional): whether the output tensor has
  47. :attr:`dim` retained or not. Default: False.
  48. dtype (:class:`torch.dtype`, optional): the desired data type
  49. of returned tensor. If specified, the input tensor is
  50. casted to :attr:`dtype` before the operation is
  51. performed. Default: None.
  52. mask (:class:`torch.Tensor`, optional): the boolean tensor
  53. containing the binary mask of validity of input tensor
  54. elements.
  55. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  56. Example::
  57. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  58. >>> input
  59. tensor([[-3, -2, -1],
  60. [ 0, 1, 2]])
  61. >>> mask = tensor([[ True, False, True], [False, False, False]])
  62. >>> mask
  63. tensor([[ True, False, True],
  64. [False, False, False]])
  65. >>> torch.masked._ops.amax(input, 1, mask=mask)
  66. tensor([ -1, -9223372036854775808])
  67. """
  68. amin_docstring = """amin(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  69. Returns minimum of all the elements in the :attr:`input`
  70. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  71. elements are masked out according to the boolean tensor
  72. :attr:`mask`.
  73. The identity value of minimum operation, which is used to start the
  74. reduction, depends on input dtype. For instance, for float32, uint8,
  75. and int32 dtypes, the identity values are ``inf``, ``255``, and ``2147483647``, respectively.
  76. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  77. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  78. size 1. Otherwise, :attr:`dim` is squeezed (see
  79. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  80. ``len(dim)``) fewer dimension(s).
  81. The boolean tensor :attr:`mask` defines the "validity" of
  82. :attr:`input` tensor elements: if :attr:`mask` element is True
  83. then the corresponding element in :attr:`input` tensor will be
  84. included in minimum computation, otherwise the element is
  85. ignored.
  86. When all elements of :attr:`input` along the given dimension
  87. :attr:`dim` are ignored (fully masked-out), the corresponding element
  88. of the output tensor will have undefined value: it may or may not
  89. correspond to the identity value of minimum operation; the
  90. choice may correspond to the value that leads to the most efficient
  91. storage of :attr:`output` tensor.
  92. The mask of the output tensor can be computed as
  93. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  94. dtype=torch.bool)``.
  95. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  96. don't need to match, but they must be :ref:`broadcastable
  97. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  98. tensor must not be greater than of the :attr:`input` tensor.
  99. Args:
  100. input (Tensor): the input tensor
  101. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  102. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  103. Keyword args:
  104. keepdim (bool, optional): whether the output tensor has
  105. :attr:`dim` retained or not. Default: False.
  106. dtype (:class:`torch.dtype`, optional): the desired data type
  107. of returned tensor. If specified, the input tensor is
  108. casted to :attr:`dtype` before the operation is
  109. performed. Default: None.
  110. mask (:class:`torch.Tensor`, optional): the boolean tensor
  111. containing the binary mask of validity of input tensor
  112. elements.
  113. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  114. Example::
  115. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  116. >>> input
  117. tensor([[-3, -2, -1],
  118. [ 0, 1, 2]])
  119. >>> mask = tensor([[ True, False, True], [False, False, False]])
  120. >>> mask
  121. tensor([[ True, False, True],
  122. [False, False, False]])
  123. >>> torch.masked._ops.amin(input, 1, mask=mask)
  124. tensor([ -3, 9223372036854775807])
  125. """
  126. argmax_docstring = """argmax(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  127. Returns argmax of all the elements in the :attr:`input`
  128. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  129. elements are masked out according to the boolean tensor
  130. :attr:`mask`.
  131. The identity value of argmax operation, which is used to start the
  132. reduction, depends on input dtype. For instance, for float32, uint8,
  133. and int32 dtypes, the identity values are ``-inf``, ``0``, and ``-2147483648``, respectively.
  134. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  135. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  136. size 1. Otherwise, :attr:`dim` is squeezed (see
  137. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  138. ``len(dim)``) fewer dimension(s).
  139. The boolean tensor :attr:`mask` defines the "validity" of
  140. :attr:`input` tensor elements: if :attr:`mask` element is True
  141. then the corresponding element in :attr:`input` tensor will be
  142. included in argmax computation, otherwise the element is
  143. ignored.
  144. When all elements of :attr:`input` along the given dimension
  145. :attr:`dim` are ignored (fully masked-out), the corresponding element
  146. of the output tensor will have undefined value: it may or may not
  147. correspond to the identity value of argmax operation; the
  148. choice may correspond to the value that leads to the most efficient
  149. storage of :attr:`output` tensor.
  150. The mask of the output tensor can be computed as
  151. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  152. dtype=torch.bool)``.
  153. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  154. don't need to match, but they must be :ref:`broadcastable
  155. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  156. tensor must not be greater than of the :attr:`input` tensor.
  157. Args:
  158. input (Tensor): the input tensor
  159. dim (int): the dimension along which argmax is computed.
  160. Keyword args:
  161. keepdim (bool, optional): whether the output tensor has
  162. :attr:`dim` retained or not. Default: False.
  163. dtype (:class:`torch.dtype`, optional): the desired data type
  164. of returned tensor. If specified, the input tensor is
  165. casted to :attr:`dtype` before the operation is
  166. performed. Default: None.
  167. mask (:class:`torch.Tensor`, optional): the boolean tensor
  168. containing the binary mask of validity of input tensor
  169. elements.
  170. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  171. Example::
  172. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  173. >>> input
  174. tensor([[-3, -2, -1],
  175. [ 0, 1, 2]])
  176. >>> mask = tensor([[ True, False, True], [False, False, False]])
  177. >>> mask
  178. tensor([[ True, False, True],
  179. [False, False, False]])
  180. >>> torch.masked._ops.argmax(input, 1, mask=mask)
  181. tensor([2, 0])
  182. """
  183. argmin_docstring = """argmin(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  184. Returns argmin of all the elements in the :attr:`input`
  185. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  186. elements are masked out according to the boolean tensor
  187. :attr:`mask`.
  188. The identity value of argmin operation, which is used to start the
  189. reduction, depends on input dtype. For instance, for float32, uint8,
  190. and int32 dtypes, the identity values are ``inf``, ``255``, and ``2147483647``, respectively.
  191. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  192. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  193. size 1. Otherwise, :attr:`dim` is squeezed (see
  194. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  195. ``len(dim)``) fewer dimension(s).
  196. The boolean tensor :attr:`mask` defines the "validity" of
  197. :attr:`input` tensor elements: if :attr:`mask` element is True
  198. then the corresponding element in :attr:`input` tensor will be
  199. included in argmin computation, otherwise the element is
  200. ignored.
  201. When all elements of :attr:`input` along the given dimension
  202. :attr:`dim` are ignored (fully masked-out), the corresponding element
  203. of the output tensor will have undefined value: it may or may not
  204. correspond to the identity value of argmin operation; the
  205. choice may correspond to the value that leads to the most efficient
  206. storage of :attr:`output` tensor.
  207. The mask of the output tensor can be computed as
  208. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  209. dtype=torch.bool)``.
  210. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  211. don't need to match, but they must be :ref:`broadcastable
  212. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  213. tensor must not be greater than of the :attr:`input` tensor.
  214. Args:
  215. input (Tensor): the input tensor
  216. dim (int): the dimension along which argmin is computed.
  217. Keyword args:
  218. keepdim (bool, optional): whether the output tensor has
  219. :attr:`dim` retained or not. Default: False.
  220. dtype (:class:`torch.dtype`, optional): the desired data type
  221. of returned tensor. If specified, the input tensor is
  222. casted to :attr:`dtype` before the operation is
  223. performed. Default: None.
  224. mask (:class:`torch.Tensor`, optional): the boolean tensor
  225. containing the binary mask of validity of input tensor
  226. elements.
  227. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  228. Example::
  229. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  230. >>> input
  231. tensor([[-3, -2, -1],
  232. [ 0, 1, 2]])
  233. >>> mask = tensor([[ True, False, True], [False, False, False]])
  234. >>> mask
  235. tensor([[ True, False, True],
  236. [False, False, False]])
  237. >>> torch.masked._ops.argmin(input, 1, mask=mask)
  238. tensor([0, 0])
  239. """
  240. cumprod_docstring = """cumprod(input, dim, *, dtype=None, mask=None) -> Tensor
  241. Returns cumulative_prod of all the slices in the :attr:`input` tensor
  242. along :attr:`dim` while the :attr:`input` elements are masked out
  243. according to the boolean tensor :attr:`mask`.
  244. Let ``x`` be a sequence of unmasked elements of one-dimensional slice
  245. of the :attr:`input` tensor. Cumsum of i-th element in ``x`` is
  246. defined as ``prod(x[:i])``.
  247. The boolean tensor :attr:`mask` defines the "validity" of
  248. :attr:`input` tensor elements: if :attr:`mask` element is True then
  249. the corresponding element in :attr:`input` tensor will be included in
  250. cumulative_prod computation, otherwise the element is ignored.
  251. The values of masked-out elements of the output tensor have undefined
  252. value: it may or may not be set to zero or nan; the choice may correspond to
  253. the value that leads to the most efficient storage of :attr:`output`
  254. tensor.
  255. The mask of the cumulative_prod output tensor can be computed as
  256. ``torch.broadcast_to(mask, input.shape)``.
  257. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  258. don't need to match, but they must be :ref:`broadcastable
  259. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  260. tensor must not be greater than of the :attr:`input` tensor.
  261. Args:
  262. input (Tensor): the input tensor
  263. dim (int): the dimension along which cumulative_prod is computed.
  264. Keyword args:
  265. dtype (:class:`torch.dtype`, optional): the desired data type
  266. of returned tensor. If specified, the input tensor is
  267. casted to :attr:`dtype` before the operation is
  268. performed. Default: None.
  269. mask (:class:`torch.Tensor`, optional): the boolean tensor
  270. containing the binary mask of validity of input tensor
  271. elements.
  272. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  273. Example::
  274. >>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
  275. >>> input
  276. tensor([[-3., -2., -1.],
  277. [ 0., 1., 2.]])
  278. >>> mask = tensor([[ True, False, True], [False, False, False]])
  279. >>> mask
  280. tensor([[ True, False, True],
  281. [False, False, False]])
  282. >>> torch.masked._ops.cumprod(input, 1, mask=mask)
  283. tensor([[-3., -3., 3.],
  284. [ 1., 1., 1.]])
  285. """
  286. cumsum_docstring = """cumsum(input, dim, *, dtype=None, mask=None) -> Tensor
  287. Returns cumulative_sum of all the slices in the :attr:`input` tensor
  288. along :attr:`dim` while the :attr:`input` elements are masked out
  289. according to the boolean tensor :attr:`mask`.
  290. Let ``x`` be a sequence of unmasked elements of one-dimensional slice
  291. of the :attr:`input` tensor. Cumsum of i-th element in ``x`` is
  292. defined as ``sum(x[:i])``.
  293. The boolean tensor :attr:`mask` defines the "validity" of
  294. :attr:`input` tensor elements: if :attr:`mask` element is True then
  295. the corresponding element in :attr:`input` tensor will be included in
  296. cumulative_sum computation, otherwise the element is ignored.
  297. The values of masked-out elements of the output tensor have undefined
  298. value: it may or may not be set to zero or nan; the choice may correspond to
  299. the value that leads to the most efficient storage of :attr:`output`
  300. tensor.
  301. The mask of the cumulative_sum output tensor can be computed as
  302. ``torch.broadcast_to(mask, input.shape)``.
  303. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  304. don't need to match, but they must be :ref:`broadcastable
  305. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  306. tensor must not be greater than of the :attr:`input` tensor.
  307. Args:
  308. input (Tensor): the input tensor
  309. dim (int): the dimension along which cumulative_sum is computed.
  310. Keyword args:
  311. dtype (:class:`torch.dtype`, optional): the desired data type
  312. of returned tensor. If specified, the input tensor is
  313. casted to :attr:`dtype` before the operation is
  314. performed. Default: None.
  315. mask (:class:`torch.Tensor`, optional): the boolean tensor
  316. containing the binary mask of validity of input tensor
  317. elements.
  318. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  319. Example::
  320. >>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
  321. >>> input
  322. tensor([[-3., -2., -1.],
  323. [ 0., 1., 2.]])
  324. >>> mask = tensor([[ True, False, True], [False, False, False]])
  325. >>> mask
  326. tensor([[ True, False, True],
  327. [False, False, False]])
  328. >>> torch.masked._ops.cumsum(input, 1, mask=mask)
  329. tensor([[-3., -3., -4.],
  330. [ 0., 0., 0.]])
  331. """
  332. log_softmax_docstring = """log_softmax(input, dim, *, dtype=None, mask=None) -> Tensor
  333. Returns log_softmax of all the slices in the :attr:`input` tensor
  334. along :attr:`dim` while the :attr:`input` elements are masked out
  335. according to the boolean tensor :attr:`mask`.
  336. Let ``x`` be a sequence of unmasked elements of one-dimensional slice
  337. of the :attr:`input` tensor. LogSoftmax of i-th element in ``x`` is
  338. defined as ``log(exp(x[i])/sum(exp(x)))``.
  339. The boolean tensor :attr:`mask` defines the "validity" of
  340. :attr:`input` tensor elements: if :attr:`mask` element is True then
  341. the corresponding element in :attr:`input` tensor will be included in
  342. log_softmax computation, otherwise the element is ignored.
  343. The values of masked-out elements of the output tensor have undefined
  344. value: it may or may not be set to zero or nan; the choice may correspond to
  345. the value that leads to the most efficient storage of :attr:`output`
  346. tensor.
  347. The mask of the log_softmax output tensor can be computed as
  348. ``torch.broadcast_to(mask, input.shape)``.
  349. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  350. don't need to match, but they must be :ref:`broadcastable
  351. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  352. tensor must not be greater than of the :attr:`input` tensor.
  353. Args:
  354. input (Tensor): the input tensor
  355. dim (int): the dimension along which log_softmax is computed.
  356. Keyword args:
  357. dtype (:class:`torch.dtype`, optional): the desired data type
  358. of returned tensor. If specified, the input tensor is
  359. casted to :attr:`dtype` before the operation is
  360. performed. Default: None.
  361. mask (:class:`torch.Tensor`, optional): the boolean tensor
  362. containing the binary mask of validity of input tensor
  363. elements.
  364. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  365. Example::
  366. >>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
  367. >>> input
  368. tensor([[-3., -2., -1.],
  369. [ 0., 1., 2.]])
  370. >>> mask = tensor([[ True, False, True], [False, False, False]])
  371. >>> mask
  372. tensor([[ True, False, True],
  373. [False, False, False]])
  374. >>> torch.masked._ops.log_softmax(input, 1, mask=mask)
  375. tensor([[-2.1269, -inf, -0.1269],
  376. [ nan, nan, nan]])
  377. """
  378. logsumexp_docstring = """logsumexp(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  379. Returns logsumexp of all the elements in the :attr:`input`
  380. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  381. elements are masked out according to the boolean tensor
  382. :attr:`mask`.
  383. The identity value of logsumexp operation, which is used to start the reduction, is ``-2147483648``.
  384. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  385. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  386. size 1. Otherwise, :attr:`dim` is squeezed (see
  387. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  388. ``len(dim)``) fewer dimension(s).
  389. The boolean tensor :attr:`mask` defines the "validity" of
  390. :attr:`input` tensor elements: if :attr:`mask` element is True
  391. then the corresponding element in :attr:`input` tensor will be
  392. included in logsumexp computation, otherwise the element is
  393. ignored.
  394. When all elements of :attr:`input` along the given dimension
  395. :attr:`dim` are ignored (fully masked-out), the corresponding element
  396. of the output tensor will have undefined value: it may or may not
  397. correspond to the identity value of logsumexp operation; the
  398. choice may correspond to the value that leads to the most efficient
  399. storage of :attr:`output` tensor.
  400. The mask of the output tensor can be computed as
  401. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  402. dtype=torch.bool)``.
  403. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  404. don't need to match, but they must be :ref:`broadcastable
  405. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  406. tensor must not be greater than of the :attr:`input` tensor.
  407. Args:
  408. input (Tensor): the input tensor
  409. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  410. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  411. Keyword args:
  412. keepdim (bool, optional): whether the output tensor has
  413. :attr:`dim` retained or not. Default: False.
  414. dtype (:class:`torch.dtype`, optional): the desired data type
  415. of returned tensor. If specified, the input tensor is
  416. casted to :attr:`dtype` before the operation is
  417. performed. Default: None.
  418. mask (:class:`torch.Tensor`, optional): the boolean tensor
  419. containing the binary mask of validity of input tensor
  420. elements.
  421. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  422. Example::
  423. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  424. >>> input
  425. tensor([[-3, -2, -1],
  426. [ 0, 1, 2]])
  427. >>> mask = tensor([[ True, False, True], [False, False, False]])
  428. >>> mask
  429. tensor([[ True, False, True],
  430. [False, False, False]])
  431. >>> torch.masked._ops.logsumexp(input, 1, mask=mask)
  432. tensor([ 0, -9223372036854775808])
  433. """
  434. mean_docstring = """mean(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  435. Returns mean of all the elements in the :attr:`input`
  436. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  437. elements are masked out according to the boolean tensor
  438. :attr:`mask`.
  439. By definition, the identity value of a mean operation is the mean
  440. value of the tensor. If all elements of the input tensor along given
  441. dimension(s) :attr:`dim` are masked-out, the identity value of the
  442. mean is undefined. Due to this ambiguity, the elements of output
  443. tensor with strided layout, that correspond to fully masked-out
  444. elements, have ``nan`` values.
  445. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  446. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  447. size 1. Otherwise, :attr:`dim` is squeezed (see
  448. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  449. ``len(dim)``) fewer dimension(s).
  450. The boolean tensor :attr:`mask` defines the "validity" of
  451. :attr:`input` tensor elements: if :attr:`mask` element is True
  452. then the corresponding element in :attr:`input` tensor will be
  453. included in mean computation, otherwise the element is
  454. ignored.
  455. When all elements of :attr:`input` along the given dimension
  456. :attr:`dim` are ignored (fully masked-out), the corresponding element
  457. of the output tensor will have undefined value: it may or may not
  458. correspond to the identity value of mean operation; the
  459. choice may correspond to the value that leads to the most efficient
  460. storage of :attr:`output` tensor.
  461. The mask of the output tensor can be computed as
  462. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  463. dtype=torch.bool)``.
  464. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  465. don't need to match, but they must be :ref:`broadcastable
  466. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  467. tensor must not be greater than of the :attr:`input` tensor.
  468. Args:
  469. input (Tensor): the input tensor
  470. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  471. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  472. Keyword args:
  473. keepdim (bool, optional): whether the output tensor has
  474. :attr:`dim` retained or not. Default: False.
  475. dtype (:class:`torch.dtype`, optional): the desired data type
  476. of returned tensor. If specified, the input tensor is
  477. casted to :attr:`dtype` before the operation is
  478. performed. Default: None.
  479. mask (:class:`torch.Tensor`, optional): the boolean tensor
  480. containing the binary mask of validity of input tensor
  481. elements.
  482. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  483. Example::
  484. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  485. >>> input
  486. tensor([[-3, -2, -1],
  487. [ 0, 1, 2]])
  488. >>> mask = tensor([[ True, False, True], [False, False, False]])
  489. >>> mask
  490. tensor([[ True, False, True],
  491. [False, False, False]])
  492. >>> torch.masked._ops.mean(input, 1, mask=mask)
  493. tensor([-2., nan])
  494. """
  495. median_docstring = """median(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  496. Returns median of all the elements in the :attr:`input`
  497. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  498. elements are masked out according to the boolean tensor
  499. :attr:`mask`.
  500. By definition, the identity value of a median operation is the median
  501. value of the tensor. If all elements of the input tensor along given
  502. dimension(s) :attr:`dim` are masked-out, the identity value of the
  503. median is undefined. Due to this ambiguity, the elements of output
  504. tensor with strided layout, that correspond to fully masked-out
  505. elements, have ``nan`` values.
  506. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  507. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  508. size 1. Otherwise, :attr:`dim` is squeezed (see
  509. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  510. ``len(dim)``) fewer dimension(s).
  511. The boolean tensor :attr:`mask` defines the "validity" of
  512. :attr:`input` tensor elements: if :attr:`mask` element is True
  513. then the corresponding element in :attr:`input` tensor will be
  514. included in median computation, otherwise the element is
  515. ignored.
  516. When all elements of :attr:`input` along the given dimension
  517. :attr:`dim` are ignored (fully masked-out), the corresponding element
  518. of the output tensor will have undefined value: it may or may not
  519. correspond to the identity value of median operation; the
  520. choice may correspond to the value that leads to the most efficient
  521. storage of :attr:`output` tensor.
  522. The mask of the output tensor can be computed as
  523. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  524. dtype=torch.bool)``.
  525. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  526. don't need to match, but they must be :ref:`broadcastable
  527. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  528. tensor must not be greater than of the :attr:`input` tensor.
  529. Args:
  530. input (Tensor): the input tensor
  531. dim (int): the dimension along which median is computed.
  532. Keyword args:
  533. keepdim (bool, optional): whether the output tensor has
  534. :attr:`dim` retained or not. Default: False.
  535. dtype (:class:`torch.dtype`, optional): the desired data type
  536. of returned tensor. If specified, the input tensor is
  537. casted to :attr:`dtype` before the operation is
  538. performed. Default: None.
  539. mask (:class:`torch.Tensor`, optional): the boolean tensor
  540. containing the binary mask of validity of input tensor
  541. elements.
  542. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  543. Example::
  544. >>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
  545. >>> input
  546. tensor([[-3., -2., -1.],
  547. [ 0., 1., 2.]])
  548. >>> mask = tensor([[ True, False, True], [False, False, False]])
  549. >>> mask
  550. tensor([[ True, False, True],
  551. [False, False, False]])
  552. >>> torch.masked._ops.median(input, 1, mask=mask)
  553. tensor([-3., nan])
  554. """
  555. norm_docstring = """norm(input, ord, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  556. Returns norm of all the elements in the :attr:`input`
  557. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  558. elements are masked out according to the boolean tensor
  559. :attr:`mask`.
  560. The identity value of norm operation, which is used to start the
  561. reduction, is ``0.0``, except for ``ord=-inf`` it is
  562. ``inf``.
  563. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  564. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  565. size 1. Otherwise, :attr:`dim` is squeezed (see
  566. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  567. ``len(dim)``) fewer dimension(s).
  568. The boolean tensor :attr:`mask` defines the "validity" of
  569. :attr:`input` tensor elements: if :attr:`mask` element is True
  570. then the corresponding element in :attr:`input` tensor will be
  571. included in norm computation, otherwise the element is
  572. ignored.
  573. When all elements of :attr:`input` along the given dimension
  574. :attr:`dim` are ignored (fully masked-out), the corresponding element
  575. of the output tensor will have undefined value: it may or may not
  576. correspond to the identity value of norm operation; the
  577. choice may correspond to the value that leads to the most efficient
  578. storage of :attr:`output` tensor.
  579. The mask of the output tensor can be computed as
  580. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  581. dtype=torch.bool)``.
  582. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  583. don't need to match, but they must be :ref:`broadcastable
  584. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  585. tensor must not be greater than of the :attr:`input` tensor.
  586. Args:
  587. input (Tensor): the input tensor
  588. ord (int, float, optional): the order of vector norm. Default: 2.
  589. See :func:`torch.linalg.vector_norm` for a list of supported norms.
  590. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  591. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  592. Keyword args:
  593. keepdim (bool, optional): whether the output tensor has
  594. :attr:`dim` retained or not. Default: False.
  595. dtype (:class:`torch.dtype`, optional): the desired data type
  596. of returned tensor. If specified, the input tensor is
  597. casted to :attr:`dtype` before the operation is
  598. performed. Default: None.
  599. mask (:class:`torch.Tensor`, optional): the boolean tensor
  600. containing the binary mask of validity of input tensor
  601. elements.
  602. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  603. Example::
  604. >>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
  605. >>> input
  606. tensor([[-3., -2., -1.],
  607. [ 0., 1., 2.]])
  608. >>> mask = tensor([[ True, False, True], [False, False, False]])
  609. >>> mask
  610. tensor([[ True, False, True],
  611. [False, False, False]])
  612. >>> torch.masked._ops.norm(input, 2.0, 1, mask=mask)
  613. tensor([3.1623, 0.0000])
  614. """
  615. normalize_docstring = """normalize(input, ord, dim, *, eps=1e-12, dtype=None, mask=None) -> Tensor
  616. Returns normalize of all the slices in the :attr:`input` tensor
  617. along :attr:`dim` while the :attr:`input` elements are masked out
  618. according to the boolean tensor :attr:`mask`.
  619. Let ``x`` be a sequence of unmasked elements of one-dimensional slice
  620. of the :attr:`input` tensor. Normalize of i-th element in ``x`` is
  621. defined as ``x[i]/max(norm(x, p), eps)``.
  622. The boolean tensor :attr:`mask` defines the "validity" of
  623. :attr:`input` tensor elements: if :attr:`mask` element is True then
  624. the corresponding element in :attr:`input` tensor will be included in
  625. normalize computation, otherwise the element is ignored.
  626. The values of masked-out elements of the output tensor have undefined
  627. value: it may or may not be set to zero or nan; the choice may correspond to
  628. the value that leads to the most efficient storage of :attr:`output`
  629. tensor.
  630. The mask of the normalize output tensor can be computed as
  631. ``torch.broadcast_to(mask, input.shape)``.
  632. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  633. don't need to match, but they must be :ref:`broadcastable
  634. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  635. tensor must not be greater than of the :attr:`input` tensor.
  636. Args:
  637. input (Tensor): the input tensor
  638. ord (int, float): the order of vector norm. Default: 2.
  639. See :func:`torch.linalg.vector_norm` for a list of supported norms.
  640. dim (int): the dimension along which normalize is computed.
  641. Keyword args:
  642. eps (float, optional): small value to avoid division by zero. Default: 1e-12.
  643. dtype (:class:`torch.dtype`, optional): the desired data type
  644. of returned tensor. If specified, the input tensor is
  645. casted to :attr:`dtype` before the operation is
  646. performed. Default: None.
  647. mask (:class:`torch.Tensor`, optional): the boolean tensor
  648. containing the binary mask of validity of input tensor
  649. elements.
  650. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  651. Example::
  652. >>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
  653. >>> input
  654. tensor([[-3., -2., -1.],
  655. [ 0., 1., 2.]])
  656. >>> mask = tensor([[ True, False, True], [False, False, False]])
  657. >>> mask
  658. tensor([[ True, False, True],
  659. [False, False, False]])
  660. >>> torch.masked._ops.normalize(input, 2.0, 1, mask=mask)
  661. tensor([[-0.9487, 0.0000, -0.3162],
  662. [ 0.0000, 0.0000, 0.0000]])
  663. """
  664. prod_docstring = """prod(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  665. Returns product of all the elements in the :attr:`input`
  666. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  667. elements are masked out according to the boolean tensor
  668. :attr:`mask`.
  669. The identity value of product operation, which is used to start the reduction, is ``1``.
  670. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  671. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  672. size 1. Otherwise, :attr:`dim` is squeezed (see
  673. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  674. ``len(dim)``) fewer dimension(s).
  675. The boolean tensor :attr:`mask` defines the "validity" of
  676. :attr:`input` tensor elements: if :attr:`mask` element is True
  677. then the corresponding element in :attr:`input` tensor will be
  678. included in product computation, otherwise the element is
  679. ignored.
  680. When all elements of :attr:`input` along the given dimension
  681. :attr:`dim` are ignored (fully masked-out), the corresponding element
  682. of the output tensor will have undefined value: it may or may not
  683. correspond to the identity value of product operation; the
  684. choice may correspond to the value that leads to the most efficient
  685. storage of :attr:`output` tensor.
  686. The mask of the output tensor can be computed as
  687. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  688. dtype=torch.bool)``.
  689. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  690. don't need to match, but they must be :ref:`broadcastable
  691. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  692. tensor must not be greater than of the :attr:`input` tensor.
  693. Args:
  694. input (Tensor): the input tensor
  695. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  696. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  697. Keyword args:
  698. keepdim (bool, optional): whether the output tensor has
  699. :attr:`dim` retained or not. Default: False.
  700. dtype (:class:`torch.dtype`, optional): the desired data type
  701. of returned tensor. If specified, the input tensor is
  702. casted to :attr:`dtype` before the operation is
  703. performed. Default: None.
  704. mask (:class:`torch.Tensor`, optional): the boolean tensor
  705. containing the binary mask of validity of input tensor
  706. elements.
  707. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  708. Example::
  709. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  710. >>> input
  711. tensor([[-3, -2, -1],
  712. [ 0, 1, 2]])
  713. >>> mask = tensor([[ True, False, True], [False, False, False]])
  714. >>> mask
  715. tensor([[ True, False, True],
  716. [False, False, False]])
  717. >>> torch.masked._ops.prod(input, 1, mask=mask)
  718. tensor([3, 1])
  719. """
  720. softmax_docstring = """softmax(input, dim, *, dtype=None, mask=None) -> Tensor
  721. Returns softmax of all the slices in the :attr:`input` tensor
  722. along :attr:`dim` while the :attr:`input` elements are masked out
  723. according to the boolean tensor :attr:`mask`.
  724. Let ``x`` be a sequence of unmasked elements of one-dimensional slice
  725. of the :attr:`input` tensor. Softmax of i-th element in ``x`` is
  726. defined as ``exp(x[i])/sum(exp(x))``.
  727. The boolean tensor :attr:`mask` defines the "validity" of
  728. :attr:`input` tensor elements: if :attr:`mask` element is True then
  729. the corresponding element in :attr:`input` tensor will be included in
  730. softmax computation, otherwise the element is ignored.
  731. The values of masked-out elements of the output tensor have undefined
  732. value: it may or may not be set to zero or nan; the choice may correspond to
  733. the value that leads to the most efficient storage of :attr:`output`
  734. tensor.
  735. The mask of the softmax output tensor can be computed as
  736. ``torch.broadcast_to(mask, input.shape)``.
  737. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  738. don't need to match, but they must be :ref:`broadcastable
  739. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  740. tensor must not be greater than of the :attr:`input` tensor.
  741. Args:
  742. input (Tensor): the input tensor
  743. dim (int): the dimension along which softmax is computed.
  744. Keyword args:
  745. dtype (:class:`torch.dtype`, optional): the desired data type
  746. of returned tensor. If specified, the input tensor is
  747. casted to :attr:`dtype` before the operation is
  748. performed. Default: None.
  749. mask (:class:`torch.Tensor`, optional): the boolean tensor
  750. containing the binary mask of validity of input tensor
  751. elements.
  752. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  753. Example::
  754. >>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
  755. >>> input
  756. tensor([[-3., -2., -1.],
  757. [ 0., 1., 2.]])
  758. >>> mask = tensor([[ True, False, True], [False, False, False]])
  759. >>> mask
  760. tensor([[ True, False, True],
  761. [False, False, False]])
  762. >>> torch.masked._ops.softmax(input, 1, mask=mask)
  763. tensor([[0.1192, 0.0000, 0.8808],
  764. [ nan, nan, nan]])
  765. """
  766. softmin_docstring = """softmin(input, dim, *, dtype=None, mask=None) -> Tensor
  767. Returns softmin of all the slices in the :attr:`input` tensor
  768. along :attr:`dim` while the :attr:`input` elements are masked out
  769. according to the boolean tensor :attr:`mask`.
  770. Let ``x`` be a sequence of unmasked elements of one-dimensional slice
  771. of the :attr:`input` tensor. Softmin of i-th element in ``x`` is
  772. defined as ``exp(-x[i])/sum(exp(-x))``.
  773. The boolean tensor :attr:`mask` defines the "validity" of
  774. :attr:`input` tensor elements: if :attr:`mask` element is True then
  775. the corresponding element in :attr:`input` tensor will be included in
  776. softmin computation, otherwise the element is ignored.
  777. The values of masked-out elements of the output tensor have undefined
  778. value: it may or may not be set to zero or nan; the choice may correspond to
  779. the value that leads to the most efficient storage of :attr:`output`
  780. tensor.
  781. The mask of the softmin output tensor can be computed as
  782. ``torch.broadcast_to(mask, input.shape)``.
  783. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  784. don't need to match, but they must be :ref:`broadcastable
  785. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  786. tensor must not be greater than of the :attr:`input` tensor.
  787. Args:
  788. input (Tensor): the input tensor
  789. dim (int): the dimension along which softmin is computed.
  790. Keyword args:
  791. dtype (:class:`torch.dtype`, optional): the desired data type
  792. of returned tensor. If specified, the input tensor is
  793. casted to :attr:`dtype` before the operation is
  794. performed. Default: None.
  795. mask (:class:`torch.Tensor`, optional): the boolean tensor
  796. containing the binary mask of validity of input tensor
  797. elements.
  798. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  799. Example::
  800. >>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
  801. >>> input
  802. tensor([[-3., -2., -1.],
  803. [ 0., 1., 2.]])
  804. >>> mask = tensor([[ True, False, True], [False, False, False]])
  805. >>> mask
  806. tensor([[ True, False, True],
  807. [False, False, False]])
  808. >>> torch.masked._ops.softmin(input, 1, mask=mask)
  809. tensor([[0.8808, 0.0000, 0.1192],
  810. [ nan, nan, nan]])
  811. """
  812. std_docstring = """std(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) -> Tensor
  813. Returns standard_deviation of all the elements in the :attr:`input`
  814. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  815. elements are masked out according to the boolean tensor
  816. :attr:`mask`.
  817. The identity value of sample standard deviation operation is undefined. The
  818. elements of output tensor with strided layout, that correspond to
  819. fully masked-out elements, have ``nan`` values.
  820. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  821. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  822. size 1. Otherwise, :attr:`dim` is squeezed (see
  823. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  824. ``len(dim)``) fewer dimension(s).
  825. The boolean tensor :attr:`mask` defines the "validity" of
  826. :attr:`input` tensor elements: if :attr:`mask` element is True
  827. then the corresponding element in :attr:`input` tensor will be
  828. included in standard_deviation computation, otherwise the element is
  829. ignored.
  830. When all elements of :attr:`input` along the given dimension
  831. :attr:`dim` are ignored (fully masked-out), the corresponding element
  832. of the output tensor will have undefined value: it may or may not
  833. correspond to the identity value of standard_deviation operation; the
  834. choice may correspond to the value that leads to the most efficient
  835. storage of :attr:`output` tensor.
  836. The mask of the output tensor can be computed as
  837. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  838. dtype=torch.bool)``.
  839. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  840. don't need to match, but they must be :ref:`broadcastable
  841. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  842. tensor must not be greater than of the :attr:`input` tensor.
  843. Args:
  844. input (Tensor): the input tensor
  845. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  846. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  847. unbiased (bool): when True, use Bessel's correction, otherwise, compute
  848. the uncorrected sample variance.
  849. Keyword args:
  850. keepdim (bool, optional): whether the output tensor has
  851. :attr:`dim` retained or not. Default: False.
  852. dtype (:class:`torch.dtype`, optional): the desired data type
  853. of returned tensor. If specified, the input tensor is
  854. casted to :attr:`dtype` before the operation is
  855. performed. Default: None.
  856. mask (:class:`torch.Tensor`, optional): the boolean tensor
  857. containing the binary mask of validity of input tensor
  858. elements.
  859. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  860. Example::
  861. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  862. >>> input
  863. tensor([[-3, -2, -1],
  864. [ 0, 1, 2]])
  865. >>> mask = tensor([[ True, False, True], [False, False, False]])
  866. >>> mask
  867. tensor([[ True, False, True],
  868. [False, False, False]])
  869. >>> torch.masked._ops.std(input, 1, False, mask=mask)
  870. tensor([1., nan])
  871. """
  872. sum_docstring = """sum(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
  873. Returns sum of all the elements in the :attr:`input`
  874. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  875. elements are masked out according to the boolean tensor
  876. :attr:`mask`.
  877. The identity value of sum operation, which is used to start the reduction, is ``0``.
  878. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  879. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  880. size 1. Otherwise, :attr:`dim` is squeezed (see
  881. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  882. ``len(dim)``) fewer dimension(s).
  883. The boolean tensor :attr:`mask` defines the "validity" of
  884. :attr:`input` tensor elements: if :attr:`mask` element is True
  885. then the corresponding element in :attr:`input` tensor will be
  886. included in sum computation, otherwise the element is
  887. ignored.
  888. When all elements of :attr:`input` along the given dimension
  889. :attr:`dim` are ignored (fully masked-out), the corresponding element
  890. of the output tensor will have undefined value: it may or may not
  891. correspond to the identity value of sum operation; the
  892. choice may correspond to the value that leads to the most efficient
  893. storage of :attr:`output` tensor.
  894. The mask of the output tensor can be computed as
  895. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  896. dtype=torch.bool)``.
  897. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  898. don't need to match, but they must be :ref:`broadcastable
  899. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  900. tensor must not be greater than of the :attr:`input` tensor.
  901. Args:
  902. input (Tensor): the input tensor
  903. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  904. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  905. Keyword args:
  906. keepdim (bool, optional): whether the output tensor has
  907. :attr:`dim` retained or not. Default: False.
  908. dtype (:class:`torch.dtype`, optional): the desired data type
  909. of returned tensor. If specified, the input tensor is
  910. casted to :attr:`dtype` before the operation is
  911. performed. Default: None.
  912. mask (:class:`torch.Tensor`, optional): the boolean tensor
  913. containing the binary mask of validity of input tensor
  914. elements.
  915. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  916. Example::
  917. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  918. >>> input
  919. tensor([[-3, -2, -1],
  920. [ 0, 1, 2]])
  921. >>> mask = tensor([[ True, False, True], [False, False, False]])
  922. >>> mask
  923. tensor([[ True, False, True],
  924. [False, False, False]])
  925. >>> torch.masked._ops.sum(input, 1, mask=mask)
  926. tensor([-4, 0])
  927. """
  928. var_docstring = """var(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) -> Tensor
  929. Returns variance of all the elements in the :attr:`input`
  930. tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
  931. elements are masked out according to the boolean tensor
  932. :attr:`mask`.
  933. The identity value of sample variance operation is undefined. The
  934. elements of output tensor with strided layout, that correspond to
  935. fully masked-out elements, have ``nan`` values.
  936. If :attr:`keepdim` is ``True``, the output tensor is of the same size
  937. as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
  938. size 1. Otherwise, :attr:`dim` is squeezed (see
  939. :func:`torch.squeeze`), resulting in the output tensor having 1 (or
  940. ``len(dim)``) fewer dimension(s).
  941. The boolean tensor :attr:`mask` defines the "validity" of
  942. :attr:`input` tensor elements: if :attr:`mask` element is True
  943. then the corresponding element in :attr:`input` tensor will be
  944. included in variance computation, otherwise the element is
  945. ignored.
  946. When all elements of :attr:`input` along the given dimension
  947. :attr:`dim` are ignored (fully masked-out), the corresponding element
  948. of the output tensor will have undefined value: it may or may not
  949. correspond to the identity value of variance operation; the
  950. choice may correspond to the value that leads to the most efficient
  951. storage of :attr:`output` tensor.
  952. The mask of the output tensor can be computed as
  953. ``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
  954. dtype=torch.bool)``.
  955. The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
  956. don't need to match, but they must be :ref:`broadcastable
  957. <broadcasting-semantics>` and the dimensionality of the :attr:`mask`
  958. tensor must not be greater than of the :attr:`input` tensor.
  959. Args:
  960. input (Tensor): the input tensor
  961. dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
  962. Default: None that is equivalent to ``tuple(range(input.ndim))``.
  963. unbiased (bool): when True, use Bessel's correction, otherwise, compute
  964. the uncorrected sample variance.
  965. Keyword args:
  966. keepdim (bool, optional): whether the output tensor has
  967. :attr:`dim` retained or not. Default: False.
  968. dtype (:class:`torch.dtype`, optional): the desired data type
  969. of returned tensor. If specified, the input tensor is
  970. casted to :attr:`dtype` before the operation is
  971. performed. Default: None.
  972. mask (:class:`torch.Tensor`, optional): the boolean tensor
  973. containing the binary mask of validity of input tensor
  974. elements.
  975. Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
  976. Example::
  977. >>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
  978. >>> input
  979. tensor([[-3, -2, -1],
  980. [ 0, 1, 2]])
  981. >>> mask = tensor([[ True, False, True], [False, False, False]])
  982. >>> mask
  983. tensor([[ True, False, True],
  984. [False, False, False]])
  985. >>> torch.masked._ops.var(input, 1, False, mask=mask)
  986. tensor([1., nan])
  987. """