Unpack an autodiff array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(array_type), | intent(in), | target | :: | a | ||
| integer, | intent(in), | dimension(:) | :: | indices | ||
| integer, | intent(in) | :: | dim | |||
| integer, | intent(in) | :: | new_size |
module function unpack_indices_array(a, indices, dim, new_size) result(c) !! Unpack an autodiff array implicit none class(array_type), intent(in), target :: a integer, dimension(:), intent(in) :: indices integer, intent(in) :: new_size, dim type(array_type), pointer :: c integer :: i, s if(dim.eq.1)then c => a%create_result(array_shape = [ new_size, size(a%val,2) ]) c%val = 0.0_real32 do concurrent(i=1:size(indices,1), s=1:size(a%val,2)) c%val(indices(i),s) = a%val(i,s) end do elseif(dim.eq.2)then c => a%create_result(array_shape = [ size(a%val,1), new_size ]) c%val = 0.0_real32 do concurrent(i=1:size(a%val,1), s=1:new_size) c%val(i,indices(s)) = a%val(i,s) end do end if c%indices = indices allocate(c%adj_ja(2,1)) c%adj_ja(:,1) = [ dim, new_size ] c%get_partial_left => get_partial_unpack_indices c%get_partial_right => get_partial_pack_indices if(a%requires_grad) then c%requires_grad = .true. c%is_forward = a%is_forward c%operation = 'unpack_indices' c%left_operand => a c%owns_left_operand = a%is_temporary end if end function unpack_indices_array