Merge two autodiff arrays based on a mask
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(array_type), | intent(in), | target | :: | tsource | ||
| class(array_type), | intent(in), | target | :: | fsource | ||
| logical, | intent(in), | dimension(:,:) | :: | mask |
function merge_array(tsource, fsource, mask) result(c) !! Merge two autodiff arrays based on a mask implicit none class(array_type), intent(in), target :: tsource class(array_type), intent(in), target :: fsource logical, dimension(:,:), intent(in) :: mask type(array_type), pointer :: c integer :: i, j c => tsource%create_result(array_shape=[size(tsource%val,1), size(tsource%val,2)]) ! merge 1D array by using shape to swap dimensions do concurrent(i=1:size(tsource%val,1), j=1:size(tsource%val,2)) if(mask(i,j)) then c%val(i,j) = tsource%val(i,j) else c%val(i,j) = fsource%val(i,j) end if end do c%mask = mask c%get_partial_left => get_partial_merge_left c%get_partial_right => get_partial_merge_right c%get_partial_left_val => get_partial_merge_left_val c%get_partial_right_val => get_partial_merge_right_val if(tsource%requires_grad.or. fsource%requires_grad) then c%requires_grad = .true. c%is_forward = tsource%is_forward .or. fsource%is_forward c%operation = 'merge' c%left_operand => tsource c%right_operand => fsource c%owns_left_operand = tsource%is_temporary c%owns_right_operand = fsource%is_temporary end if end function merge_array