Skip to content

Commit c414bf0

Browse files
authored
Fix handling of unicode in torch._C._add_docstr (pytorch#487)
1 parent 99f4864 commit c414bf0

File tree

5 files changed

+81
-68
lines changed

5 files changed

+81
-68
lines changed

docs/source/torch.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ Indexing, Slicing, Joining, Mutating Ops
3232
.. autofunction:: index_select
3333
.. autofunction:: masked_select
3434
.. autofunction:: nonzero
35-
.. autofunction:: scatter
3635
.. autofunction:: split
3736
.. autofunction:: squeeze
3837
.. autofunction:: stack
3938
.. autofunction:: t
4039
.. autofunction:: transpose
41-
.. autofunction:: unfold
4240

4341

4442
Random sampling

torch/_tensor_docs.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -760,17 +760,17 @@
760760
In-place version of :meth:`~Tensor.log`
761761
""")
762762

763-
add_docstr(torch._C.FloatTensorBase.log_normal_, r"""
763+
add_docstr(torch._C.FloatTensorBase.log_normal_, u"""
764764
log_normal_(generator=None, mean=1, stdv=2)
765765
766766
Fills this tensor with numbers samples from the log-normal distribution
767-
parameterized by the given mean (µ) and standard deviation (σ). Note that
767+
parameterized by the given mean (\u00B5) and standard deviation (\u03C3). Note that
768768
:attr:`mean` and :attr:`stdv` are the mean and standard deviation of the
769769
underlying normal distribution, and not of the returned distribution:
770770
771771
.. math::
772772
773-
P(x) = \dfrac{1}{x \sigma \sqrt{2\pi}} e^{-\dfrac{(\ln x - \mu)^2}{2\sigma^2}}
773+
P(x) = \\dfrac{1}{x \\sigma \\sqrt{2\\pi}} e^{-\\dfrac{(\\ln x - \\mu)^2}{2\\sigma^2}}
774774
""")
775775

776776
add_docstr(torch._C.FloatTensorBase.lt,
@@ -1199,8 +1199,8 @@ def callable(a, b) -> number
11991199
scatter_(input, dim, index, src) -> Tensor
12001200
12011201
Writes all values from the Tensor :attr:`src` into self at the indices specified
1202-
in the :attr:`index` Tensor. The indices are specified with respect to the
1203-
given dimension, dim, in the manner described in :meth:`~Tensor.gather`.
1202+
in the :attr:`index` Tensor. The indices are specified with respect to the
1203+
given dimension, dim, in the manner described in :meth:`~Tensor.gather`.
12041204
12051205
Note that, as for gather, the values of index must be between `0` and `(self.size(dim) -1)`
12061206
inclusive and all values in a row along the specified dimension must be unique.
@@ -1215,25 +1215,25 @@ def callable(a, b) -> number
12151215
12161216
>>> x = torch.rand(2, 5)
12171217
>>> x
1218-
1218+
12191219
0.4319 0.6500 0.4080 0.8760 0.2355
12201220
0.2609 0.4711 0.8486 0.8573 0.1029
12211221
[torch.FloatTensor of size 2x5]
1222-
1222+
12231223
>>> torch.zeros(3, 5).scatter_(0, torch.LongTensor([[0, 1, 2, 0, 0], [2, 0, 0, 1, 2]]), x)
1224-
1224+
12251225
0.4319 0.4711 0.8486 0.8760 0.2355
12261226
0.0000 0.6500 0.0000 0.8573 0.0000
12271227
0.2609 0.0000 0.4080 0.0000 0.1029
12281228
[torch.FloatTensor of size 3x5]
1229-
1229+
12301230
>>> z = torch.zeros(2, 4).scatter_(1, torch.LongTensor([[2], [3]]), 1.23)
12311231
>>> z
1232-
1232+
12331233
0.0000 0.0000 1.2300 0.0000
12341234
0.0000 0.0000 0.0000 1.2300
12351235
[torch.FloatTensor of size 2x4]
1236-
1236+
12371237
""")
12381238

12391239
add_docstr(torch._C.FloatTensorBase.select,
@@ -1580,12 +1580,12 @@ def callable(a, b) -> number
15801580
"""
15811581
unfold(dim, size, step) -> Tensor
15821582
1583-
Returns a tensor which contains all slices of size :attr:`size` in
1584-
the dimension :attr:`dim`.
1583+
Returns a tensor which contains all slices of size :attr:`size` in
1584+
the dimension :attr:`dim`.
15851585
15861586
Step between two slices is given by :attr:`step`.
15871587
1588-
If `sizedim` is the original size of dimension dim, the size of dimension `dim`
1588+
If `sizedim` is the original size of dimension dim, the size of dimension `dim`
15891589
in the returned tensor will be `(sizedim - size) / step + 1`
15901590
15911591
An additional dimension of size size is appended in the returned tensor.
@@ -1599,7 +1599,7 @@ def callable(a, b) -> number
15991599
16001600
>>> x = torch.range(1, 7)
16011601
>>> x
1602-
1602+
16031603
1
16041604
2
16051605
3
@@ -1608,24 +1608,24 @@ def callable(a, b) -> number
16081608
6
16091609
7
16101610
[torch.FloatTensor of size 7]
1611-
1611+
16121612
>>> x.unfold(0, 2, 1)
1613-
1613+
16141614
1 2
16151615
2 3
16161616
3 4
16171617
4 5
16181618
5 6
16191619
6 7
16201620
[torch.FloatTensor of size 6x2]
1621-
1621+
16221622
>>> x.unfold(0, 2, 2)
1623-
1623+
16241624
1 2
16251625
3 4
16261626
5 6
16271627
[torch.FloatTensor of size 3x2]
1628-
1628+
16291629
""")
16301630

16311631
add_docstr(torch._C.FloatTensorBase.uniform_,

torch/_torch_docs.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,29 +2387,30 @@
23872387
""")
23882388

23892389
add_docstr(torch._C.multinomial,
2390-
"""
2390+
u"""
23912391
multinomial(input, num_samples, replacement=False, out=None) -> LongTensor
23922392
23932393
Returns a Tensor where each row
23942394
contains :attr:`num_samples` indices sampled from the multinomial probability distribution
23952395
located in the corresponding row of Tensor :attr:`input`.
23962396
2397-
.. note:: The rows of :attr:`input` do not need to sum to one (in which case we use the values
2398-
as weights), but must be non-negative and have a non-zero sum.
2397+
.. note::
2398+
The rows of :attr:`input` do not need to sum to one (in which case we use the values
2399+
as weights), but must be non-negative and have a non-zero sum.
23992400
24002401
Indices are ordered from left to right according to when each was sampled
24012402
(first samples are placed in first column).
24022403
24032404
If :attr:`input` is a vector, :attr:`out` is a matrix of size `num_samples`.
24042405
2405-
If :attr:`input` is a matrix with `m` rows, :attr:`out` is an matrix of shape `m × n`.
2406+
If :attr:`input` is a matrix with `m` rows, :attr:`out` is an matrix of shape `m \u00D7 n`.
24062407
24072408
If replacement is `True`, samples are drawn with replacement.
24082409
24092410
If not, they are drawn without replacement, which means that when a
24102411
sample index is drawn for a row, it cannot be drawn again for that row.
24112412
2412-
This implies the constraint that :attr:`num_samples` must be lower than :attr:`input` length
2413+
This implies the constraint that :attr:`num_samples` must be lower than :attr:`input` length
24132414
(or number of columns of :attr:`input` if it is a matrix).
24142415
24152416
Args:
@@ -2422,21 +2423,21 @@
24222423
24232424
>>> weights = torch.Tensor([0, 10, 3, 0]) # create a Tensor of weights
24242425
>>> torch.multinomial(weights, 4)
2425-
2426+
24262427
1
24272428
2
24282429
0
24292430
0
24302431
[torch.LongTensor of size 4]
2431-
2432+
24322433
>>> torch.multinomial(weights, 4, replacement=True)
2433-
2434+
24342435
1
24352436
2
24362437
1
24372438
2
24382439
[torch.LongTensor of size 4]
2439-
2440+
24402441
""")
24412442

24422443
add_docstr(torch._C.mv,
@@ -2627,10 +2628,10 @@
26272628
Returns a Tensor of random numbers drawn from separate normal distributions
26282629
who's mean and standard deviation are given.
26292630
2630-
The :attr:`means` is a Tensor with the mean of
2631+
The :attr:`means` is a Tensor with the mean of
26312632
each output element's normal distribution
26322633
2633-
The :attr:`stddevs` is a Tensor with the standard deviation of
2634+
The :attr:`stddevs` is a Tensor with the standard deviation of
26342635
each output element's normal distribution
26352636
26362637
The shapes of :attr:`means` and :attr:`stddevs` don't need to match.
@@ -2647,7 +2648,7 @@
26472648
Example::
26482649
26492650
torch.normal(means=torch.range(1, 10), stddevs=torch.range(1, 0.1, -0.1))
2650-
2651+
26512652
1.5104
26522653
1.6955
26532654
2.4895
@@ -2672,7 +2673,7 @@
26722673
Example::
26732674
26742675
>>> torch.normal(mean=0.5, stddevs=torch.range(1, 5))
2675-
2676+
26762677
0.5723
26772678
0.0871
26782679
-0.3783
@@ -2685,21 +2686,21 @@
26852686
Similar to the function above, but the standard-deviations are shared among all drawn elements.
26862687
26872688
Args:
2688-
means (Tensor): the Tensor of per-element means
2689+
means (Tensor): the Tensor of per-element means
26892690
stddevs (float, optional): the standard deviation for all distributions
26902691
out (Tensor): the optional result Tensor
26912692
26922693
Example::
26932694
26942695
>>> torch.normal(means=torch.range(1, 5))
2695-
2696+
26962697
1.1681
26972698
2.8884
26982699
3.7718
26992700
2.5616
27002701
4.2500
27012702
[torch.FloatTensor of size 5]
2702-
2703+
27032704
""")
27042705

27052706
add_docstr(torch._C.numel,
@@ -2730,26 +2731,26 @@
27302731
by the varargs :attr:`sizes`.
27312732
27322733
Args:
2733-
sizes (*int): a set of ints defining the shape of the output Tensor.
2734+
sizes (int...): a set of ints defining the shape of the output Tensor.
27342735
out (Tensor, optional): the result Tensor
27352736
27362737
Example::
27372738
27382739
>>> torch.ones(2, 3)
2739-
2740+
27402741
1 1 1
27412742
1 1 1
27422743
[torch.FloatTensor of size 2x3]
2743-
2744+
27442745
>>> torch.ones(5)
2745-
2746+
27462747
1
27472748
1
27482749
1
27492750
1
27502751
1
27512752
[torch.FloatTensor of size 5]
2752-
2753+
27532754
""")
27542755

27552756
add_docstr(torch._C.orgqr,
@@ -2938,25 +2939,25 @@
29382939
The shape of the Tensor is defined by the varargs :attr:`sizes`.
29392940
29402941
Args:
2941-
sizes (*int): a set of ints defining the shape of the output Tensor.
2942+
sizes (int...): a set of ints defining the shape of the output Tensor.
29422943
out (Tensor, optional): the result Tensor
29432944
29442945
Example::
29452946
29462947
>>> torch.rand(4)
2947-
2948+
29482949
0.9193
29492950
0.3347
29502951
0.3232
29512952
0.7715
29522953
[torch.FloatTensor of size 4]
2953-
2954+
29542955
>>> torch.rand(2, 3)
2955-
2956+
29562957
0.5010 0.5140 0.0719
29572958
0.1435 0.5636 0.0538
29582959
[torch.FloatTensor of size 2x3]
2959-
2960+
29602961
""")
29612962

29622963
add_docstr(torch._C.randn,
@@ -2969,25 +2970,25 @@
29692970
The shape of the Tensor is defined by the varargs :attr:`sizes`.
29702971
29712972
Args:
2972-
sizes (*int): a set of ints defining the shape of the output Tensor.
2973+
sizes (int...): a set of ints defining the shape of the output Tensor.
29732974
out (Tensor, optional): the result Tensor
29742975
29752976
Example::
29762977
29772978
>>> torch.randn(4)
2978-
2979+
29792980
-0.1145
29802981
0.0094
29812982
-1.1717
29822983
0.9846
29832984
[torch.FloatTensor of size 4]
2984-
2985+
29852986
>>> torch.randn(2, 3)
2986-
2987+
29872988
1.4339 0.3351 -1.0999
29882989
1.5458 -0.9643 -0.3558
29892990
[torch.FloatTensor of size 2x3]
2990-
2991+
29912992
""")
29922993

29932994
add_docstr(torch._C.randperm,
@@ -3939,24 +3940,24 @@
39393940
by the varargs :attr:`sizes`.
39403941
39413942
Args:
3942-
sizes (*int): a set of ints defining the shape of the output Tensor.
3943+
sizes (int...): a set of ints defining the shape of the output Tensor.
39433944
out (Tensor, optional): the result Tensor
39443945
39453946
Example::
39463947
39473948
>>> torch.zeros(2, 3)
3948-
3949+
39493950
0 0 0
39503951
0 0 0
39513952
[torch.FloatTensor of size 2x3]
3952-
3953+
39533954
>>> torch.zeros(5)
3954-
3955+
39553956
0
39563957
0
39573958
0
39583959
0
39593960
0
39603961
[torch.FloatTensor of size 5]
3961-
3962+
39623963
""")

0 commit comments

Comments
 (0)