GCC Code Coverage Report


Directory: src/athena/
File: src/athena/athena_activation_layer.f90
Date: 2026-04-15 16:08:59
Exec Total Coverage
Lines: 92 116 79.3%
Functions: 0 0 -%
Branches: 202 539 37.5%

Line Branch Exec Source
1 module athena__actv_layer
2 !! Module containing implementation of the activation layer
3 !!
4 !! This module wraps various activation functions into a layer type,
5 !! applying element-wise non-linear transformations to inputs.
6 !!
7 !! Mathematical operation:
8 !! y = σ(x)
9 !!
10 !! where σ is one of: relu, sigmoid, tanh, softmax, linear, etc.
11 !!
12 !! Properties:
13 !! - No learnable parameters (fixed non-linearity)
14 !! - Element-wise operation (preserves shape)
15 !! - Enables networks to learn non-linear functions
16 !! - Choice of activation affects gradient flow and convergence
17 use coreutils, only: real32, stop_program
18 use athena__base_layer, only: base_layer_type
19 use athena__misc_types, only: base_actv_type, &
20 onnx_node_type, onnx_initialiser_type, onnx_tensor_type
21 use diffstruc, only: array_type
22 implicit none
23
24
25 private
26
27 public :: actv_layer_type
28 public :: read_actv_layer, create_from_onnx_actv_layer
29
30
31 type, extends(base_layer_type) :: actv_layer_type
32 !! Layer type for activation layers
33 class(base_actv_type), allocatable :: activation
34 !! Activation function
35 contains
36 procedure, pass(this) :: set_rank => set_rank_actv
37 !! Set the input and output ranks of the layer
38 procedure, pass(this) :: set_hyperparams => set_hyperparams_actv
39 !! Set hyperparameters
40 procedure, pass(this) :: init => init_actv
41 !! Initialise layer
42 procedure, pass(this) :: print_to_unit => print_to_unit_actv
43 !! Print layer to unit
44 procedure, pass(this) :: read => read_actv
45 !! Read layer from file
46 procedure, pass(this) :: build_from_onnx => build_from_onnx_actv
47 !! Build activation layer from ONNX node and initialiser
48
49 procedure, pass(this) :: forward => forward_actv
50 !! Forward propagation derived type handler
51
52 end type actv_layer_type
53
54
55 interface actv_layer_type
56 !! Interface for the activation layer type
57 module function layer_setup( &
58 activation, &
59 input_shape, &
60 verbose &
61 ) result(layer)
62 !! Set up the activation layer
63 class(*), intent(in) :: activation
64 !! Activation function
65 integer, dimension(:), optional, intent(in) :: input_shape
66 !! Input shape
67 integer, optional, intent(in) :: verbose
68 !! Verbosity level
69 type(actv_layer_type) :: layer
70 !! Instance of the activation layer
71 end function layer_setup
72 end interface actv_layer_type
73
74
75
76 contains
77
78 !###############################################################################
79 21 module function layer_setup( &
80 activation, &
81
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
21 input_shape, &
82 verbose &
83 21 ) result(layer)
84 !! Set up the activation layer
85 use athena__activation, only: activation_setup
86 implicit none
87
88 ! Arguments
89 class(*), intent(in) :: activation
90 !! Activation function
91 integer, dimension(:), optional, intent(in) :: input_shape
92 !! Input shape
93 integer, optional, intent(in) :: verbose
94 !! Verbosity level
95 type(actv_layer_type) :: layer
96 !! Instance of the activation layer
97
98 ! Local variables
99 63 class(base_actv_type), allocatable :: activation_
100 !! Activation function
101 integer :: verbose_
102 !! Verbosity level
103
104
105 21 verbose_ = 0
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if(present(verbose)) verbose_ = verbose
107
108 !---------------------------------------------------------------------------
109 ! Set activation function
110 !---------------------------------------------------------------------------
111
5/14
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 6 taken 21 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 21 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 21 times.
✓ Branch 17 taken 21 times.
✗ Branch 18 not taken.
21 activation_ = activation_setup(activation)
112
113
114 !---------------------------------------------------------------------------
115 ! set hyperparameters
116 !---------------------------------------------------------------------------
117 call layer%set_hyperparams( &
118 activation = activation_, &
119 verbose = verbose_ &
120 21 )
121
122
123 !---------------------------------------------------------------------------
124 ! initialise layer shape
125 !---------------------------------------------------------------------------
126
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 4 times.
21 if(present(input_shape)) call layer%init( &
127 input_shape=input_shape, &
128 verbose=verbose_ &
129
4/8
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 17 times.
17 )
130
131
4/6
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 21 times.
42 end function layer_setup
132 !###############################################################################
133
134
135 !###############################################################################
136 23 subroutine set_hyperparams_actv( &
137 this, &
138 activation, &
139 input_rank, &
140 verbose &
141 )
142 !! Set hyperparameters for activation layer
143 use athena__activation, only: activation_setup
144 use coreutils, only: to_lower
145 implicit none
146
147 ! Arguments
148 class(actv_layer_type), intent(inout) :: this
149 !! Instance of the activation layer
150 integer, optional, intent(in) :: input_rank
151 !! Input rank
152 class(base_actv_type), allocatable, intent(in) :: activation
153 !! Activation function
154 integer, optional, intent(in) :: verbose
155 !! Verbosity level
156
157
158
5/8
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 23 times.
23 this%name = "actv"
159 23 this%type = "actv"
160 23 this%input_rank = 0
161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if(present(input_rank)) this%input_rank = input_rank
162 23 this%output_rank = this%input_rank
163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if(.not.allocated(activation))then
164 this%activation = activation_setup("none")
165 else
166
4/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
23 if(allocated(this%activation)) deallocate(this%activation)
167
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 23 times.
23 allocate(this%activation, source=activation)
168 end if
169
2/4
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
23 this%subtype = trim(to_lower(this%activation%name))
170
171
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 1 times.
23 if(present(verbose))then
172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if(abs(verbose).gt.0)then
173 write(*,'("ACTV activation function: ",A)') &
174 trim(this%activation%name)
175 end if
176 end if
177
178 23 end subroutine set_hyperparams_actv
179 !###############################################################################
180
181
182 !###############################################################################
183
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 subroutine init_actv(this, input_shape, verbose)
184 !! Initialise activation layer
185 implicit none
186
187 ! Arguments
188 class(actv_layer_type), intent(inout) :: this
189 !! Instance of the activation layer
190 integer, dimension(:), intent(in) :: input_shape
191 !! Input shape
192 integer, optional, intent(in) :: verbose
193 !! Verbosity level
194
195 ! Local variables
196 integer :: verbose_ = 0
197 !! Verbosity level
198
199
200 !---------------------------------------------------------------------------
201 ! initialise optional arguments
202 !---------------------------------------------------------------------------
203
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 if(present(verbose)) verbose_ = verbose
204
205
206 !---------------------------------------------------------------------------
207 ! initialise input shape
208 !---------------------------------------------------------------------------
209
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 21 times.
21 this%input_rank = size(input_shape, dim=1)
210 21 this%output_rank = this%input_rank
211
4/8
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 21 times.
21 if(.not.allocated(this%input_shape)) call this%set_shape(input_shape)
212
10/20
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 21 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 21 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 21 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 21 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 21 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 21 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 31 times.
✓ Branch 23 taken 21 times.
52 this%output_shape = this%input_shape
213
214
215 !---------------------------------------------------------------------------
216 ! Allocate arrays
217 !---------------------------------------------------------------------------
218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if(this%use_graph_input)then
219 call stop_program( &
220 "Graph input not supported for activation layer" &
221 )
222 return
223 end if
224
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
21 if(allocated(this%output)) deallocate(this%output)
225
15/26
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 21 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 21 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 21 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 21 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 21 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 21 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 21 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 21 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 21 times.
✓ Branch 33 taken 21 times.
✓ Branch 34 taken 21 times.
✓ Branch 35 taken 21 times.
✓ Branch 36 taken 21 times.
63 allocate(this%output(1,1))
226
227 end subroutine init_actv
228 !###############################################################################
229
230
231 !###############################################################################
232 6 subroutine set_rank_actv(this, input_rank, output_rank)
233 !! Set the input and output ranks of the activation layer
234 implicit none
235
236 ! Arguments
237 class(actv_layer_type), intent(inout) :: this
238 !! Instance of the activation layer
239 integer, intent(in) :: input_rank
240 !! Input rank
241 integer, intent(in) :: output_rank
242 !! Output rank
243
244 6 this%input_rank = input_rank
245 6 this%output_rank = output_rank
246
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if(this%input_rank.ne.this%output_rank)then
247 2 call stop_program("Warning: Activation layer input and output ranks differ")
248 2 return
249 end if
250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(this%input_rank.lt.1)then
251 write(*,*) "Error: Activation layer input rank must be at least 1"
252 call stop_program("Invalid activation layer input rank")
253 return
254 end if
255
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(this%output_rank.lt.1)then
256 write(*,*) "Error: Activation layer output rank must be at least 1"
257 call stop_program("Invalid activation layer output rank")
258 return
259 end if
260
261 end subroutine set_rank_actv
262 !###############################################################################
263
264
265 !##############################################################################!
266 ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * !
267 !##############################################################################!
268
269
270 !###############################################################################
271 1 subroutine print_to_unit_actv(this, unit)
272 !! Print activation layer to unit
273 use coreutils, only: to_upper
274 implicit none
275
276 ! Arguments
277 class(actv_layer_type), intent(in) :: this
278 !! Instance of the activation layer
279 integer, intent(in) :: unit
280 !! File unit
281
282
283 ! Write initial parameters
284 !---------------------------------------------------------------------------
285 1 write(unit,'(3X,"INPUT_SHAPE = ",3(1X,I0))') this%input_shape
286
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(this%activation%name .ne. 'none')then
287 1 call this%activation%print_to_unit(unit)
288 end if
289
290 1 end subroutine print_to_unit_actv
291 !###############################################################################
292
293
294 !###############################################################################
295 1 subroutine read_actv(this, unit, verbose)
296 !! Read activation layer from file
297 use athena__tools_infile, only: assign_val, assign_vec
298 use coreutils, only: to_lower, to_upper
299 use athena__activation, only: read_activation
300 implicit none
301
302 ! Arguments
303 class(actv_layer_type), intent(inout) :: this
304 !! Instance of the activation layer
305 integer, intent(in) :: unit
306 !! File unit
307 integer, optional, intent(in) :: verbose
308 !! Verbosity level
309
310 ! Local variables
311 integer :: verbose_ = 0
312 !! Verbosity level
313 integer :: stat
314 !! File status
315 integer :: itmp1, iline
316 !! Temporary integer and line counter
317 character(20) :: activation_name
318 !! Activation function name
319 3 class(base_actv_type), allocatable :: activation
320 !! Activation function
321 integer, dimension(3) :: input_shape
322 !! Input shape
323 character(256) :: buffer, tag, err_msg
324 !! Buffer for reading lines, tag for identifying lines, error message
325
326
327 ! Initialise optional arguments
328 !---------------------------------------------------------------------------
329
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(present(verbose)) verbose_ = verbose
330
331
332 ! Loop over tags in layer card
333 !---------------------------------------------------------------------------
334 1 iline = 0
335 2 tag_loop: do
336
337 ! Check for end of file
338 !------------------------------------------------------------------------
339 3 read(unit,'(A)',iostat=stat) buffer
340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(stat.ne.0)then
341 write(err_msg,'("file encountered error (EoF?) before END ",A)') &
342 to_upper(this%name)
343 call stop_program(err_msg)
344 return
345 end if
346
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
3 if(trim(adjustl(buffer)).eq."") cycle tag_loop
347
348 ! Check for end of layer card
349 !------------------------------------------------------------------------
350
4/6
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 2 times.
6 if(trim(adjustl(buffer)).eq."END "//to_upper(trim(this%name)))then
351 1 backspace(unit)
352 3 exit tag_loop
353 end if
354 2 iline = iline + 1
355
356
2/4
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 tag=trim(adjustl(buffer))
357
6/10
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
2 if(scan(buffer,"=").ne.0) tag=trim(tag(:scan(tag,"=")-1))
358
359 ! Read parameters from save file
360 !------------------------------------------------------------------------
361 4 select case(trim(tag))
362 case("INPUT_SHAPE")
363 1 call assign_vec(buffer, input_shape, itmp1)
364 case("ACTIVATION")
365 1 iline = iline - 1
366 1 backspace(unit)
367
5/14
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
1 activation = read_activation(unit, iline)
368 case default
369 !! don't look for "e" due to scientific notation of numbers
370 !! ... i.e. exponent (E+00)
371 if(scan(to_lower(trim(adjustl(buffer))),&
372 'abcdfghijklmnopqrstuvwxyz').eq.0)then
373 cycle tag_loop
374 elseif(tag(:3).eq.'END')then
375 cycle tag_loop
376 end if
377 write(err_msg,'("Unrecognised line in input file: ",A)') &
378 trim(adjustl(buffer))
379 call stop_program(err_msg)
380
3/5
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
4 return
381 end select
382 end do tag_loop
383
384
385 ! Set hyperparameters and initialise layer
386 !---------------------------------------------------------------------------
387 call this%set_hyperparams( &
388 activation = activation &
389 1 )
390 1 call this%init(input_shape = input_shape)
391
392
393 ! Check for end of layer card
394 !---------------------------------------------------------------------------
395 1 read(unit,'(A)') buffer
396
3/6
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
2 if(trim(adjustl(buffer)).ne."END "//to_upper(trim(this%name)))then
397 write(0,*) trim(adjustl(buffer))
398 write(err_msg,'("END ",A," not where expected")') to_upper(this%name)
399 call stop_program(err_msg)
400 1 return
401 end if
402
403
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 end subroutine read_actv
404 !###############################################################################
405
406
407 !###############################################################################
408 1 function read_actv_layer(unit, verbose) result(layer)
409 !! Read activation layer from file
410 implicit none
411
412 ! Arguments
413 integer, intent(in) :: unit
414 !! File unit
415 integer, optional, intent(in) :: verbose
416 !! Verbosity level
417 class(base_layer_type), allocatable :: layer
418 !! Instance of the activation layer
419
420 ! Local variables
421 integer :: verbose_ = 0
422 !! Verbosity level
423
424
425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(present(verbose)) verbose_ = verbose
426
11/58
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ 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 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 1 times.
✗ Branch 52 not taken.
✓ Branch 53 taken 1 times.
✗ Branch 54 not taken.
✓ Branch 55 taken 1 times.
✓ Branch 56 taken 1 times.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 1 times.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
2 allocate(layer, source=actv_layer_type("none"))
427 1 call layer%read(unit, verbose=verbose_)
428
429 2 end function read_actv_layer
430 !###############################################################################
431
432
433 !###############################################################################
434 3 subroutine build_from_onnx_actv(this, node, initialisers, value_info, verbose )
435 !! Read ONNX attributes for activation layer
436 implicit none
437
438 ! Arguments
439 class(actv_layer_type), intent(inout) :: this
440 !! Instance of the activation layer
441 type(onnx_node_type), intent(in) :: node
442 !! ONNX node information
443 type(onnx_initialiser_type), dimension(:), intent(in) :: initialisers
444 !! ONNX initialiser information
445 type(onnx_tensor_type), dimension(:), intent(in) :: value_info
446 !! ONNX value info
447 integer, intent(in) :: verbose
448 !! Verbosity level
449
450 ! Local variables
451 integer :: verbose_ = 0
452 !! Verbosity level
453
454 3 end subroutine build_from_onnx_actv
455 !###############################################################################
456
457
458 !###############################################################################
459
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 function create_from_onnx_actv_layer(node, initialisers, value_info, verbose) &
460 3 result(layer)
461 !! Build activation layer from attributes and return layer
462 use athena__onnx_utils, only: onnx_to_athena_activation
463 implicit none
464
465 ! Arguments
466 type(onnx_node_type), intent(in) :: node
467 !! ONNX node information
468 type(onnx_initialiser_type), dimension(:), intent(in) :: initialisers
469 !! ONNX initialiser information
470 type(onnx_tensor_type), dimension(:), intent(in) :: value_info
471 !! ONNX value info
472 integer, optional, intent(in) :: verbose
473 !! Verbosity level
474 class(base_layer_type), allocatable :: layer
475 !! Instance of the activation layer
476
477 ! Local variables
478 integer :: verbose_ = 0
479 !! Verbosity level
480
481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(present(verbose)) verbose_ = verbose
482 allocate(layer, source=actv_layer_type( &
483
12/60
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ 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 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✓ Branch 50 taken 3 times.
✗ Branch 52 not taken.
✓ Branch 53 taken 3 times.
✗ Branch 54 not taken.
✓ Branch 55 taken 3 times.
✗ Branch 56 not taken.
✓ Branch 57 taken 3 times.
✓ Branch 58 taken 3 times.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 3 times.
✓ Branch 63 taken 3 times.
✗ Branch 64 not taken.
9 onnx_to_athena_activation(trim(node%op_type))))
484
6/12
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
3 call layer%build_from_onnx(node, initialisers, value_info, verbose=verbose_)
485
486 9 end function create_from_onnx_actv_layer
487 !###############################################################################
488
489
490 !##############################################################################!
491 ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * !
492 !##############################################################################!
493
494
495 !###############################################################################
496
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 subroutine forward_actv(this, input)
497 !! Forward propagation
498 implicit none
499
500 ! Arguments
501 class(actv_layer_type), intent(inout) :: this
502 !! Instance of the fully connected layer
503 class(array_type), dimension(:,:), intent(in) :: input
504 !! Input values
505
506 ! Local variables
507 integer :: i, s
508 !! Loop indices
509 type(array_type), pointer :: ptr
510 !! Pointer array
511
512
8/14
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 19 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 19 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 19 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 19 times.
✓ Branch 18 taken 19 times.
✓ Branch 19 taken 19 times.
38 do s = 1, size(input, 2)
513
8/14
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 19 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 19 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 19 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 19 times.
✓ Branch 18 taken 19 times.
✓ Branch 19 taken 19 times.
57 do i = 1, size(input, 1)
514
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 19 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 19 times.
19 ptr => this%activation%apply(input(i,s))
515
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 19 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 19 times.
38 call this%output(i,s)%assign_and_deallocate_source(ptr)
516 end do
517 end do
518
519 19 end subroutine forward_actv
520 !###############################################################################
521
522
37/126
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 19 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ 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 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 1 times.
✓ Branch 37 taken 18 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 1 times.
✓ Branch 40 taken 12 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 1 times.
✓ Branch 43 taken 12 times.
✓ Branch 44 taken 1 times.
✓ Branch 45 taken 13 times.
✓ Branch 46 taken 12 times.
✓ Branch 47 taken 1 times.
✓ Branch 48 taken 30 times.
✓ Branch 49 taken 1 times.
✓ Branch 50 taken 18 times.
✓ Branch 51 taken 19 times.
✗ 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 12 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✓ Branch 70 taken 12 times.
✓ Branch 71 taken 12 times.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✓ Branch 74 taken 12 times.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✓ Branch 109 taken 12 times.
✗ Branch 110 not taken.
✓ Branch 111 taken 12 times.
✗ Branch 112 not taken.
✓ Branch 113 taken 11 times.
✓ Branch 114 taken 1 times.
✓ Branch 115 taken 1 times.
✗ Branch 116 not taken.
✓ Branch 118 taken 12 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 11 times.
✓ Branch 121 taken 1 times.
✓ Branch 122 taken 12 times.
✗ Branch 123 not taken.
✓ Branch 124 taken 11 times.
✓ Branch 125 taken 1 times.
✓ Branch 126 taken 12 times.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✓ Branch 129 taken 12 times.
✗ Branch 130 not taken.
✓ Branch 131 taken 12 times.
90 end module athena__actv_layer
523