torch_tensor_from_array_int16_3d_default_layout Subroutine

public subroutine torch_tensor_from_array_int16_3d_default_layout(tensor, data_in, device_type, device_index, requires_grad)

Return a Torch tensor pointing to data_in array of rank 3 containing data of type int16 with default layout [1, 2, ..., n].

Arguments

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

Returned tensor

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

Input data that tensor will point at

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_int16_3d_default_layout(tensor, data_in, &
                                                                       device_type, device_index, &
                                                                       requires_grad)
    use, intrinsic :: iso_c_binding, only : c_int
    use, intrinsic :: iso_fortran_env, only : int16

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

    ! inputs
    integer(kind=int16), intent(in), target :: data_in(:,:,:)  !! Input data that tensor will point at
    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(ftorch_int)       :: layout(3)  !! Order of indices
    integer(c_int), parameter :: ndims = 3  !! Number of dimension of input data
    integer :: i

    ! Set the default tensor layout
    do i = 1, ndims
      layout(i) = i
    end do

    call torch_tensor_from_array(tensor, data_in, layout, device_type, device_index, requires_grad)

  end subroutine torch_tensor_from_array_int16_3d_default_layout