8
8
9
9
contains
10
10
11
- type (network_type) function net_constructor(dims, activation) result(net)
11
+ type (network_type) module function net_constructor(dims, activation) result(net)
12
12
integer (ik), intent (in ) :: dims(:)
13
13
character (len=* ), intent (in ), optional :: activation
14
14
call net % init(dims)
@@ -21,7 +21,7 @@ type(network_type) function net_constructor(dims, activation) result(net)
21
21
end function net_constructor
22
22
23
23
24
- pure real (rk) function accuracy(self, x, y)
24
+ pure real (rk) module function accuracy(self, x, y)
25
25
class(network_type), intent (in ) :: self
26
26
real (rk), intent (in ) :: x(:,:), y(:,:)
27
27
integer (ik) :: i, good
@@ -35,7 +35,7 @@ pure real(rk) function accuracy(self, x, y)
35
35
end function accuracy
36
36
37
37
38
- pure subroutine backprop (self , y , dw , db )
38
+ pure module subroutine backprop(self, y, dw, db)
39
39
class(network_type), intent (in out ) :: self
40
40
real (rk), intent (in ) :: y(:)
41
41
type (array2d), allocatable , intent (out ) :: dw(:)
@@ -64,7 +64,7 @@ pure subroutine backprop(self, y, dw, db)
64
64
end subroutine backprop
65
65
66
66
67
- pure subroutine fwdprop (self , x )
67
+ pure module subroutine fwdprop(self, x)
68
68
class(network_type), intent (in out ) :: self
69
69
real (rk), intent (in ) :: x(:)
70
70
integer (ik) :: n
@@ -78,7 +78,7 @@ pure subroutine fwdprop(self, x)
78
78
end subroutine fwdprop
79
79
80
80
81
- subroutine init (self , dims )
81
+ module subroutine init (self , dims )
82
82
class(network_type), intent (in out ) :: self
83
83
integer (ik), intent (in ) :: dims(:)
84
84
integer (ik) :: n
@@ -93,7 +93,7 @@ subroutine init(self, dims)
93
93
end subroutine init
94
94
95
95
96
- subroutine load (self , filename )
96
+ module subroutine load (self , filename )
97
97
class(network_type), intent (in out ) :: self
98
98
character (len=* ), intent (in ) :: filename
99
99
integer (ik) :: fileunit, n, num_layers, layer_idx
@@ -118,14 +118,14 @@ subroutine load(self, filename)
118
118
end subroutine load
119
119
120
120
121
- pure real (rk) function loss(self, x, y)
121
+ pure real (rk) module function loss(self, x, y)
122
122
class(network_type), intent (in ) :: self
123
123
real (rk), intent (in ) :: x(:), y(:)
124
124
loss = 0.5 * sum ((y - self % output(x))** 2 ) / size (x)
125
125
end function loss
126
126
127
127
128
- pure function output_single (self , x ) result(a)
128
+ pure module function output_single(self, x) result(a)
129
129
class(network_type), intent (in ) :: self
130
130
real (rk), intent (in ) :: x(:)
131
131
real (rk), allocatable :: a(:)
@@ -139,7 +139,7 @@ pure function output_single(self, x) result(a)
139
139
end function output_single
140
140
141
141
142
- pure function output_batch (self , x ) result(a)
142
+ pure module function output_batch(self, x) result(a)
143
143
class(network_type), intent (in ) :: self
144
144
real (rk), intent (in ) :: x(:,:)
145
145
real (rk), allocatable :: a(:,:)
@@ -151,7 +151,7 @@ pure function output_batch(self, x) result(a)
151
151
end function output_batch
152
152
153
153
154
- subroutine save (self , filename )
154
+ module subroutine save (self , filename )
155
155
class(network_type), intent (in out ) :: self
156
156
character (len=* ), intent (in ) :: filename
157
157
integer (ik) :: fileunit, n
@@ -171,20 +171,20 @@ subroutine save(self, filename)
171
171
end subroutine save
172
172
173
173
174
- pure subroutine set_activation_equal (self , activation )
174
+ pure module subroutine set_activation_equal(self, activation)
175
175
class(network_type), intent (in out ) :: self
176
176
character (len=* ), intent (in ) :: activation
177
177
call self % layers(:) % set_activation(activation)
178
178
end subroutine set_activation_equal
179
179
180
180
181
- pure subroutine set_activation_layers (self , activation )
181
+ pure module subroutine set_activation_layers(self, activation)
182
182
class(network_type), intent (in out ) :: self
183
183
character (len=* ), intent (in ) :: activation(size (self % layers))
184
184
call self % layers(:) % set_activation(activation)
185
185
end subroutine set_activation_layers
186
186
187
- subroutine sync (self , image )
187
+ module subroutine sync (self , image )
188
188
class(network_type), intent (in out ) :: self
189
189
integer (ik), intent (in ) :: image
190
190
integer (ik) :: n
@@ -197,8 +197,7 @@ subroutine sync(self, image)
197
197
end do layers
198
198
end subroutine sync
199
199
200
-
201
- subroutine train_batch (self , x , y , eta )
200
+ module subroutine train_batch (self , x , y , eta )
202
201
class(network_type), intent (in out ) :: self
203
202
real (rk), intent (in ) :: x(:,:), y(:,:), eta
204
203
type (array1d), allocatable :: db(:), db_batch(:)
@@ -235,8 +234,7 @@ subroutine train_batch(self, x, y, eta)
235
234
236
235
end subroutine train_batch
237
236
238
-
239
- subroutine train_epochs (self , x , y , eta , num_epochs , batch_size )
237
+ module subroutine train_epochs (self , x , y , eta , num_epochs , batch_size )
240
238
class(network_type), intent (in out ) :: self
241
239
integer (ik), intent (in ) :: num_epochs, batch_size
242
240
real (rk), intent (in ) :: x(:,:), y(:,:), eta
@@ -266,7 +264,7 @@ subroutine train_epochs(self, x, y, eta, num_epochs, batch_size)
266
264
end subroutine train_epochs
267
265
268
266
269
- pure subroutine train_single (self , x , y , eta )
267
+ pure module subroutine train_single(self, x, y, eta)
270
268
class(network_type), intent (in out ) :: self
271
269
real (rk), intent (in ) :: x(:), y(:), eta
272
270
type (array2d), allocatable :: dw(:)
@@ -277,7 +275,7 @@ pure subroutine train_single(self, x, y, eta)
277
275
end subroutine train_single
278
276
279
277
280
- pure subroutine update (self , dw , db , eta )
278
+ pure module subroutine update(self, dw, db, eta)
281
279
class(network_type), intent (in out ) :: self
282
280
class(array2d), intent (in ) :: dw(:)
283
281
class(array1d), intent (in ) :: db(:)
0 commit comments