-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathconversions.yaml
252 lines (251 loc) · 6.09 KB
/
conversions.yaml
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
types:
- numpy: np.ndarray
pytorch: torch.Tensor
- numpy: np.float32
pytorch: torch.float32; torch.float
- numpy: np.float64
pytorch: torch.float64; torch.double
- numpy: np.float16
pytorch: torch.float16; torch.half
- numpy: np.int8
pytorch: torch.int8
- numpy: np.uint8
pytorch: torch.uint8
- numpy: np.int16
pytorch: torch.int16; torch.short
- numpy: np.int32
pytorch: torch.int32; torch.int
- numpy: np.int64
pytorch: torch.int64; torch.long
ones and zeros:
- numpy: np.empty((2, 3))
pytorch: torch.empty(2, 3)
- numpy: np.empty_like(x)
pytorch: torch.empty_like(x)
- numpy: np.eye
pytorch: torch.eye
- numpy: np.identity
pytorch: torch.eye
- numpy: np.ones
pytorch: torch.ones
- numpy: np.ones_like
pytorch: torch.ones_like
- numpy: np.zeros
pytorch: torch.zeros
- numpy: np.zeros_like
pytorch: torch.zeros_like
from existing data:
- numpy: np.array([[1, 2], [3, 4]])
pytorch: torch.tensor([[1, 2], [3, 4]])
- numpy: |
np.array([3.2, 4.3], dtype=np.float16)
np.float16([3.2, 4.3])
pytorch: torch.tensor([3.2, 4.3], dtype=torch.float16)
- numpy: x.copy()
pytorch: x.clone()
- numpy: x.astype(np.float32)
pytorch: x.type(torch.float32); x.float()
- numpy:
content: np.fromfile(file)
skip_test: true
pytorch:
content: torch.tensor(torch.Storage(file))
skip_test: true
- numpy: np.frombuffer
pytorch:
- numpy: np.fromfunction
pytorch:
- numpy: np.fromiter
pytorch:
- numpy: np.fromstring
pytorch:
- numpy: np.load
pytorch: torch.load
- numpy: np.loadtxt
pytorch:
- numpy: np.concatenate
pytorch: torch.cat
numerical ranges:
- numpy: np.arange(10)
pytorch: torch.arange(10)
- numpy: np.arange(2, 3, 0.1)
pytorch: torch.arange(2, 3, 0.1)
- numpy: np.linspace
pytorch: torch.linspace
- numpy: np.logspace
pytorch: torch.logspace
linear algebra:
- numpy: np.dot
pytorch: |
torch.dot # 1D arrays only
torch.mm # 2D arrays only
torch.mv # matrix-vector (2D x 1D)
- numpy: np.matmul
pytorch: torch.matmul
- numpy: np.tensordot
pytorch: torch.tensordot
- numpy: np.einsum
pytorch: torch.einsum
building matrices:
- numpy: np.diag
pytorch: torch.diag
- numpy: np.tril
pytorch: torch.tril
- numpy: np.triu
pytorch: torch.triu
attributes:
- numpy: x.shape
pytorch: x.shape; x.size()
- numpy: x.strides
pytorch: x.stride()
- numpy: x.ndim
pytorch: x.dim()
- numpy: x.data
pytorch: x.data
- numpy: x.size
pytorch: x.nelement()
- numpy: x.dtype
pytorch: x.dtype
indexing:
- numpy: x[0]
pytorch: x[0]
- numpy: x[:, 0]
pytorch: x[:, 0]
- numpy:
content: x[indices]
skip_test: true
pytorch:
content: x[indices]
skip_test: true
- numpy:
content: np.take(x, indices)
skip_test: true
pytorch:
content: torch.take(x, torch.LongTensor(indices))
skip_test: true
- numpy: x[x != 0]
pytorch: x[x != 0]
shape manipulation:
- numpy: x.reshape
pytorch: x.reshape; x.view
- numpy: x.resize()
pytorch: x.resize_
- numpy:
pytorch: x.resize_as_
- numpy: |
x = np.arange(6).reshape(3, 2, 1)
x.transpose(2, 0, 1) # 012 -> 201
pytorch: |
x = torch.arange(6).reshape(3, 2, 1)
x.permute(2, 0, 1); x.transpose(1, 2).transpose(0, 1) # 012 -> 021 -> 201
- numpy: x.flatten
pytorch: x.view(-1)
- numpy: x.squeeze()
pytorch: x.squeeze()
- numpy: x[:, None]; np.expand_dims(x, 1)
pytorch: x[:, None]; x.unsqueeze(1)
item selection and manipulation:
- numpy: np.put
pytorch:
- numpy: x.put
pytorch: x.put_
- numpy: |
x = np.array([1, 2, 3])
x.repeat(2) # [1, 1, 2, 2, 3, 3]
pytorch: |
x = torch.tensor([1, 2, 3])
x.repeat_interleave(2) # [1, 1, 2, 2, 3, 3]
x.repeat(2) # [1, 2, 3, 1, 2, 3]
x.repeat(2).reshape(2, -1).transpose(1, 0).reshape(-1)
# [1, 1, 2, 2, 3, 3]
- numpy: np.tile(x, (3, 2))
pytorch: x.repeat(3, 2)
- numpy: |
x = np.array([[0, 1], [2, 3], [4, 5]])
idxs = np.array([0, 2])
np.choose(idxs, x) # [0, 5]
pytorch: |
x = torch.tensor([[0, 1], [2, 3], [4, 5]])
idxs = torch.tensor([0, 2])
x[idxs, torch.arange(x.shape[1])] # [0, 5]
torch.gather(x, 0, idxs[None, :])[0] # [0, 5]
- numpy: np.sort
pytorch:
content: sorted, indices = torch.sort(x, [dim])
skip_test: true
- numpy: np.argsort
pytorch:
content: sorted, indices = torch.sort(x, [dim])
skip_test: true
- numpy: np.nonzero
pytorch: torch.nonzero
- numpy: np.where
pytorch: torch.where
- numpy: x[::-1]
pytorch: torch.flip(x, [0])
- numpy: np.unique(x)
pytorch: torch.unique(x)
calculation:
- numpy: x.min
pytorch: x.min
- numpy: x.argmin
pytorch: x.argmin
- numpy: x.max
pytorch: x.max
- numpy: x.argmax
pytorch: x.argmax
- numpy: x.clip
pytorch: x.clamp
- numpy: x.round
pytorch: x.round
- numpy: np.floor(x)
pytorch:
content: torch.floor(x); x.floor()
skip_test: true
- numpy: np.ceil(x)
pytorch:
content: torch.ceil(x); x.ceil()
skip_test: true
- numpy: x.trace
pytorch: x.trace
- numpy: x.sum
pytorch: x.sum
- numpy: x.sum(axis=0)
pytorch: x.sum(0)
- numpy: x.cumsum
pytorch: x.cumsum
- numpy: x.mean
pytorch: x.mean
- numpy: x.std
pytorch: x.std
- numpy: x.prod
pytorch: x.prod
- numpy: x.cumprod
pytorch: x.cumprod
- numpy: x.all
pytorch: x.all
- numpy: x.any
pytorch: x.any
arithmetic and comparison operations:
- numpy: np.less
pytorch: x.lt
- numpy: np.less_equal
pytorch: x.le
- numpy: np.greater
pytorch: x.gt
- numpy: np.greater_equal
pytorch: x.ge
- numpy: np.equal
pytorch: x.eq
- numpy: np.not_equal
pytorch: x.ne
random numbers:
- numpy: np.random.seed
pytorch: torch.manual_seed
- numpy: np.random.permutation(5)
pytorch: torch.randperm(5)
numerical operations:
- numpy: np.sign
pytorch: torch.sign
- numpy: np.sqrt
pytorch: torch.sqrt