forked from modern-fortran/neural-fortran
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_parametric_activation.f90
78 lines (64 loc) · 2.08 KB
/
test_parametric_activation.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
program test_parametric_activation
use iso_fortran_env, only: stderr => error_unit
use nf, only: dense, layer
use nf_dense_layer, only: dense_layer
use nf_activation, only: elu, leaky_relu
implicit none
type(layer) :: layer1
real :: alpha
logical :: ok = .true.
layer1 = dense(10, activation=elu())
select type(this_layer => layer1 % p)
type is (dense_layer)
select type(this_activation => this_layer % activation)
type is (elu)
alpha = this_activation % alpha
end select
end select
if (.not. alpha == 1) then
ok = .false.
write(stderr, '(a)') 'default alpha for ELU is as expected.. failed'
end if
layer1 = dense(10, activation=elu(0.1))
select type(this_layer => layer1 % p)
type is (dense_layer)
select type(this_activation => this_layer % activation)
type is (elu)
alpha = this_activation % alpha
end select
end select
if (.not. alpha == 0.1) then
ok = .false.
write(stderr, '(a)') 'User set alpha for ELU is as expected.. failed'
end if
layer1 = dense(10, activation=leaky_relu())
select type(this_layer => layer1 % p)
type is (dense_layer)
select type(this_activation => this_layer % activation)
type is (leaky_relu)
alpha = this_activation % alpha
end select
end select
if (.not. alpha == 0.3) then
ok = .false.
write(stderr, '(a)') 'Default alpha for leaky ReLU is as expected.. failed'
end if
layer1 = dense(10, activation=leaky_relu(0.01))
select type(this_layer => layer1 % p)
type is (dense_layer)
select type(this_activation => this_layer % activation)
type is (leaky_relu)
alpha = this_activation % alpha
end select
end select
if (.not. alpha == 0.01) then
ok = .false.
write(stderr, '(a)') 'User set alpha for leaky ReLU is as expected.. failed'
end if
if (ok) then
print '(a)', 'test_parametric_activation: All tests passed.'
else
write(stderr, '(a)') 'test_parametric_activation: One or more tests failed.'
stop 1
end if
end program test_parametric_activation