Right trim an autodiff array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(array_type), | intent(in), | target | :: | a | ||
| integer, | intent(in) | :: | b | |||
| integer, | intent(in), | optional | :: | dim |
module function slice_right_array(a, b, dim) result(c) !! Right trim an autodiff array implicit none class(array_type), intent(in), target :: a integer, intent(in) :: b integer, intent(in), optional :: dim type(array_type), pointer :: c integer :: s integer :: dim_ if(present(dim)) then dim_ = dim else dim_ = 1 end if ! right trim 1D array by using shape to swap dimensions if(dim_.eq.1)then c => a%create_result(array_shape = [b, size(a%val,2)]) do concurrent(s=1:size(a%val,2)) c%val( :, s) = a%val( size(a%val,1)-b+1:size(a%val,1), s) end do else c => a%create_result(array_shape = [size(a%val,1), b]) do concurrent(s=1:size(a%val,1)) c%val( s, : ) = a%val( s, size(a%val,2)-b+1:size(a%val,2)) end do end if c%indices = [ dim_, b ] if(a%requires_grad) then c%requires_grad = .true. c%is_forward = a%is_forward c%operation = 'slice_right' c%left_operand => a c%owns_left_operand = a%is_temporary end if end function slice_right_array