Return the array data associated with a Torch tensor of rank 5 and data type real32
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(torch_tensor), | intent(in) | :: | tensor |
Returned tensor |
||
real(kind=real32), | intent(out), | pointer | :: | data_out(:,:,:,:,:) |
Pointer to tensor data |
|
integer, | intent(in), | optional | :: | sizes(5) |
Number of entries for each rank |
subroutine torch_tensor_to_array_real32_5d(tensor, data_out, sizes) use, intrinsic :: iso_c_binding, only : c_int, c_int64_t, c_loc use, intrinsic :: iso_fortran_env, only : real32, int64 type(torch_tensor), intent(in) :: tensor !! Returned tensor real(kind=real32), pointer, intent(out) :: data_out(:,:,:,:,:) !! Pointer to tensor data integer, optional, intent(in) :: sizes(5) !! Number of entries for each rank integer(kind=int64), allocatable :: my_shape(:) !! Number of entries for each rank ! Local data integer(c_int), parameter :: dtype = torch_kFloat32 !! 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, 5(I0, " "), A)') 'sizes :: [ ', sizes(:), ']' write(*,'(A, 5(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, dtype) call c_f_pointer(cptr, data_out, my_shape) end subroutine torch_tensor_to_array_real32_5d