reshape_array Module Function

module function reshape_array(a, new_shape) result(c)

Reshape an autodiff array

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in), target :: a
integer, intent(in), dimension(:) :: new_shape

Return Value type(array_type), pointer


Source Code

  module function reshape_array(a, new_shape) result(c)
    !! Reshape an autodiff array
    implicit none
    class(array_type), intent(in), target :: a
    integer, dimension(:), intent(in) :: new_shape
    type(array_type), pointer :: c

    integer :: s

    c => a%create_result(array_shape = [ new_shape, size(a%val,2) ])
    do concurrent(s=1:size(a%val,2))
       c%val(:, s) = a%val(:, s)
    end do
    c%indices = a%shape

    c%get_partial_left => get_partial_reshape
    c%get_partial_left_val => get_partial_reshape_val
    if(a%requires_grad) then
       c%requires_grad = .true.
       c%is_forward = a%is_forward
       c%operation = 'reshape'
       c%left_operand => a
       c%owns_left_operand = a%is_temporary
    end if
  end function reshape_array