get_partial_matmul_left Function

function get_partial_matmul_left(this, upstream_grad) result(output)

Get partial derivative with respect to left operand of matmul

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this
type(array_type), intent(in) :: upstream_grad

Return Value type(array_type)


Source Code

  function get_partial_matmul_left(this, upstream_grad) result(output)
    !! Get partial derivative with respect to left operand of matmul
    implicit none
    class(array_type), intent(inout) :: this
    type(array_type), intent(in) :: upstream_grad
    type(array_type) :: output

    logical :: right_is_temporary_local
    type(array_type), pointer :: ptr

    right_is_temporary_local = this%right_operand%is_temporary
    this%right_operand%is_temporary = .false.
    if(size(this%right_operand%shape).eq.2)then
       if(this%is_forward)then
          ptr => matmul( upstream_grad, this%right_operand )
       else
          ptr => matmul( upstream_grad, transpose(this%right_operand) )
       end if
    elseif(size(upstream_grad%shape).eq.2)then
       if(this%is_forward)then
          ptr => matmul( upstream_grad, this%right_operand )
       else
          ptr => matmul( transpose(upstream_grad), this%right_operand )
       end if
    else
       ptr => upstream_grad .outer. this%right_operand
    end if
    this%right_operand%is_temporary = right_is_temporary_local
    call output%assign_and_deallocate_source(ptr)

  end function get_partial_matmul_left