_docs.py 48 KB

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