GCC Code Coverage Report


Directory: src/athena/
File: athena_activation_none.f90
Date: 2025-12-10 07:37:07
Exec Total Coverage
Lines: 0 0 100.0%
Functions: 0 0 -%
Branches: 0 0 -%

Line Branch Exec Source
1 module athena__activation_none
2 !! Module containing implementation of no activation function (identity)
3 !!
4 !! This module implements the identity function (no activation).
5 !!
6 !! Mathematical operation:
7 !! \[ f(x) = x \]
8 !!
9 !! Derivative:
10 !! \[ f'(x) = 1 \]
11 !!
12 !! Properties: Preserves input as-is, linear transformation
13 !! Used for regression outputs or when no non-linearity is desired
14 use coreutils, only: real32, print_warning
15 use diffstruc, only: array_type
16 use athena__misc_types, only: base_actv_type
17 use athena__misc_types, only: onnx_attribute_type
18 implicit none
19
20
21 private
22
23 public :: none_actv_type, create_from_onnx_none_activation
24
25
26 type, extends(base_actv_type) :: none_actv_type
27 contains
28 procedure, pass(this) :: apply => apply_none
29 procedure, pass(this) :: reset => reset_none
30 procedure, pass(this) :: apply_attributes => apply_attributes_none
31 procedure, pass(this) :: export_attributes => export_attributes_none
32 end type none_actv_type
33
34 interface none_actv_type
35 procedure initialise
36 end interface none_actv_type
37
38
39
40 contains
41
42 !###############################################################################
43 function initialise(attributes) result(activation)
44 !! Initialise a none (no-op) activation function
45 implicit none
46
47 ! Arguments
48 type(none_actv_type) :: activation
49 !! None activation type
50 type(onnx_attribute_type), dimension(:), intent(in), optional :: attributes
51 !! Optional array of ONNX attributes
52
53
54 call activation%reset()
55 if(present(attributes)) then
56 call activation%apply_attributes(attributes)
57 end if
58
59 end function initialise
60 !-------------------------------------------------------------------------------
61 pure subroutine reset_none(this)
62 !! Reset none activation function attributes and variables
63 implicit none
64
65 ! Arguments
66 class(none_actv_type), intent(inout) :: this
67 !! None activation type
68
69 this%name = "none"
70 this%scale = 1._real32
71 this%threshold = 0._real32
72 this%apply_scaling = .false.
73
74 end subroutine reset_none
75 !-------------------------------------------------------------------------------
76 function create_from_onnx_none_activation(attributes) result(activation)
77 !! Create none activation function from ONNX attributes
78 implicit none
79
80 ! Arguments
81 type(onnx_attribute_type), dimension(:), intent(in) :: attributes
82 !! Array of ONNX attributes
83
84 class(base_actv_type), allocatable :: activation
85 !! Instance of activation type
86
87 allocate(activation, source = none_actv_type(attributes = attributes))
88
89 end function create_from_onnx_none_activation
90 !###############################################################################
91
92
93 !###############################################################################
94 subroutine apply_attributes_none(this, attributes)
95 !! Load ONNX attributes into none activation function
96 implicit none
97
98 ! Arguments
99 class(none_actv_type), intent(inout) :: this
100 !! None activation type
101 type(onnx_attribute_type), dimension(:), intent(in) :: attributes
102 !! Array of ONNX attributes
103
104 ! Local variables
105 integer :: i
106 !! Loop variable
107
108 ! Load provided attributes
109 do i=1, size(attributes,dim=1)
110 select case(trim(attributes(i)%name))
111 case("name")
112 if(trim(attributes(i)%val) .ne. trim(this%name)) then
113 call print_warning( &
114 'None activation: name attribute "' // &
115 trim(attributes(i)%val) // &
116 '"" does not match expected "' // trim(this%name)//'"' &
117 )
118
119 end if
120 case default
121 call print_warning( &
122 'None activation: unknown attribute '// &
123 trim(attributes(i)%name) &
124 )
125 end select
126 end do
127
128 end subroutine apply_attributes_none
129 !###############################################################################
130
131
132 !###############################################################################
133 pure function export_attributes_none(this) result(attributes)
134 !! Export none activation function attributes as ONNX attributes
135 implicit none
136
137 ! Arguments
138 class(none_actv_type), intent(in) :: this
139 !! None activation type
140 type(onnx_attribute_type), allocatable, dimension(:) :: attributes
141 !! Array of ONNX attributes
142
143 ! Local variables
144 character(50) :: buffer
145 !! Temporary string buffer
146
147 ! No attributes for none activation
148 allocate(attributes(1))
149
150 write(buffer, '(A)') this%name
151 attributes(1) = onnx_attribute_type( &
152 "name", "string", trim(adjustl(buffer)) )
153
154 end function export_attributes_none
155 !###############################################################################
156
157
158 !###############################################################################
159 function apply_none(this, val) result(output)
160 !! Apply identity activation to 1D array
161 !!
162 !! Simply returns scaled input: f = scale * x
163 implicit none
164
165 ! Arguments
166 class(none_actv_type), intent(in) :: this
167 !! None activation type
168 type(array_type), intent(in) :: val
169 !! Input values
170 type(array_type), pointer :: output
171 !! Scaled output values
172
173 output => val * 1._real32 ! multiplication by 1 to ensure new allocation
174 end function apply_none
175 !###############################################################################
176
177 end module athena__activation_none
178