8000 fix avgpool · DiffSharp/DiffSharp@d2e7a33 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2e7a33

Browse files
author
Don Syme
committed
fix avgpool
1 parent dd1ac70 commit d2e7a33

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
namespace DiffSharp
2+
3+
[<AutoOpen>]
4+
module AvgPoolExtensions =
5+
6+
type Tensor with
7+
/// <summary>Applies a 1D average pooling over an input signal composed of several input planes, returning the max indices along with the outputs.</summary>
8+
/// <param name="kernelSize">The size of the window to take a max over.</param>
9+
/// <param name="stride">The stride of the window. Default value is kernelSize.</param>
10+
/// <param name="padding">The implicit zero padding to be added on both sides.</param>
11+
member a.avgpool1d(kernelSize:int, ?stride:int, ?padding:int(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
12+
let stride = defaultArg stride kernelSize
13+
let padding = defaultArg padding 0
14+
//let ceil_mode = defaultArg ceil_mode false
15+
//let count_include_pad= defaultArg count_include_pad true
16+
Shape.checkCanAvgpool1d a.dtype a.shape kernelSize stride padding |> ignore
17+
Tensor.Op
18+
{ new UnaryOp("avgpool1d") with
19+
member _.fRaw(a) = a.AvgPool1D(kernelSize, stride, padding(* , ceil_mode, count_include_pad *))
20+
member t.ad_dfda(a, ad, f) = ad.avgpool1d(kernelSize, stride, padding(* , ceil_mode, count_include_pad *))
21+
member _.fd_dfda(a, f, fd) = fd.avgpoolReverse1d(a, kernelSize, stride, padding(* , ceil_mode, count_include_pad *))
22+
}
23+
a
24+
25+
member internal a.avgpoolReverse1d(originalInput:Tensor, kernelSize:int, ?stride:int, ?padding:int(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
26+
let stride = defaultArg stride kernelSize
27+
let padding = defaultArg padding 0
28+
//let ceil_mode = defaultArg ceil_mode false
29+
//let count_include_pad= defaultArg count_include_pad true
30+
Tensor.Op
31+
{ new UnaryOp("avgpoolReverse1d") with
32+
member _.fRaw(a) = a.AvgPoolReverse1D(originalInput.primalRaw, kernelSize, stride, padding(* , ceil_mode, count_include_pad *))
33+
member _.ad_dfda(a, ad, f) = ad.avgpoolReverse1d(originalInput, kernelSize, stride, padding(* , ceil_mode, count_include_pad *))
34+
member _.fd_dfda(a, f, fd) = fd.avgpool1d(kernelSize, stride, padding(* , ceil_mode, count_include_pad *))
35+
}
36+
a
37+
38+
/// <summary>Applies a 1D average pooling over an input signal composed of several input planes, returning the max indices along with the outputs.</summary>
39+
/// <param name="kernelSize">The size of the window to take a max over.</param>
40+
/// <param name="stride">The stride of the window. Default value is kernelSize.</param>
41+
/// <param name="padding">The implicit zero padding to be added on both sides.</param>
42+
/// <param name="kernelSizes">The sizes of the window to take a max over.</param>
43+
/// <param name="strides">The strides of the window. Default value is kernelSize.</param>
44+
/// <param name="paddings">The implicit zero paddings to be added on both sides.</param>
45+
member a.avgpool2d(?kernelSize:int, ?stride:int, ?padding:int, ?kernelSizes:seq<int>, ?strides:seq<int>, ?paddings:seq<int>(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
46+
let kernelSizes, strides, paddings = Shape.resolve2dMaxPoolSizes kernelSize kernelSizes stride strides padding paddings
47+
//let ceil_mode = defaultArg ceil_mode false
48+
//let count_include_pad= defaultArg count_include_pad true
49+
Shape.checkCanAvgpool2d a.dtype a.shape kernelSizes strides paddings |> ignore
50+
Tensor.Op
51+
{ new UnaryOp("avgpool2d") with
52+
member _.fRaw(a) = a.AvgPool2D(kernelSizes, strides, paddings(* , ceil_mode, count_include_pad *))
53+
member _.ad_dfda(a, ad, f) = ad.avgpool2d(kernelSizes=kernelSizes, strides=strides, paddings=paddings(* , ceil_mode=ceil_mode, count_include_pad=count_include_pad *))
54+
member _.fd_dfda(a, f, fd) = fd.avgpoolReverse2d(a, kernelSizes=kernelSizes, strides=strides, paddings=paddings(* , ceil_mode=ceil_mode, count_include_pad=count_include_pad *))
55+
}
56+
a
57+
58+
member internal a.avgpoolReverse2d(originalInput:Tensor, ?kernelSize:int, ?stride:int, ?padding:int, ?kernelSizes:seq<int>, ?strides:seq<int>, ?paddings:seq<int>(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
59+
let kernelSizes, strides, paddings = Shape.resolve2dMaxPoolSizes kernelSize kernelSizes stride strides padding paddings
60+
//let ceil_mode = defaultArg ceil_mode false
61+
//let count_include_pad= defaultArg count_include_pad true
62+
Tensor.Op
63+
{ new UnaryOp("avgpoolReverse2d") with
64+
member _.fRaw(a) = a.AvgPoolReverse2D(originalInput.primalRaw, kernelSizes, strides, paddings(* , ceil_mode, count_include_pad *))
65+
member _.ad_dfda(a, ad, f) = ad.avgpoolReverse2d(originalInput, kernelSizes=kernelSizes, strides=strides, paddings=paddings(* , ceil_mode=ceil_mode, count_include_pad=count_include_pad *))
66+
member _.fd_dfda(a, f, fd) = fd.avgpool2d(kernelSizes=kernelSizes, strides=strides, paddings=paddings(* , ceil_mode=ceil_mode, count_include_pad=count_include_pad *))
67+
}
68+
a
69+
70+
/// <summary>Applies a 3D average pooling over an input signal composed of several input planes, returning the max indices along with the outputs.</summary>
71+
/// <param name="kernelSize">The size of the window to take a max over.</param>
72+
/// <param name="stride">The stride of the window. Default value is kernelSize.</param>
73+
/// <param name="padding">The implicit zero padding to be added on both sides.</param>
74+
/// <param name="kernelSizes">The sizes of the window to take a max over.</param>
75+
/// <param name="strides">The strides of the window. Default value is kernelSize.</param>
76+
/// <param name="paddings">The implicit zero paddings to be added on both sides.</param>
77+
member a.avgpool3d(?kernelSize:int, ?stride:int, ?padding:int, ?kernelSizes:seq<int>, ?strides:seq<int>, ?paddings:seq<int>(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
78+
let kernelSizes, strides, paddings = Shape.resolve3dMaxPoolSizes kernelSize kernelSizes stride strides padding paddings
79+
//let ceil_mode = defaultArg ceil_mode false
80+
//let count_include_pad= defaultArg count_include_pad true
81+
Shape.checkCanAvgpool3d a.dtype a.shape kernelSizes strides paddings |> ignore
82+
Tensor.Op
83+
{ new UnaryOp("avgpool3d") with
84+
member _.fRaw(a) = a.AvgPool3D(kernelSizes, strides, paddings(* , ceil_mode, count_include_pad *))
85+
member _.ad_dfda(a, ad, f) = ad.avgpool3d(kernelSizes=kernelSizes, strides=strides, paddings=paddings(* , ceil_mode=ceil_mode, count_include_pad=count_include_pad *))
86+
member _.fd_dfda(a, f, fd) = fd.avgpoolReverse3d(a, kernelSizes=kernelSizes, strides=strides, paddings=paddings(* , ceil_mode=ceil_mode, count_include_pad=count_include_pad *))
87+
}
88+
a
89+
90+
member internal a.avgpoolReverse3d(originalInput:Tensor, ?kernelSize:int, ?stride:int, ?padding:int, ?kernelSizes:seq<int>, ?strides:seq<int>, ?paddings:seq<int>(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
91+
let kernelSizes, strides, paddings = Shape.resolve3dMaxPoolSizes kernelSize kernelSizes stride strides padding paddings
92+
//let ceil_mode = defaultArg ceil_mode false
93+
//let count_include_pad= defaultArg count_include_pad true
94+
Tensor.Op
95+
{ new UnaryOp("avgpoolReverse3d") with
96+
member _.fRaw(a) = a.AvgPoolReverse3D(originalInput.primalRaw, kernelSizes, strides, paddings(* , ceil_mode, count_include_pad *))
97+
member _.ad_dfda(a, ad, f) = ad.avgpoolReverse3d(originalInput, kernelSizes=kernelSizes, strides=strides, paddings=paddings(* , ceil_mode=ceil_mode, count_include_pad=count_include_pad *))
98+
member _.fd_dfda(a, f, fd) = fd.avgpool3d(kernelSizes=kernelSizes, strides=strides, paddings=paddings(* , ceil_mode=ceil_mode, count_include_pad=count_include_pad *))
99+
}
100+
a
101+
102+
type dsharp with
103+
/// <summary>Applies a 1D average pooling over an input signal composed of several input planes, returning the max indices along with the outputs.</summary>
104+
/// <param name="input">The input tensor.</param>
105+
/// <param name="kernelSize">The size of the window to take a max over.</param>
106+
/// <param name="stride">The stride of the window. Default value is kernelSize.</param>
107+
/// <param name="padding">The implicit zero padding to be added on both sides.</param>
108+
static member avgpool1d(input: Tensor, kernelSize:int, ?stride:int, ?padding:int(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
109+
input.avgpool2d(kernelSize=kernelSize, ?stride=stride, ?padding=padding(* , ?ceil_mode=ceil_mode, ?count_include_pad=count_include_pad *))
110+
111+
/// <summary>Applies a 2D average pooling over an input signal composed of several input planes, returning the max indices along with the outputs.</summary>
112+
/// <param name="input">The input tensor.</param>
113+
/// <param name="kernelSize">The size of the window to take a max over.</param>
114+
/// <param name="stride">The stride of the window. Default value is kernelSize.</param>
115+
/// <param name="padding">The implicit zero padding to be added on both sides.</param>
116+
/// <param name="kernelSizes">The sizes of the window to take a max over.</param>
117+
/// <param name="strides">The strides of the window. Default value is kernelSize.</param>
118+
/// <param name="paddings">The implicit zero paddings to be added on both sides.</param>
119+
static member avgpool2d(input: Tensor, ?kernelSize:int, ?stride:int, ?padding:int, ?kernelSizes:seq<int>, ?strides:seq<int>, ?paddings:seq<int>(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
120+
input.avgpool2d(?kernelSize=kernelSize, ?stride=stride, ?padding=padding, ?kernelSizes=kernelSizes, ?strides=strides, ?paddings=paddings(* , ?ceil_mode=ceil_mode, ?count_include_pad=count_include_pad *))
121+
122+
/// <summary>Applies a 2D average pooling over an input signal composed of several input planes, returning the max indices along with the outputs.</summary>
123+
/// <param name="input">The input tensor.</param>
124+
/// <param name="kernelSize">The size of the window to take a max over.</param>
125+
/// <param name="stride">The stride of the window. Default value is kernelSize.</param>
126+
/// <param name="padding">The implicit zero padding to be added on both sides.</param>
127+
/// <param name="kernelSizes">The sizes of the window to take a max over.</param>
128+
/// <param name="strides">The strides of the window. Default value is kernelSize.</param>
129+
/// <param name="paddings">The implicit zero paddings to be added on both sides.</param>
130+
static member avgpool3d(input: Tensor, ?kernelSize:int, ?stride:int, ?padding:int, ?kernelSizes:seq<int>, ?strides:seq<int>, ?paddings:seq<int>(* , ?ceil_mode: bool, ?count_include_pad: bool *)) =
131+
input.avgpool3d(?kernelSize=kernelSize, ?stride=stride, ?padding=padding, ?kernelSizes=kernelSizes, ?strides=strides, ?paddings=paddings(* , ?ceil_mode=ceil_mode, ?count_include_pad=count_include_pad *))
132+

0 commit comments

Comments
 (0)
0