Skip to content

Commit 35ece26

Browse files
weiyangfbPenghuiCheng
authored andcommitted
fix doc for as_tensor (pytorch#10309)
Summary: - fixes pytorch#9914 Pull Request resolved: pytorch#10309 Differential Revision: D9196427 Pulled By: weiyangfb fbshipit-source-id: c9a01e42c2e9dbfe2bd94ad14651d9f578751de2
1 parent dc27635 commit 35ece26

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

torch/_torch_docs.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,21 @@ def parse_kwargs(desc):
425425
426426
Example::
427427
428-
>>> torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
429-
tensor([[ 0.1000, 1.2000],
430-
[ 2.2000, 3.1000],
431-
[ 4.9000, 5.2000]])
432-
433428
>>> a = numpy.array([1, 2, 3])
434-
>>> t = torch.from_numpy(a)
429+
>>> t = torch.as_tensor(a)
435430
>>> t
436431
tensor([ 1, 2, 3])
437432
>>> t[0] = -1
438433
>>> a
439434
array([-1, 2, 3])
435+
436+
>>> a = numpy.array([1, 2, 3])
437+
>>> t = torch.as_tensor(a, device=torch.device('cuda'))
438+
>>> t
439+
tensor([ 1, 2, 3])
440+
>>> t[0] = -1
441+
>>> a
442+
array([1, 2, 3])
440443
""".format(**factory_data_common_args))
441444

442445
add_docstr(torch.asin,

0 commit comments

Comments
 (0)