|
1 | 1 | program test_dense_layer |
2 | 2 | use iso_fortran_env, only: stderr => error_unit |
3 | | - use nf, only: dense, layer |
4 | | - use nf_activation, only: relu |
| 3 | + use nf, only: dense, layer, relu |
| 4 | + use tuff, only: test, test_result |
5 | 5 | implicit none |
6 | | - type(layer) :: layer1, layer2 |
7 | | - logical :: ok = .true. |
| 6 | + type(layer) :: layer1, layer2, layer3 |
| 7 | + type(test_result) :: tests |
8 | 8 |
|
9 | 9 | layer1 = dense(10) |
10 | | - |
11 | | - if (.not. layer1 % name == 'dense') then |
12 | | - ok = .false. |
13 | | - write(stderr, '(a)') 'dense layer has its name set correctly.. failed' |
14 | | - end if |
15 | | - |
16 | | - if (.not. all(layer1 % layer_shape == [10])) then |
17 | | - ok = .false. |
18 | | - write(stderr, '(a)') 'dense layer is created with requested size.. failed' |
19 | | - end if |
20 | | - |
21 | | - if (layer1 % initialized) then |
22 | | - ok = .false. |
23 | | - write(stderr, '(a)') 'dense layer should not be marked as initialized yet.. failed' |
24 | | - end if |
25 | | - |
26 | | - if (.not. layer1 % activation == 'sigmoid') then |
27 | | - ok = .false. |
28 | | - write(stderr, '(a)') 'dense layer is defaults to sigmoid activation.. failed' |
29 | | - end if |
30 | | - |
31 | | - layer1 = dense(10, activation=relu()) |
32 | | - |
33 | | - if (.not. layer1 % activation == 'relu') then |
34 | | - ok = .false. |
35 | | - write(stderr, '(a)') 'dense layer is created with the specified activation.. failed' |
36 | | - end if |
37 | | - |
38 | | - layer2 = dense(20) |
39 | | - call layer2 % init(layer1) |
40 | | - |
41 | | - if (.not. layer2 % initialized) then |
42 | | - ok = .false. |
43 | | - write(stderr, '(a)') 'dense layer should now be marked as initialized.. failed' |
44 | | - end if |
45 | | - |
46 | | - if (.not. all(layer2 % input_layer_shape == [10])) then |
47 | | - ok = .false. |
48 | | - write(stderr, '(a)') 'dense layer should have a correct input layer shape.. failed' |
49 | | - end if |
50 | | - |
51 | | - if (ok) then |
52 | | - print '(a)', 'test_dense_layer: All tests passed.' |
53 | | - else |
54 | | - write(stderr, '(a)') 'test_dense_layer: One or more tests failed.' |
55 | | - stop 1 |
56 | | - end if |
| 10 | + layer2 = dense(10, activation=relu()) |
| 11 | + layer3 = dense(20) |
| 12 | + call layer3 % init(layer1) |
| 13 | + |
| 14 | + tests = test("Dense layer", [ & |
| 15 | + test("layer name is set", layer1 % name == 'dense'), & |
| 16 | + test("layer shape is correct", all(layer1 % layer_shape == [10])), & |
| 17 | + test("layer is initialized", layer3 % initialized), & |
| 18 | + test("layer's default activation is sigmoid", layer1 % activation == 'sigmoid'), & |
| 19 | + test("user set activation works", layer2 % activation == 'relu'), & |
| 20 | + test("layer initialized after init", layer3 % initialized), & |
| 21 | + test("layer input shape is set after init", all(layer3 % input_layer_shape == [10])) & |
| 22 | + ]) |
57 | 23 |
|
58 | 24 | end program test_dense_layer |
0 commit comments