Get partial derivative of softmax reverse operation (in-place version)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(array_type), | intent(in) | :: | this | |||
| real(kind=real32), | intent(in), | dimension(:,:) | :: | upstream_grad | ||
| real(kind=real32), | intent(out), | dimension(:,:) | :: | output |
pure subroutine get_partial_softmax_reverse_right_val(this, upstream_grad, output) !! Get partial derivative of softmax reverse operation (in-place version) implicit none class(array_type), intent(in) :: this real(real32), dimension(:,:), intent(in) :: upstream_grad real(real32), dimension(:,:), intent(out) :: output integer :: dim, i real(real32), dimension(size(this%val,3-this%indices(1))) :: sum_yu dim = this%indices(1) if(dim.eq.1)then sum_yu = sum(this%left_operand%val * upstream_grad, dim=dim) do concurrent(i=1:size(this%val,1)) output(i, :) = upstream_grad(i, :) - sum_yu(i) * this%left_operand%val(i, :) end do else sum_yu = sum(this%left_operand%val * upstream_grad, dim=dim) do concurrent(i=1:size(this%val,2)) output(:, i) = upstream_grad(:, i) - sum_yu(i) * this%left_operand%val(:, i) end do end if end subroutine get_partial_softmax_reverse_right_val