get_partial_sum_val_sum Subroutine

pure subroutine get_partial_sum_val_sum(this, upstream_grad, output)

Fused partial+sum for sum: output(:,1) = sum_s(spread(upstream_grad))

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_sum_val_sum(this, upstream_grad, output)
    !! Fused partial+sum for sum: output(:,1) = sum_s(spread(upstream_grad))
    implicit none
    class(array_type), intent(in) :: this
    real(real32), dimension(:,:), intent(in) :: upstream_grad
    real(real32), dimension(:), intent(out) :: output

    integer :: s, dim, n_samples

    dim = this%indices(1)
    n_samples = size(upstream_grad, 2)

    if(dim.eq.1)then
       output(:) = upstream_grad(1,1) * real(n_samples, real32)
    else if(dim.eq.2)then
       output(:) = upstream_grad(:,1) * real(n_samples, real32)
    end if
  end subroutine get_partial_sum_val_sum