Index an autodiff array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(array_type), | intent(in), | target | :: | a | ||
| integer, | intent(in), | dimension(:) | :: | indices |
module function index_array(a, indices) result(c) !! Index an autodiff array implicit none class(array_type), intent(in), target :: a integer, dimension(:), intent(in) :: indices type(array_type), pointer :: c integer :: i, s allocate(c) call c%allocate(array_shape=[size(a%val,1), size(indices)]) do concurrent(s=1:size(indices), i=1:size(a%val,1)) c%val(i, s) = a%val(i, indices(s)) end do c%indices = indices c%get_partial_left => get_partial_index if(a%requires_grad) then c%requires_grad = .true. c%is_forward = a%is_forward c%operation = 'index' c%left_operand => a c%owns_left_operand = a%is_temporary end if end function index_array