torch_tensor_from_array_int64_5d Subroutine

public subroutine torch_tensor_from_array_int64_5d(tensor, data_in, layout, device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 5 containing data of type int64

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(out) :: tensor

Returned tensor

integer(kind=int64), intent(in), target :: data_in(:,:,:,:,:)

Input data that tensor will point at

integer(kind=ftorch_int), intent(in) :: layout(5)

Control order of indices

integer(kind=c_int), intent(in) :: device_type

Device type the tensor will live on (torch_kCPU or torch_kCUDA)

integer, intent(in), optional :: device_index

Device index to use for torch_kCUDA case

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor


Source Code

  subroutine torch_tensor_from_array_int64_5d(tensor, data_in, layout, &
                                                        device_type, device_index, requires_grad)
    use, intrinsic :: iso_c_binding, only : c_bool, c_int, c_int64_t, c_loc
    use, intrinsic :: iso_fortran_env, only : int64

    ! output tensor
    type(torch_tensor), intent(out) :: tensor  !! Returned tensor

    ! inputs
    integer(kind=int64), intent(in), target :: data_in(:,:,:,:,:)  !! Input data that tensor will point at
    integer(ftorch_int), intent(in) :: layout(5)  !! Control order of indices
    integer(c_int), intent(in)    :: device_type    !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
    integer, 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(5)            !! Shape of the tensor
    integer(c_int), parameter :: dtype = torch_kInt64  !! Data type
    integer(c_int64_t)        :: strides(5)                 !! Strides for accessing data
    integer(c_int), parameter :: ndims = 5                  !! Number of dimension of input data

    tensor_shape = shape(data_in)

    call torch_tensor_from_blob(tensor, c_loc(data_in), ndims, tensor_shape, &
                                layout, dtype, device_type, device_index, &
                                requires_grad)

  end subroutine torch_tensor_from_array_int64_5d