Dot product of two autodiff arrays
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(array_type), | intent(in), | target | :: | a | ||
| class(array_type), | intent(in), | target | :: | b |
module function dot_product_arrays(a, b) result(c) !! Dot product of two autodiff arrays implicit none class(array_type), intent(in), target :: a, b type(array_type), pointer :: c integer :: s ! check shapes if(size(a%shape).ne.1 .or. size(b%shape).ne.1)then call stop_program("dot_product_arrays: only 1D arrays supported") elseif(any(shape(a%val).ne.shape(b%val)))then call stop_program("dot_product_arrays: array length mismatch") end if c => a%create_result(array_shape = [1, size(a%val,2)]) do concurrent(s=1:size(a%val,2)) c%val(1,s) = dot_product(a%val(:,s), b%val(:,s)) end do c%get_partial_left => get_partial_dot_product_left c%get_partial_right => get_partial_dot_product_right c%get_partial_left_val => get_partial_dot_product_left_val c%get_partial_right_val => get_partial_dot_product_right_val c%is_sample_dependent = a%is_sample_dependent if(a%requires_grad .or. b%requires_grad) then c%requires_grad = .true. c%is_forward = a%is_forward .or. b%is_forward c%operation = 'dot_product' c%left_operand => a c%right_operand => b c%owns_left_operand = a%is_temporary c%owns_right_operand = b%is_temporary end if end function dot_product_arrays