Skip to content

Commit 9c01f5d

Browse files
ezyangapaszke
authored andcommitted
Document hybrid sparse tensors.
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
1 parent cbb9f08 commit 9c01f5d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

docs/source/sparse.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,25 @@ by providing these two tensors, as well as the size of the sparse tensor
2121
>>> i = torch.LongTensor([[0, 1], [2, 0]])
2222
>>> v = torch.FloatTensor([3, 4])
2323
>>> torch.sparse.FloatTensor(i, v, torch.Size([2,3])).to_dense()
24-
0 0 3
25-
4 0 0
24+
25+
0 0 3
26+
4 0 0
2627
[torch.FloatTensor of size 2x2]
2728

29+
You can also construct hybrid sparse tensors, where only the first n
30+
dimensions are sparse, and the rest of the dimensions are dense.
31+
32+
>>> i = torch.LongTensor([[2, 4]])
33+
>>> v = torch.FloatTensor([[1, 3], [5, 7]])
34+
>>> torch.sparse.FloatTensor(i, v).to_dense()
35+
36+
0 0
37+
0 0
38+
1 3
39+
0 0
40+
5 7
41+
[torch.FloatTensor of size 5x2]
42+
2843
An empty sparse tensor can be constructed by specifying its size:
2944

3045
>>> torch.sparse.FloatTensor(2, 3)

0 commit comments

Comments
 (0)