forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPooling.cpp
134 lines (115 loc) · 3.47 KB
/
Pooling.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
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
#include <ATen/ATen.h>
#include <ATen/NativeFunctions.h>
#include <ATen/TensorUtils.h>
#include <c10/util/Exception.h>
#include <tuple>
namespace at { namespace native {
static void check1d(
const char* function_name,
const char* argument_name,
IntList x) {
AT_CHECK(
x.size() == 1,
function_name, "() argument '", argument_name,
"' should contain one int (got ", x.size(), ")");
}
Tensor adaptive_avg_pool1d(const Tensor & self, IntList output_size) {
checkDim("adaptive_avg_pool1d", TensorArg(self, "self", 1), 3);
check1d("adaptive_avg_pool1d", "output_size", output_size);
auto output = at::adaptive_avg_pool2d(
self.unsqueeze(2),
{1, output_size[0]});
return output.squeeze(2);
}
std::tuple<Tensor,Tensor> adaptive_max_pool1d(const Tensor & self, IntList output_size) {
checkDim("adaptive_max_pool1d", TensorArg(self, "self", 1), 3);
check1d("adaptive_max_pool1d", "output_size", output_size);
Tensor output, indices;
std::tie(output, indices) = at::adaptive_max_pool2d(
self.unsqueeze(2),
{1, output_size[0]});
return std::make_tuple(output.squeeze(2), indices.squeeze(2));
}
std::tuple<Tensor, Tensor> max_pool1d_with_indices(
const Tensor& self,
IntList kernel_size,
IntList stride,
IntList padding,
IntList dilation,
bool ceil_mode) {
if (stride.empty()) {
stride = kernel_size;
}
checkDim("max_pool1d", TensorArg(self, "self", 1), 3);
check1d("max_pool1d", "kernel_size", kernel_size);
check1d("max_pool1d", "stride", stride);
check1d("max_pool1d", "padding", padding);
check1d("max_pool1d", "dilation", dilation);
Tensor output, indices;
std::tie(output, indices) = at::max_pool2d_with_indices(
self.unsqueeze(2),
{1, kernel_size[0]},
{1, stride[0]},
{0, padding[0]},
{1, dilation[0]},
ceil_mode);
return std::make_tuple(output.squeeze(2), indices.squeeze(2));
}
Tensor avg_pool1d(
const Tensor& self,
IntList kernel_size,
IntList stride,
IntList padding,
bool ceil_mode,
bool count_include_pad) {
if (stride.empty()) {
stride = kernel_size;
}
checkDim("avg_pool1d", TensorArg(self, "self", 1), 3);
check1d("avg_pool1d", "kernel_size", kernel_size);
check1d("avg_pool1d", "stride", stride);
check1d("avg_pool1d", "padding", padding);
auto output = at::avg_pool2d(
self.unsqueeze(2),
{1, kernel_size[0]},
{1, stride[0]},
{0, padding[0]},
ceil_mode,
count_include_pad);
return output.squeeze(2);
}
Tensor max_pool1d(
const Tensor& self,
IntList kernel_size,
IntList stride,
IntList padding,
IntList dilation,
bool ceil_mode) {
auto output_and_indices = at::max_pool1d_with_indices(
self, kernel_size, stride, padding, dilation, ceil_mode);
return std::get<0>(output_and_indices);
}
Tensor max_pool2d(
const Tensor& self,
IntList kernel_size,
IntList stride,
IntList padding,
IntList dilation,
bool ceil_mode) {
auto output_and_indices = at::max_pool2d_with_indices(
self, kernel_size, stride, padding, dilation, ceil_mode);
return std::get<0>(output_and_indices);
}
Tensor max_pool3d(
const Tensor& self,
IntList kernel_size,
IntList stride,
IntList padding,
IntList dilation,
bool ceil_mode) {
auto output_and_indices = at::max_pool3d_with_indices(
self, kernel_size, stride, padding, dilation, ceil_mode);
return std::get<0>(output_and_indices);
}
} // namespace native
} // namespace at