set_params Module Subroutine

module subroutine set_params(this, params)

Set the learnable parameters of the layer

This function sets the learnable parameters of the layer from a single array. This has been modified from the neural-fortran library

Arguments

Type IntentOptional Attributes Name
class(learnable_layer_type), intent(inout) :: this

Instance of the layer

real(kind=real32), intent(in), dimension(this%num_params) :: params

Learnable parameters


Source Code

  module subroutine set_params(this, params)
    !! Set the learnable parameters of the layer
    !!
    !! This function sets the learnable parameters of the layer
    !! from a single array.
    !! This has been modified from the neural-fortran library
    implicit none

    ! Arguments
    class(learnable_layer_type), intent(inout) :: this
    !! Instance of the layer
    real(real32), dimension(this%num_params), intent(in) :: params
    !! Learnable parameters

    ! Local variables
    integer :: i, start_idx, end_idx
    !! Loop indices

    if(.not.allocated(this%params))then
       call stop_program("set_params: params not allocated")
       return
    end if
    start_idx = 0
    end_idx = 0
    do i = 1, size(this%params)
       start_idx = end_idx + 1
       end_idx = start_idx + size(this%params(i)%val,1) - 1
       this%params(i)%val(:,1) = params(start_idx:end_idx)
    end do

  end subroutine set_params