@@ -16,8 +16,7 @@ module nf_layer_constructors
1616 input, &
1717 linear2d, &
1818 locally_connected1d, &
19- maxpool1d, &
20- maxpool2d, &
19+ maxpool, &
2120 reshape, &
2221 self_attention, &
2322 embedding, &
@@ -151,10 +150,61 @@ module function conv2d(filters, kernel_width, kernel_height, activation) result(
151150 type (layer) :: res
152151 ! ! Resulting layer instance
153152 end function conv2d
154-
153+
155154 end interface conv
156155
157156
157+ interface maxpool
158+
159+ module function maxpool1d (pool_width , stride ) result(res)
160+ ! ! 1-d maxpooling layer constructor.
161+ ! !
162+ ! ! This layer is for downscaling other layers, typically `conv1d`.
163+ ! !
164+ ! ! This specific function is available under a generic name `maxpool`.
165+ ! !
166+ ! ! Example:
167+ ! !
168+ ! ! ```
169+ ! ! use nf, only :: maxpool1d, layer
170+ ! ! type(layer) :: maxpool1d_layer
171+ ! ! maxpool1d_layer = maxpool1d(pool_width=2, stride=2)
172+ ! ! ```
173+ integer , intent (in ) :: pool_width
174+ ! ! Width of the pooling window, commonly 2
175+ integer , intent (in ) :: stride
176+ ! ! Stride of the pooling window, commonly equal to `pool_width`;
177+ type (layer) :: res
178+ ! ! Resulting layer instance
179+ end function maxpool1d
180+
181+ module function maxpool2d (pool_width , pool_height , stride ) result(res)
182+ ! ! 2-d maxpooling layer constructor.
183+ ! !
184+ ! ! This layer is for downscaling other layers, typically `conv2d`.
185+ ! !
186+ ! ! This specific function is available under a generic name `maxpool`.
187+ ! !
188+ ! ! Example:
189+ ! !
190+ ! ! ```
191+ ! ! use nf, only :: maxpool2d, layer
192+ ! ! type(layer) :: maxpool2d_layer
193+ ! ! maxpool2d_layer = maxpool2d(pool_width=2, pool_height=2, stride=2)
194+ ! ! ```
195+ integer , intent (in ) :: pool_width
196+ ! ! Width of the pooling window, commonly 2
197+ integer , intent (in ) :: pool_height
198+ ! ! Height of the pooling window; currently must be equal to pool_width
199+ integer , intent (in ) :: stride
200+ ! ! Stride of the pooling window, commonly equal to `pool_width`;
201+ type (layer) :: res
202+ ! ! Resulting layer instance
203+ end function maxpool2d
204+
205+ end interface maxpool
206+
207+
158208 interface reshape
159209
160210 module function reshape2d (dim1 , dim2 ) result(res)
@@ -267,50 +317,6 @@ module function locally_connected1d(filters, kernel_size, activation) result(res
267317 ! ! Resulting layer instance
268318 end function locally_connected1d
269319
270- module function maxpool1d (pool_size , stride ) result(res)
271- ! ! 1-d maxpooling layer constructor.
272- ! !
273- ! ! This layer is for downscaling other layers, typically `conv1d`.
274- ! !
275- ! ! Example:
276- ! !
277- ! ! ```
278- ! ! use nf, only :: maxpool1d, layer
279- ! ! type(layer) :: maxpool1d_layer
280- ! ! maxpool1d_layer = maxpool1d(pool_size=2)
281- ! ! maxpool1d_layer = maxpool1d(pool_size=2, stride=3)
282- ! ! ```
283- integer , intent (in ) :: pool_size
284- ! ! Width of the pooling window, commonly 2
285- integer , intent (in ), optional :: stride
286- ! ! Stride of the pooling window, commonly equal to `pool_size`;
287- ! ! Defaults to `pool_size` if omitted.
288- type (layer) :: res
289- ! ! Resulting layer instance
290- end function maxpool1d
291-
292- module function maxpool2d (pool_size , stride ) result(res)
293- ! ! 2-d maxpooling layer constructor.
294- ! !
295- ! ! This layer is for downscaling other layers, typically `conv2d`.
296- ! !
297- ! ! Example:
298- ! !
299- ! ! ```
300- ! ! use nf, only :: maxpool2d, layer
301- ! ! type(layer) :: maxpool2d_layer
302- ! ! maxpool2d_layer = maxpool2d(pool_size=2)
303- ! ! maxpool2d_layer = maxpool2d(pool_size=2, stride=3)
304- ! ! ```
305- integer , intent (in ) :: pool_size
306- ! ! Width of the pooling window, commonly 2
307- integer , intent (in ), optional :: stride
308- ! ! Stride of the pooling window, commonly equal to `pool_size`;
309- ! ! Defaults to `pool_size` if omitted.
310- type (layer) :: res
311- ! ! Resulting layer instance
312- end function maxpool2d
313-
314320 module function linear2d (out_features ) result(res)
315321 ! ! Rank-2 (sequence_length, out_features) linear layer constructor.
316322 ! ! sequence_length is determined at layer initialization, based on the
0 commit comments