Return the array data associated with a Torch tensor of rank 4 and data type real64
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(torch_tensor), | intent(in) | :: | tensor |
Returned tensor |
||
real(kind=real64), | intent(out), | pointer | :: | data_out(:,:,:,:) |
Pointer to tensor data |
|
integer, | intent(in), | optional | :: | sizes(4) |
Number of entries for each rank |
subroutine torch_tensor_to_array_real64_4d(tensor, data_out, sizes) use, intrinsic :: iso_c_binding, only : c_int, c_int64_t, c_loc use, intrinsic :: iso_fortran_env, only : real64, int64 type(torch_tensor), intent(in) :: tensor !! Returned tensor real(kind=real64), pointer, intent(out) :: data_out(:,:,:,:) !! Pointer to tensor data integer, optional, intent(in) :: sizes(4) !! Number of entries for each rank integer(kind=int64), allocatable :: my_shape(:) !! Number of entries for each rank ! Local data integer(c_int), parameter :: c_dtype = torch_kFloat64 !! Data type type(c_ptr) :: cptr my_shape = tensor%get_shape() if (present(sizes)) then if (.not. all(my_shape == sizes)) then write(*,*) 'Error :: sizes argument does not match shape of tensor' write(*,'(A, 4(I0, " "), A)') 'sizes :: [ ', sizes(:), ']' write(*,'(A, 4(I0, " "), A)') 'tensor shape :: [ ', my_shape(:), ']' stop 1 end if end if ! Have the data_out array point to the Tensor data cptr = torch_to_blob_c(tensor%p, c_dtype) call c_f_pointer(cptr, data_out, my_shape) end subroutine torch_tensor_to_array_real64_4d