Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/nf/nf_conv1d_layer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module nf_conv1d_layer
procedure :: backward
procedure :: get_gradients_ptr
procedure :: get_num_params
procedure :: get_params
procedure :: get_params_ptr
procedure :: init
procedure :: set_params
Expand Down Expand Up @@ -89,15 +88,6 @@ pure module function get_num_params(self) result(num_params)
!! Number of parameters
end function get_num_params

module function get_params(self) result(params)
!! Return the parameters (weights and biases) of this layer.
!! The parameters are ordered as weights first, biases second.
class(conv1d_layer), intent(in), target :: self
!! A `conv1d_layer` instance
real, allocatable :: params(:)
!! Parameters to get
end function get_params

module subroutine get_params_ptr(self, w_ptr, b_ptr)
!! Return pointers to the parameters (weights and biases) of this layer.
class(conv1d_layer), intent(in), target :: self
Expand Down
8 changes: 0 additions & 8 deletions src/nf/nf_conv1d_layer_submodule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,6 @@ pure module function get_num_params(self) result(num_params)
num_params = product(shape(self % kernel)) + size(self % biases)
end function get_num_params

module function get_params(self) result(params)
class(conv1d_layer), intent(in), target :: self
real, allocatable :: params(:)
real, pointer :: w_(:) => null()
w_(1:size(self % kernel)) => self % kernel
params = [ w_, self % biases]
end function get_params

module subroutine get_params_ptr(self, w_ptr, b_ptr)
class(conv1d_layer), intent(in), target :: self
real, pointer, intent(out) :: w_ptr(:)
Expand Down
10 changes: 0 additions & 10 deletions src/nf/nf_conv2d_layer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ module nf_conv2d_layer
procedure :: backward
procedure :: get_gradients_ptr
procedure :: get_num_params
procedure :: get_params
procedure :: get_params_ptr
procedure :: init
procedure :: set_params
Expand Down Expand Up @@ -90,15 +89,6 @@ pure module function get_num_params(self) result(num_params)
!! Number of parameters
end function get_num_params

module function get_params(self) result(params)
!! Return the parameters (weights and biases) of this layer.
!! The parameters are ordered as weights first, biases second.
class(conv2d_layer), intent(in), target :: self
!! A `conv2d_layer` instance
real, allocatable :: params(:)
!! Parameters to get
end function get_params

module subroutine get_params_ptr(self, w_ptr, b_ptr)
!! Return pointers to the parameters (weights and biases) of this layer.
class(conv2d_layer), intent(in), target :: self
Expand Down
16 changes: 0 additions & 16 deletions src/nf/nf_conv2d_layer_submodule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,6 @@ pure module function get_num_params(self) result(num_params)
num_params = product(shape(self % kernel)) + size(self % biases)
end function get_num_params


module function get_params(self) result(params)
class(conv2d_layer), intent(in), target :: self
real, allocatable :: params(:)

real, pointer :: w_(:) => null()

w_(1:size(self % kernel)) => self % kernel

params = [ &
w_, &
self % biases &
]

end function get_params


module subroutine get_params_ptr(self, w_ptr, b_ptr)
class(conv2d_layer), intent(in), target :: self
Expand Down
10 changes: 0 additions & 10 deletions src/nf/nf_dense_layer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module nf_dense_layer
procedure :: forward
procedure :: get_gradients_ptr
procedure :: get_num_params
procedure :: get_params
procedure :: get_params_ptr
procedure :: init
procedure :: set_params
Expand Down Expand Up @@ -88,15 +87,6 @@ pure module function get_num_params(self) result(num_params)
!! Number of parameters in this layer
end function get_num_params

module function get_params(self) result(params)
!! Return the parameters (weights and biases) of this layer.
!! The parameters are ordered as weights first, biases second.
class(dense_layer), intent(in), target :: self
!! Dense layer instance
real, allocatable :: params(:)
!! Parameters of this layer
end function get_params

module subroutine get_params_ptr(self, w_ptr, b_ptr)
class(dense_layer), intent(in), target :: self
real, pointer, intent(out) :: w_ptr(:)
Expand Down
16 changes: 0 additions & 16 deletions src/nf/nf_dense_layer_submodule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ pure module function get_num_params(self) result(num_params)
end function get_num_params


module function get_params(self) result(params)
class(dense_layer), intent(in), target :: self
real, allocatable :: params(:)

real, pointer :: w_(:) => null()

w_(1:size(self % weights)) => self % weights

params = [ &
w_, &
self % biases &
]

end function get_params


module subroutine get_params_ptr(self, w_ptr, b_ptr)
class(dense_layer), intent(in), target :: self
real, pointer, intent(out) :: w_ptr(:)
Expand Down
11 changes: 11 additions & 0 deletions src/nf/nf_layer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ module function get_params(self) result(params)
!! Parameters of this layer
end function get_params

module subroutine get_params_ptr(self, w_ptr, b_ptr)
!! Returns the parameters of this layer as pointers.
!! This is used for layers that have weights and biases.
class(layer), intent(in) :: self
!! Layer instance
real, pointer :: w_ptr(:)
!! Pointer to weights of this layer
real, pointer :: b_ptr(:)
!! Pointer to biases of this layer
end subroutine get_params_ptr

module subroutine set_params(self, params)
!! Returns the parameters of this layer.
class(layer), intent(in out) :: self
Expand Down
27 changes: 22 additions & 5 deletions src/nf/nf_layer_submodule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ end function get_num_params
module function get_params(self) result(params)
class(layer), intent(in) :: self
real, allocatable :: params(:)
real, pointer :: w_ptr(:)
real, pointer :: b_ptr(:)

select type (this_layer => self % p)
type is (input1d_layer)
Expand All @@ -649,15 +651,27 @@ module function get_params(self) result(params)
type is (input3d_layer)
! No parameters to get.
type is (dense_layer)
params = this_layer % get_params()
call this_layer % get_params_ptr(w_ptr, b_ptr)
allocate(params(size(w_ptr) + size(b_ptr)))
params(1:size(w_ptr)) = w_ptr
params(size(w_ptr)+1:) = b_ptr
type is (dropout_layer)
! No parameters to get.
type is (conv1d_layer)
params = this_layer % get_params()
call this_layer % get_params_ptr(w_ptr, b_ptr)
allocate(params(size(w_ptr) + size(b_ptr)))
params(1:size(w_ptr)) = w_ptr
params(size(w_ptr)+1:) = b_ptr
type is (conv2d_layer)
params = this_layer % get_params()
call this_layer % get_params_ptr(w_ptr, b_ptr)
allocate(params(size(w_ptr) + size(b_ptr)))
params(1:size(w_ptr)) = w_ptr
params(size(w_ptr)+1:) = b_ptr
type is (locally_connected2d_layer)
params = this_layer % get_params()
call this_layer % get_params_ptr(w_ptr, b_ptr)
allocate(params(size(w_ptr) + size(b_ptr)))
params(1:size(w_ptr)) = w_ptr
params(size(w_ptr)+1:) = b_ptr
type is (maxpool1d_layer)
! No parameters to get.
type is (maxpool2d_layer)
Expand All @@ -669,7 +683,10 @@ module function get_params(self) result(params)
type is (reshape3d_layer)
! No parameters to get.
type is (linear2d_layer)
params = this_layer % get_params()
call this_layer % get_params_ptr(w_ptr, b_ptr)
allocate(params(size(w_ptr) + size(b_ptr)))
params(1:size(w_ptr)) = w_ptr
params(size(w_ptr)+1:) = b_ptr
type is (self_attention_layer)
params = this_layer % get_params()
type is (embedding_layer)
Expand Down
10 changes: 0 additions & 10 deletions src/nf/nf_locally_connected2d_layer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ module nf_locally_connected2d_layer
procedure :: get_gradients
procedure :: get_gradients_ptr
procedure :: get_num_params
procedure :: get_params
procedure :: get_params_ptr
procedure :: init
procedure :: set_params
Expand Down Expand Up @@ -90,15 +89,6 @@ pure module function get_num_params(self) result(num_params)
!! Number of parameters
end function get_num_params

module function get_params(self) result(params)
!! Return the parameters (weights and biases) of this layer.
!! The parameters are ordered as weights first, biases second.
class(locally_connected2d_layer), intent(in), target :: self
!! A `locally_connected2d_layer` instance
real, allocatable :: params(:)
!! Parameters to get
end function get_params

module subroutine get_params_ptr(self, w_ptr, b_ptr)
class(locally_connected2d_layer), intent(in), target :: self
real, pointer, intent(out) :: w_ptr(:)
Expand Down
6 changes: 0 additions & 6 deletions src/nf/nf_locally_connected2d_layer_submodule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ pure module function get_num_params(self) result(num_params)
num_params = product(shape(self % kernel)) + product(shape(self % biases))
end function get_num_params

module function get_params(self) result(params)
class(locally_connected2d_layer), intent(in), target :: self
real, allocatable :: params(:)
params = [self % kernel, self % biases]
end function get_params

module subroutine get_params_ptr(self, w_ptr, b_ptr)
class(locally_connected2d_layer), intent(in), target :: self
real, pointer, intent(out) :: w_ptr(:)
Expand Down