get_partial_negate_val_sum Subroutine

pure subroutine get_partial_negate_val_sum(this, upstream_grad, output)

Fused partial+sum for negate: output(:,1) = -sum_over_samples(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_negate_val_sum(this, upstream_grad, output)
    !! Fused partial+sum for negate: output(:,1) = -sum_over_samples(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, n_samples

    n_samples = size(upstream_grad, 2)
    if(size(output,1).eq.1 .and. size(upstream_grad,1).gt.1)then
       output(1) = -sum(upstream_grad)
    else if(n_samples .eq. 1)then
       output(:) = -upstream_grad(:,1)
    else
       output(:) = -upstream_grad(:,1)
       do s = 2, n_samples
          output(:) = output(:) - upstream_grad(:,s)
       end do
    end if
  end subroutine get_partial_negate_val_sum