forked from modern-fortran/neural-fortran
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_dense_layer.f90
58 lines (46 loc) · 1.58 KB
/
test_dense_layer.f90
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
program test_dense_layer
use iso_fortran_env, only: stderr => error_unit
use nf, only: dense, layer
use nf_activation, only: relu
implicit none
type(layer) :: layer1, layer2
logical :: ok = .true.
layer1 = dense(10)
if (.not. layer1 % name == 'dense') then
ok = .false.
write(stderr, '(a)') 'dense layer has its name set correctly.. failed'
end if
if (.not. all(layer1 % layer_shape == [10])) then
ok = .false.
write(stderr, '(a)') 'dense layer is created with requested size.. failed'
end if
if (layer1 % initialized) then
ok = .false.
write(stderr, '(a)') 'dense layer should not be marked as initialized yet.. failed'
end if
if (.not. layer1 % activation == 'sigmoid') then
ok = .false.
write(stderr, '(a)') 'dense layer is defaults to sigmoid activation.. failed'
end if
layer1 = dense(10, activation=relu())
if (.not. layer1 % activation == 'relu') then
ok = .false.
write(stderr, '(a)') 'dense layer is created with the specified activation.. failed'
end if
layer2 = dense(20)
call layer2 % init(layer1)
if (.not. layer2 % initialized) then
ok = .false.
write(stderr, '(a)') 'dense layer should now be marked as initialized.. failed'
end if
if (.not. all(layer2 % input_layer_shape == [10])) then
ok = .false.
write(stderr, '(a)') 'dense layer should have a correct input layer shape.. failed'
end if
if (ok) then
print '(a)', 'test_dense_layer: All tests passed.'
else
write(stderr, '(a)') 'test_dense_layer: One or more tests failed.'
stop 1
end if
end program test_dense_layer