-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.py
More file actions
38 lines (23 loc) · 661 Bytes
/
notes.py
File metadata and controls
38 lines (23 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import torch
# install with pip3 install torch
v = torch.Tensor([1,2,3,4])
m = torch.Tensor([[1,2],[3,4]])
v.shape
m.shape
# componentwise multiplication
v * v
# @ symbol for matrix multiplication
y = torch.ones([3,4])
x = torch.zeros([1,4])
x.t() # transpose
# this all only works on dense matrices
# how do you construct a sparse matrix?
i = torch.LongTensor([[0,1,1],[2,0,2]])
v = torch.FloatTensor([3,4,5])
z = torch.sparse.FloatTensor(i,v, torch.Size([2,3]))
torch.sparse.mm # function for matrix - matrix multiplication, first matrix is sparse
print("123")
# equivalent
torch.sparse.mm(z.t(), m.t()).t()
torch.sparse.addmm
m @ z.to_dense()