Return a Torch tensor pointing to data_in array of rank 4 containing data of type real32
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(torch_tensor), | intent(out) | :: | tensor |
Returned tensor |
||
real(kind=real32), | intent(in), | target | :: | data_in(:,:,:,:) |
Input data that tensor will point at |
|
integer(kind=ftorch_int), | intent(in) | :: | layout(4) |
Control order of indices |
||
integer(kind=c_int), | intent(in) | :: | device_type |
Device type the tensor will live on ( |
||
integer(kind=c_int), | intent(in), | optional | :: | device_index |
device index to use for |
|
logical, | intent(in), | optional | :: | requires_grad |
Whether gradients need to be computed for the created tensor |
subroutine torch_tensor_from_array_real32_4d(tensor, data_in, layout, & device_type, device_index, requires_grad) use, intrinsic :: iso_c_binding, only : c_bool, c_float, c_int, c_int64_t, c_loc use, intrinsic :: iso_fortran_env, only : real32 ! output tensor type(torch_tensor), intent(out) :: tensor !! Returned tensor ! inputs real(kind=real32), intent(in), target :: data_in(:,:,:,:) !! Input data that tensor will point at integer(ftorch_int), intent(in) :: layout(4) !! Control order of indices integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`) integer(c_int), optional, intent(in) :: device_index !! device index to use for `torch_kCUDA` case logical, optional, intent(in) :: requires_grad !! Whether gradients need to be computed for the created tensor ! local data integer(c_int64_t) :: tensor_shape(4) !! Shape of the tensor integer(c_int), parameter :: dtype = torch_kFloat32 !! Data type integer(c_int64_t) :: strides(4) !! Strides for accessing data integer(c_int), parameter :: ndims = 4 !! Number of dimension of input data integer(ftorch_int) :: i integer(c_int) :: device_index_value logical :: requires_grad_value !! Whether gradients need to be computed for the created tensor ! Process optional arguments if (present(device_index)) then device_index_value = device_index else if (device_type == torch_kCPU) then device_index_value = -1 else device_index_value = 0 endif if (.not. present(requires_grad)) then requires_grad_value = .false. else requires_grad_value = requires_grad end if tensor_shape = shape(data_in) strides(layout(1)) = 1 do i = 2, ndims strides(layout(i)) = strides(layout(i - 1)) * tensor_shape(layout(i - 1)) end do tensor%p = torch_from_blob_c(c_loc(data_in), ndims, tensor_shape, & strides, dtype, device_type, & device_index_value, & logical(requires_grad_value, c_bool)) end subroutine torch_tensor_from_array_real32_4d