forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cpp
52 lines (46 loc) · 1.3 KB
/
Utils.cpp
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
#include <ATen/native/mkldnn/Utils.h>
#include <ATen/native/Pool.h>
namespace at { namespace native {
std::vector<int64_t> conv_output_size(
IntArrayRef input_size,
IntArrayRef kernel_size,
IntArrayRef padding,
IntArrayRef stride,
IntArrayRef dilation) {
auto dim = input_size.size();
std::vector<int64_t> output_size(dim);
output_size[0] = input_size[0];
output_size[1] = kernel_size[0];
for (size_t d = 2; d < dim; ++d) {
auto kernel = dilation[d - 2] * (kernel_size[d] - 1) + 1;
output_size[d] = (input_size[d] + (2 * padding[d - 2])
- kernel) / stride[d - 2] + 1;
}
return output_size;
}
std::vector<int64_t> pool_output_sizes(
IntArrayRef input_size,
IntArrayRef kernel_size,
IntArrayRef stride,
IntArrayRef padding_l,
IntArrayRef padding_r,
IntArrayRef dilation,
bool ceil_mode) {
std::vector<int64_t> output_size(input_size.size());
// copy N and C
output_size[0] = input_size[0];
output_size[1] = input_size[1];
for (size_t i = 2; i < input_size.size(); ++i) {
output_size[i] = pooling_output_shape_pad_lr<int64_t>(
input_size[i],
kernel_size[i - 2],
padding_l[i - 2],
padding_r[i - 2],
stride[i - 2],
dilation[i - 2],
ceil_mode
);
}
return output_size;
}
}}