assign_array Module Subroutine

recursive module subroutine assign_array(this, input)

Assign the array

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(out), target :: this

Instance of the array type

type(array_type), intent(in) :: input

Input array


Source Code

  recursive module subroutine assign_array(this, input)
    !! Assign the array
    implicit none

    ! Arguments
    class(array_type), intent(out), target :: this
    !! Instance of the array type
    type(array_type), intent(in) :: input
    !! Input array

    this%id = input%id
    this%rank = input%rank
    this%size = input%size
    this%is_sample_dependent = input%is_sample_dependent
    this%is_forward = input%is_forward
    this%is_scalar = input%is_scalar
    this%allocated = input%allocated
    if(allocated(input%shape)) this%shape = input%shape
    if(allocated(input%val)) this%val = input%val
    this%requires_grad = input%requires_grad
    if(associated(input%grad)) this%grad => input%grad
    if(associated(input%left_operand)) this%left_operand => input%left_operand
    if(associated(input%right_operand)) this%right_operand => input%right_operand
    this%operation = input%operation

    ! Transfer ownership flags - this is critical to prevent memory leaks
    this%owns_gradient = input%owns_gradient
    this%owns_left_operand = input%owns_left_operand
    this%owns_right_operand = input%owns_right_operand

    if(allocated(input%indices)) this%indices = input%indices
    if(allocated(input%adj_ja)) this%adj_ja = input%adj_ja
    if(allocated(input%mask)) this%mask = input%mask

    if(associated(input%get_partial_left)) &
         this%get_partial_left => input%get_partial_left
    if(associated(input%get_partial_right)) &
         this%get_partial_right => input%get_partial_right
    if(associated(input%get_partial_left_val)) &
         this%get_partial_left_val => input%get_partial_left_val
    if(associated(input%get_partial_right_val)) &
         this%get_partial_right_val => input%get_partial_right_val
    if(associated(input%get_partial_left_val_sum)) &
         this%get_partial_left_val_sum => input%get_partial_left_val_sum
    if(associated(input%get_partial_right_val_sum)) &
         this%get_partial_right_val_sum => input%get_partial_right_val_sum

  end subroutine assign_array