Skip to content

Commit ed3d802

Browse files
committed
fix(network/layer): ifort func result workaround
This commit works around a problem in which ifort does not allow function prefixes to contain a type declaration when a function has an explicitly named result.
1 parent 3f59a28 commit ed3d802

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/mod_layer.f90

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,30 @@ module mod_layer
3131
end type array2d
3232

3333
interface layer_type
34-
type(layer_type) module function constructor(this_size, next_size) result(layer)
34+
module function constructor(this_size, next_size) result(layer)
3535
!! Layer class constructor. this_size is the number of neurons in the layer.
3636
!! next_size is the number of neurons in the next layer, used to allocate
3737
!! the weights.
3838
implicit none
3939
integer(ik), intent(in) :: this_size, next_size
40+
type(layer_type) layer
4041
end function constructor
4142
end interface layer_type
4243

4344
interface array1d
44-
pure type(array1d) module function array1d_constructor(length) result(a)
45+
pure module function array1d_constructor(length) result(a)
4546
!! Overloads the default type constructor.
4647
implicit none
4748
integer(ik), intent(in) :: length
49+
type(array1d) :: a
4850
end function array1d_constructor
4951
end interface array1d
5052

5153
interface array2d
52-
pure type(array2d) module function array2d_constructor(dims) result(a)
54+
pure module function array2d_constructor(dims) result(a)
5355
!! Overloads the default type constructor.
5456
integer(ik), intent(in) :: dims(2)
57+
type(array2d) :: a
5558
end function array2d_constructor
5659
end interface array2d
5760

src/mod_layer_submodule.f90

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
contains
88

9-
type(layer_type) module function constructor(this_size, next_size) result(layer)
9+
module function constructor(this_size, next_size) result(layer)
1010
integer(ik), intent(in) :: this_size, next_size
11+
type(layer_type) :: layer
1112
allocate(layer % a(this_size))
1213
allocate(layer % z(this_size))
1314
layer % a = 0
@@ -16,14 +17,16 @@ type(layer_type) module function constructor(this_size, next_size) result(layer)
1617
layer % b = randn(this_size)
1718
end function constructor
1819

19-
pure type(array1d) module function array1d_constructor(length) result(a)
20+
pure module function array1d_constructor(length) result(a)
2021
integer(ik), intent(in) :: length
22+
type(array1d) :: a
2123
allocate(a % array(length))
2224
a % array = 0
2325
end function array1d_constructor
2426

25-
pure type(array2d) module function array2d_constructor(dims) result(a)
27+
pure module function array2d_constructor(dims) result(a)
2628
integer(ik), intent(in) :: dims(2)
29+
type(array2d) :: a
2730
allocate(a % array(dims(1), dims(2)))
2831
a % array = 0
2932
end function array2d_constructor

src/mod_network.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ module mod_network
4040

4141
interface network_type
4242

43-
type(network_type) module function net_constructor(dims, activation) result(net)
43+
module function net_constructor(dims, activation) result(net)
4444
!! Network class constructor. Size of input array dims indicates the total
4545
!! number of layers (input + hidden + output), and the value of its elements
4646
!! corresponds the size of each layer.
4747
implicit none
4848
integer(ik), intent(in) :: dims(:)
4949
character(len=*), intent(in), optional :: activation
50+
type(network_type) :: net
5051
end function net_constructor
5152

5253
end interface network_type
@@ -62,7 +63,6 @@ pure real(rk) module function accuracy(self, x, y)
6263
real(rk), intent(in) :: x(:,:), y(:,:)
6364
end function accuracy
6465

65-
6666
pure module subroutine backprop(self, y, dw, db)
6767
!! Applies a backward propagation through the network
6868
!! and returns the weight and bias gradients.
@@ -82,7 +82,6 @@ pure module subroutine fwdprop(self, x)
8282
real(rk), intent(in) :: x(:)
8383
end subroutine fwdprop
8484

85-
8685
module subroutine init(self, dims)
8786
!! Allocates and initializes the layers with given dimensions dims.
8887
implicit none

src/mod_network_submodule.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
contains
1010

11-
type(network_type) module function net_constructor(dims, activation) result(net)
11+
module function net_constructor(dims, activation) result(net)
1212
integer(ik), intent(in) :: dims(:)
1313
character(len=*), intent(in), optional :: activation
14+
type(network_type) :: net
1415
call net % init(dims)
1516
if (present(activation)) then
1617
call net % set_activation(activation)
@@ -20,7 +21,6 @@ type(network_type) module function net_constructor(dims, activation) result(net)
2021
call net % sync(1)
2122
end function net_constructor
2223

23-
2424
pure real(rk) module function accuracy(self, x, y)
2525
class(network_type), intent(in) :: self
2626
real(rk), intent(in) :: x(:,:), y(:,:)

0 commit comments

Comments
 (0)