init_reshape Subroutine

private subroutine init_reshape(this, input_shape, verbose)

Initialise reshape layer

Type Bound

reshape_layer_type

Arguments

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

Instance of the reshape layer

integer, intent(in), dimension(:) :: input_shape

Input shape

integer, intent(in), optional :: verbose

Verbosity level


Source Code

  subroutine init_reshape(this, input_shape, verbose)
    !! Initialise reshape layer
    implicit none

    ! Arguments
    class(reshape_layer_type), intent(inout) :: this
    !! Instance of the reshape layer
    integer, dimension(:), intent(in) :: input_shape
    !! Input shape
    integer, optional, intent(in) :: verbose
    !! Verbosity level

    ! Local variables
    integer :: verbose_ = 0
    !! Verbosity level
    integer :: input_size, output_size
    !! Total number of elements
    integer :: i
    !! Loop index

    if(present(verbose)) verbose_ = verbose

    !---------------------------------------------------------------------------
    ! Set input shape
    !---------------------------------------------------------------------------
    this%input_rank = size(input_shape)
    if(allocated(this%input_shape)) deallocate(this%input_shape)
    allocate(this%input_shape, source=input_shape)


    !---------------------------------------------------------------------------
    ! Validate reshape compatibility
    !---------------------------------------------------------------------------
    input_size = product(input_shape)

    output_size = product(this%output_shape)

    if(input_size .ne. output_size)then
       write(*,'("ERROR: Reshape layer - incompatible shapes")')
       write(*,'("  Input shape has ",I0," elements")') input_size
       write(*,'("  Output shape has ",I0," elements")') output_size
       call stop_program("Reshape layer shape mismatch")
    end if


    !---------------------------------------------------------------------------
    ! Print layer info
    !---------------------------------------------------------------------------
    if(verbose_ .gt. 0)then
       write(*,'("  Reshape layer initialised")')
       write(*,'("    Input shape:  ",*(I0," x "))') this%input_shape
       write(*,'("    Output shape: ",*(I0," x "))') this%output_shape
    end if

  end subroutine init_reshape