Skip to content

Commit 75ef184

Browse files
committed
Test dropout state that follows an input layer
1 parent 820b081 commit 75ef184

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

test/test_dropout_layer.f90

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
program test_dropout_layer
22
use iso_fortran_env, only: stderr => error_unit
3-
use nf, only: dropout, layer
3+
use nf, only: dropout, input, layer, network
44
use nf_dropout_layer, only: dropout_layer
55
type(layer) :: layer1
6+
type(network) :: net
7+
integer :: input_size
8+
69
logical :: ok = .true.
710

811
layer1 = dropout(0.5)
@@ -29,6 +32,39 @@ program test_dropout_layer
2932

3033
end select
3134

35+
! Now we're gonna initialize a minimal network with an input layer and a
36+
! dropout that follows and we'll check that the dropout layer has expected
37+
! state.
38+
input_size = 10
39+
net = network([ &
40+
input(input_size), &
41+
dropout(0.5) &
42+
])
43+
44+
select type(layer1_p => net % layers(1) % p)
45+
type is(dropout_layer)
46+
if (layer1_p % input_size /= input_size) then
47+
ok = .false.
48+
write(stderr, '(a)') 'dropout layer input size should be the same as the input layer.. failed'
49+
end if
50+
51+
if (.not. allocated(layer1_p % output)) then
52+
ok = .false.
53+
write(stderr, '(a)') 'dropout layer output array should be allocated.. failed'
54+
end if
55+
56+
if (.not. allocated(layer1_p % gradient)) then
57+
ok = .false.
58+
write(stderr, '(a)') 'dropout layer gradient array should be allocated.. failed'
59+
end if
60+
61+
if (.not. allocated(layer1_p % mask)) then
62+
ok = .false.
63+
write(stderr, '(a)') 'dropout layer mask array should be allocated.. failed'
64+
end if
65+
66+
end select
67+
3268
if (ok) then
3369
print '(a)', 'test_dropout_layer: All tests passed.'
3470
else

0 commit comments

Comments
 (0)