Skip to content

Commit 40a6f33

Browse files
committed
Fix out-of-bounds error for inputs with odd widths and heights
1 parent be5ca0a commit 40a6f33

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/nf/nf_maxpool2d_layer_submodule.f90

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ pure module subroutine forward(self, input)
4343
integer :: i, j, n
4444
integer :: ii, jj
4545
integer :: iend, jend
46+
integer :: iextent, jextent
4647
integer :: maxloc_xy(2)
4748

4849
input_width = size(input, dim=2)
49-
input_height = size(input, dim=2)
50+
input_height = size(input, dim=3)
51+
52+
iextent = input_width - mod(input_width, self % stride)
53+
jextent = input_height - mod(input_height, self % stride)
5054

5155
! Stride along the width and height of the input image
5256
stride_over_input: do concurrent( &
53-
i = 1:input_width:self % stride, &
54-
j = 1:input_height:self % stride &
57+
i = 1:iextent:self % stride, &
58+
j = 1:jextent:self % stride &
5559
)
5660

5761
! Indices of the pooling layer

0 commit comments

Comments
 (0)