Prompt48 commited on
Commit
af37e18
·
verified ·
1 Parent(s): a81b876

Upload edit\Qwen3-TTS-test\.venv\Lib\site-packages\torch\masked\_docs.py with huggingface_hub

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