GCC Code Coverage Report


Directory: src/lib/
File: src/lib/mod_input4d_layer.f90
Date: 2024-06-28 12:51:18
Exec Total Coverage
Lines: 32 50 64.0%
Functions: 0 0 -%
Branches: 197 867 22.7%

Line Branch Exec Source
1 !!!#############################################################################
2 !!! Code written by Ned Thaddeus Taylor
3 !!! Code part of the ATHENA library - a feedforward neural network library
4 !!!#############################################################################
5 !!! module contains implementation of a 4D input layer
6 !!!#############################################################################
7 module input4d_layer
8 use constants, only: real12
9 use base_layer, only: input_layer_type
10 implicit none
11
12
13 type, extends(input_layer_type) :: input4d_layer_type
14 real(real12), allocatable, dimension(:,:,:,:,:) :: output
15 contains
16 procedure, pass(this) :: get_output => get_output_input4d
17 procedure, pass(this) :: init => init_input4d
18 procedure, pass(this) :: set_batch_size => set_batch_size_input4d
19 procedure, pass(this) :: forward => forward_rank
20 procedure, pass(this) :: backward => backward_rank
21 procedure, pass(this) :: set => set_input4d
22 end type input4d_layer_type
23
24 interface input4d_layer_type
25 module function layer_setup(input_shape, batch_size) result(layer)
26 integer, dimension(:), optional, intent(in) :: input_shape
27 integer, optional, intent(in) :: batch_size
28 type(input4d_layer_type) :: layer
29 end function layer_setup
30 end interface input4d_layer_type
31
32
33 private
34 public :: input4d_layer_type
35
36
37 contains
38
39 !!!#############################################################################
40 !!! get layer outputs
41 !!!#############################################################################
42 1 pure subroutine get_output_input4d(this, output)
43 implicit none
44 class(input4d_layer_type), intent(in) :: this
45 real(real12), allocatable, dimension(..), intent(out) :: output
46
47 select rank(output)
48 rank(1)
49 output = reshape(this%output, [size(this%output)])
50 rank(2)
51 output = &
52 reshape(this%output, [product(this%output_shape),this%batch_size])
53 rank(5)
54
42/84
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 54 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 60 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✓ Branch 72 taken 1 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 1 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 1 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 1 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 1 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 1 times.
✗ Branch 91 not taken.
✓ Branch 92 taken 1 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 1 times.
✓ Branch 95 taken 1 times.
✓ Branch 96 taken 1 times.
✓ Branch 97 taken 1 times.
✓ Branch 98 taken 3 times.
✓ Branch 99 taken 1 times.
✓ Branch 100 taken 9 times.
✓ Branch 101 taken 3 times.
✓ Branch 102 taken 27 times.
✓ Branch 103 taken 9 times.
42 output = this%output
55 end select
56
57 1 end subroutine get_output_input4d
58 !!!#############################################################################
59
60
61 !!!##########################################################################!!!
62 !!! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * !!!
63 !!!##########################################################################!!!
64
65
66 !!!#############################################################################
67 !!! forward propagation assumed rank handler
68 !!! placeholder to satisfy deferred
69 !!!#############################################################################
70 pure subroutine forward_rank(this, input)
71 implicit none
72 class(input4d_layer_type), intent(inout) :: this
73 real(real12), dimension(..), intent(in) :: input
74
75 select rank(input)
76 rank(1)
77 this%output = reshape(input, shape=shape(this%output))
78 rank(2)
79 this%output = reshape(input, shape=shape(this%output))
80 rank(3)
81 this%output = reshape(input, shape=shape(this%output))
82 rank(4)
83 this%output = reshape(input, shape=shape(this%output))
84 rank(5)
85 this%output = reshape(input, shape=shape(this%output))
86 rank(6)
87 this%output = reshape(input, shape=shape(this%output))
88 end select
89 end subroutine forward_rank
90 !!!#############################################################################
91
92
93 !!!#############################################################################
94 !!! backward propagation assumed rank handler
95 !!! placeholder to satisfy deferred
96 !!!#############################################################################
97 pure subroutine backward_rank(this, input, gradient)
98 implicit none
99 class(input4d_layer_type), intent(inout) :: this
100 real(real12), dimension(..), intent(in) :: input
101 real(real12), dimension(..), intent(in) :: gradient
102 return
103 end subroutine backward_rank
104 !!!#############################################################################
105
106
107 !!!##########################################################################!!!
108 !!! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * !!!
109 !!!##########################################################################!!!
110
111
112 !!!#############################################################################
113 !!! set up layer
114 !!!#############################################################################
115 #if defined(GFORTRAN)
116 module function layer_setup(input_shape) result(layer)
117 implicit none
118 integer, dimension(:), optional, intent(in) :: input_shape
119
120 type(input4d_layer_type) :: layer
121 #else
122
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 module procedure layer_setup
123 implicit none
124 #endif
125
126
127
3/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
4 layer%name = "input1d"
128 4 layer%input_rank = 4
129 !!--------------------------------------------------------------------------
130 !! initialise batch size
131 !!--------------------------------------------------------------------------
132
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if(present(batch_size)) layer%batch_size = batch_size
133
134
135 !!--------------------------------------------------------------------------
136 !! initialise layer shape
137 !!--------------------------------------------------------------------------
138
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
4 if(present(input_shape)) call layer%init(input_shape=input_shape)
139
140 #if defined(GFORTRAN)
141 end function layer_setup
142 #else
143
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 end procedure layer_setup
144 #endif
145 !!!#############################################################################
146
147
148 !!!#############################################################################
149 !!! initialise layer
150 !!!#############################################################################
151
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 subroutine init_input4d(this, input_shape, batch_size, verbose)
152 implicit none
153 class(input4d_layer_type), intent(inout) :: this
154 integer, dimension(:), intent(in) :: input_shape
155 integer, optional, intent(in) :: batch_size
156 integer, optional, intent(in) :: verbose
157
158 integer :: verbose_ = 0
159
160
161 !!--------------------------------------------------------------------------
162 !! initialise optional arguments
163 !!--------------------------------------------------------------------------
164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(present(verbose)) verbose_ = verbose
165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(present(batch_size)) this%batch_size = batch_size
166
167
168 !!--------------------------------------------------------------------------
169 !! initialise input shape
170 !!--------------------------------------------------------------------------
171
4/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 if(.not.allocated(this%input_shape)) call this%set_shape(input_shape)
172
173
10/20
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 4 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 4 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 4 times.
20 this%output_shape = this%input_shape
174
6/10
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✓ Branch 12 taken 16 times.
✓ Branch 13 taken 4 times.
20 this%num_outputs = product(this%input_shape)
175
176
177 !!--------------------------------------------------------------------------
178 !! initialise batch size-dependent arrays
179 !!--------------------------------------------------------------------------
180
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if(this%batch_size.gt.0) call this%set_batch_size(this%batch_size)
181
182 4 end subroutine init_input4d
183 !!!#############################################################################
184
185
186 !!!#############################################################################
187 !!! set batch size
188 !!!#############################################################################
189 3 subroutine set_batch_size_input4d(this, batch_size, verbose)
190 implicit none
191 class(input4d_layer_type), intent(inout) :: this
192 integer, intent(in) :: batch_size
193 integer, optional, intent(in) :: verbose
194
195 integer :: verbose_ = 0
196
197
198 !!--------------------------------------------------------------------------
199 !! initialise optional arguments
200 !!--------------------------------------------------------------------------
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(present(verbose)) verbose_ = verbose
202 3 this%batch_size = batch_size
203
204
205 !!--------------------------------------------------------------------------
206 !! allocate arrays
207 !!--------------------------------------------------------------------------
208
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(allocated(this%input_shape))then
209
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
3 if(allocated(this%output)) deallocate(this%output)
210 allocate(this%output( &
211 6 this%input_shape(1), &
212 6 this%input_shape(2), &
213 6 this%input_shape(3), &
214 6 this%input_shape(4), &
215
53/96
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
✓ Branch 26 taken 3 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 3 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 3 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 3 times.
✓ Branch 36 taken 3 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 3 times.
✓ Branch 40 taken 3 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✓ Branch 43 taken 3 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 3 times.
✗ Branch 46 not taken.
✓ Branch 47 taken 3 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 3 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 3 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 3 times.
✗ Branch 56 not taken.
✓ Branch 57 taken 3 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 3 times.
✗ Branch 62 not taken.
✓ Branch 63 taken 3 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 3 times.
✗ Branch 68 not taken.
✓ Branch 69 taken 3 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 3 times.
✗ Branch 74 not taken.
✓ Branch 75 taken 3 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 3 times.
✗ Branch 80 not taken.
✓ Branch 81 taken 3 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 3 times.
✗ Branch 86 not taken.
✓ Branch 87 taken 3 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 3 times.
✗ Branch 92 not taken.
✓ Branch 93 taken 3 times.
✗ Branch 95 not taken.
✓ Branch 96 taken 3 times.
✗ Branch 98 not taken.
✓ Branch 99 taken 3 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 3 times.
✗ Branch 104 not taken.
✓ Branch 105 taken 3 times.
✗ Branch 107 not taken.
✓ Branch 108 taken 3 times.
✗ Branch 110 not taken.
✓ Branch 111 taken 3 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 3 times.
✓ Branch 116 taken 3 times.
✓ Branch 117 taken 3 times.
✓ Branch 118 taken 7 times.
✓ Branch 119 taken 3 times.
✓ Branch 120 taken 45 times.
✓ Branch 121 taken 7 times.
✓ Branch 122 taken 303 times.
✓ Branch 123 taken 45 times.
✓ Branch 124 taken 2085 times.
✓ Branch 125 taken 303 times.
2446 this%batch_size), source=0._real12)
216 end if
217
218 3 end subroutine set_batch_size_input4d
219 !!!#############################################################################
220
221
222 !!!##########################################################################!!!
223 !!! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * !!!
224 !!!##########################################################################!!!
225
226
227 !!!#############################################################################
228 !!! set input layer values
229 !!!#############################################################################
230 3 pure subroutine set_input4d(this, input)
231 implicit none
232 class(input4d_layer_type), intent(inout) :: this
233 real(real12), &
234 dimension(..), intent(in) :: input
235 !dimension(this%batch_size * this%num_outputs), intent(in) :: input
236
237 select rank(input)
238 rank(1)
239 this%output = reshape(input, shape=shape(this%output))
240 rank(2)
241 this%output = reshape(input, shape=shape(this%output))
242 rank(3)
243 this%output = reshape(input, shape=shape(this%output))
244 rank(4)
245 this%output = reshape(input, shape=shape(this%output))
246 rank(5)
247
31/42
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 3 times.
✓ Branch 12 taken 7 times.
✓ Branch 13 taken 3 times.
✓ Branch 14 taken 45 times.
✓ Branch 15 taken 7 times.
✓ Branch 16 taken 303 times.
✓ Branch 17 taken 45 times.
✓ Branch 18 taken 2085 times.
✓ Branch 19 taken 303 times.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 3 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 3 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 3 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 3 times.
✓ Branch 35 taken 3 times.
✓ Branch 36 taken 7 times.
✓ Branch 37 taken 3 times.
✓ Branch 38 taken 45 times.
✓ Branch 39 taken 7 times.
✓ Branch 40 taken 303 times.
✓ Branch 41 taken 45 times.
✓ Branch 42 taken 2085 times.
✓ Branch 43 taken 303 times.
4904 this%output = reshape(input, shape=shape(this%output))
248 rank(6)
249 this%output = reshape(input, shape=shape(this%output))
250 end select
251
252 3 end subroutine set_input4d
253 !!!#############################################################################
254
255
28/75
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 3 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 3 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 3 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 3 times.
✓ Branch 34 taken 3 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 3 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 3 times.
✓ Branch 45 taken 3 times.
✓ Branch 46 taken 3 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 3 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✓ Branch 67 taken 3 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✓ Branch 70 taken 3 times.
✓ Branch 71 taken 3 times.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✓ Branch 74 taken 3 times.
✓ Branch 75 taken 3 times.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✓ Branch 78 taken 3 times.
✓ Branch 79 taken 3 times.
✗ Branch 80 not taken.
✓ Branch 81 taken 3 times.
✗ Branch 82 not taken.
30 end module input4d_layer
256 !!!#############################################################################
257