emit_weight_initialiser_2d Subroutine

public subroutine emit_weight_initialiser_2d(name, nrows, ncols, weight_data, inits, num_inits)

Store a 2D weight matrix as an ONNX initialiser in row-major order.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name
integer, intent(in) :: nrows
integer, intent(in) :: ncols
real(kind=real32), intent(in) :: weight_data(:)
type(onnx_initialiser_type), intent(inout), dimension(:) :: inits
integer, intent(inout) :: num_inits

Source Code

  subroutine emit_weight_initialiser_2d( &
       name, nrows, ncols, weight_data, inits, num_inits)
    !! Store a 2D weight matrix as an ONNX initialiser in row-major order.
    implicit none

    ! Arguments
    character(*), intent(in) :: name
    integer, intent(in) :: nrows, ncols
    real(real32), intent(in) :: weight_data(:)
    type(onnx_initialiser_type), intent(inout), dimension(:) :: inits
    integer, intent(inout) :: num_inits

    num_inits = num_inits + 1
    inits(num_inits)%name = trim(name)
    inits(num_inits)%data_type = 1
    allocate(inits(num_inits)%dims(2))
    inits(num_inits)%dims = [ nrows, ncols ]
    allocate(inits(num_inits)%data(size(weight_data)))
    call col_to_row_major_2d(weight_data, inits(num_inits)%data, nrows, ncols)

  end subroutine emit_weight_initialiser_2d