get_partial_mean_all_val Subroutine

pure subroutine get_partial_mean_all_val(this, upstream_grad, output)

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in) :: this
real(kind=real32), intent(in), dimension(:,:) :: upstream_grad
real(kind=real32), intent(out), dimension(:,:) :: output

Source Code

  pure subroutine get_partial_mean_all_val(this, upstream_grad, output)
    implicit none
    class(array_type), intent(in) :: this
    real(real32), dimension(:,:), intent(in) :: upstream_grad
    real(real32), dimension(:,:), intent(out) :: output

    integer :: i, s, n_rows, n_cols
    real(real32) :: inv_count

    ! Cache values to avoid repeated accesses
    n_rows = size(output, 1)
    n_cols = size(output, 2)
    inv_count = 1.0_real32 / real(product(shape(this%left_operand%val)), real32)

    do concurrent(s = 1:n_cols, i = 1:n_rows)
       output(i,s) = upstream_grad(1,1) * inv_count
    end do
  end subroutine get_partial_mean_all_val