sum_all_array Module Function

module function sum_all_array(a) result(c)

Sum all elements in an autodiff array

Arguments

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

Return Value type(array_type), pointer


Source Code

  module function sum_all_array(a) result(c)
    !! Sum all elements in an autodiff array
    implicit none
    class(array_type), intent(in), target :: a
    type(array_type), pointer :: c

    integer :: i, s, n_rows, n_cols

    n_rows = size(a%val, 1)
    n_cols = size(a%val, 2)

    c => a%create_result(array_shape=[1, 1])
    c%val(1,1) = sum(a%val)

    c%indices = [1, 1]

    c%get_partial_left => get_partial_sum_all
    c%get_partial_left_val => get_partial_sum_all_val
    c%get_partial_left_val_sum => get_partial_sum_all_val_sum
    if(a%requires_grad)then
       c%requires_grad = .true.
       c%is_forward = a%is_forward
       c%operation = 'sum_all_array'
       c%left_operand => a
       c%owns_left_operand = a%is_temporary
    end if

  end function sum_all_array