Skip to content

Commit 2e81268

Browse files
committed
fix(mod_network_subm): add module keyword bef subr
1 parent ebc5de7 commit 2e81268

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/mod_network_submodule.f90

+17-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
contains
1010

11-
type(network_type) function net_constructor(dims, activation) result(net)
11+
type(network_type) module function net_constructor(dims, activation) result(net)
1212
integer(ik), intent(in) :: dims(:)
1313
character(len=*), intent(in), optional :: activation
1414
call net % init(dims)
@@ -21,7 +21,7 @@ type(network_type) function net_constructor(dims, activation) result(net)
2121
end function net_constructor
2222

2323

24-
pure real(rk) function accuracy(self, x, y)
24+
pure real(rk) module function accuracy(self, x, y)
2525
class(network_type), intent(in) :: self
2626
real(rk), intent(in) :: x(:,:), y(:,:)
2727
integer(ik) :: i, good
@@ -35,7 +35,7 @@ pure real(rk) function accuracy(self, x, y)
3535
end function accuracy
3636

3737

38-
pure subroutine backprop(self, y, dw, db)
38+
pure module subroutine backprop(self, y, dw, db)
3939
class(network_type), intent(in out) :: self
4040
real(rk), intent(in) :: y(:)
4141
type(array2d), allocatable, intent(out) :: dw(:)
@@ -64,7 +64,7 @@ pure subroutine backprop(self, y, dw, db)
6464
end subroutine backprop
6565

6666

67-
pure subroutine fwdprop(self, x)
67+
pure module subroutine fwdprop(self, x)
6868
class(network_type), intent(in out) :: self
6969
real(rk), intent(in) :: x(:)
7070
integer(ik) :: n
@@ -78,7 +78,7 @@ pure subroutine fwdprop(self, x)
7878
end subroutine fwdprop
7979

8080

81-
subroutine init(self, dims)
81+
module subroutine init(self, dims)
8282
class(network_type), intent(in out) :: self
8383
integer(ik), intent(in) :: dims(:)
8484
integer(ik) :: n
@@ -93,7 +93,7 @@ subroutine init(self, dims)
9393
end subroutine init
9494

9595

96-
subroutine load(self, filename)
96+
module subroutine load(self, filename)
9797
class(network_type), intent(in out) :: self
9898
character(len=*), intent(in) :: filename
9999
integer(ik) :: fileunit, n, num_layers, layer_idx
@@ -118,14 +118,14 @@ subroutine load(self, filename)
118118
end subroutine load
119119

120120

121-
pure real(rk) function loss(self, x, y)
121+
pure real(rk) module function loss(self, x, y)
122122
class(network_type), intent(in) :: self
123123
real(rk), intent(in) :: x(:), y(:)
124124
loss = 0.5 * sum((y - self % output(x))**2) / size(x)
125125
end function loss
126126

127127

128-
pure function output_single(self, x) result(a)
128+
pure module function output_single(self, x) result(a)
129129
class(network_type), intent(in) :: self
130130
real(rk), intent(in) :: x(:)
131131
real(rk), allocatable :: a(:)
@@ -139,7 +139,7 @@ pure function output_single(self, x) result(a)
139139
end function output_single
140140

141141

142-
pure function output_batch(self, x) result(a)
142+
pure module function output_batch(self, x) result(a)
143143
class(network_type), intent(in) :: self
144144
real(rk), intent(in) :: x(:,:)
145145
real(rk), allocatable :: a(:,:)
@@ -151,7 +151,7 @@ pure function output_batch(self, x) result(a)
151151
end function output_batch
152152

153153

154-
subroutine save(self, filename)
154+
module subroutine save(self, filename)
155155
class(network_type), intent(in out) :: self
156156
character(len=*), intent(in) :: filename
157157
integer(ik) :: fileunit, n
@@ -171,20 +171,20 @@ subroutine save(self, filename)
171171
end subroutine save
172172

173173

174-
pure subroutine set_activation_equal(self, activation)
174+
pure module subroutine set_activation_equal(self, activation)
175175
class(network_type), intent(in out) :: self
176176
character(len=*), intent(in) :: activation
177177
call self % layers(:) % set_activation(activation)
178178
end subroutine set_activation_equal
179179

180180

181-
pure subroutine set_activation_layers(self, activation)
181+
pure module subroutine set_activation_layers(self, activation)
182182
class(network_type), intent(in out) :: self
183183
character(len=*), intent(in) :: activation(size(self % layers))
184184
call self % layers(:) % set_activation(activation)
185185
end subroutine set_activation_layers
186186

187-
subroutine sync(self, image)
187+
module subroutine sync(self, image)
188188
class(network_type), intent(in out) :: self
189189
integer(ik), intent(in) :: image
190190
integer(ik) :: n
@@ -197,8 +197,7 @@ subroutine sync(self, image)
197197
end do layers
198198
end subroutine sync
199199

200-
201-
subroutine train_batch(self, x, y, eta)
200+
module subroutine train_batch(self, x, y, eta)
202201
class(network_type), intent(in out) :: self
203202
real(rk), intent(in) :: x(:,:), y(:,:), eta
204203
type(array1d), allocatable :: db(:), db_batch(:)
@@ -235,8 +234,7 @@ subroutine train_batch(self, x, y, eta)
235234

236235
end subroutine train_batch
237236

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)
240238
class(network_type), intent(in out) :: self
241239
integer(ik), intent(in) :: num_epochs, batch_size
242240
real(rk), intent(in) :: x(:,:), y(:,:), eta
@@ -266,7 +264,7 @@ subroutine train_epochs(self, x, y, eta, num_epochs, batch_size)
266264
end subroutine train_epochs
267265

268266

269-
pure subroutine train_single(self, x, y, eta)
267+
pure module subroutine train_single(self, x, y, eta)
270268
class(network_type), intent(in out) :: self
271269
real(rk), intent(in) :: x(:), y(:), eta
272270
type(array2d), allocatable :: dw(:)
@@ -277,7 +275,7 @@ pure subroutine train_single(self, x, y, eta)
277275
end subroutine train_single
278276

279277

280-
pure subroutine update(self, dw, db, eta)
278+
pure module subroutine update(self, dw, db, eta)
281279
class(network_type), intent(in out) :: self
282280
class(array2d), intent(in) :: dw(:)
283281
class(array1d), intent(in) :: db(:)

0 commit comments

Comments
 (0)