torch_tensor_from_blob Subroutine

public subroutine torch_tensor_from_blob(tensor, data, ndims, tensor_shape, tensor_strides, dtype, device_type, device_index, requires_grad)

Uses

  • proc~~torch_tensor_from_blob~~UsesGraph proc~torch_tensor_from_blob torch_tensor_from_blob iso_c_binding iso_c_binding proc~torch_tensor_from_blob->iso_c_binding

Exposes the given data as a tensor without taking ownership of the original data. This routine will take an array in memory and return a tensor as specified by the shape and stride input arguments.

Note that data needs to be a pointer to a contiguous block of memory! This is not generally not the case when calling c_loc on a Fortran array as array slicing can lead to non-contiguous memory. Please consider asserting that the data is contiguous with the is_contiguous implicit procedure before calling this routine.

Arguments

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

Returned tensor

type(c_ptr), intent(in) :: data

Pointer to data

integer(kind=int32), intent(in) :: ndims

Number of dimensions of the tensor

integer(kind=int64), intent(in) :: tensor_shape(ndims)

Shape of the returned tensor

integer(kind=int64), intent(in) :: tensor_strides(ndims)

Strides for accessing data in the returned tensor. Note that these are integers representing the number of items of type dtype and NOT bytes/memory.

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

Data type of the input data and tensor

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

Device type the tensor will live on (torch_kCPU or a GPU device type)

integer, intent(in), optional :: device_index

Device index for GPU devices

logical, intent(in), optional :: requires_grad

Whether gradients need to be computed for the created tensor


Calls

proc~~torch_tensor_from_blob~~CallsGraph proc~torch_tensor_from_blob torch_tensor_from_blob interface~torch_from_blob_c torch_from_blob_c proc~torch_tensor_from_blob->interface~torch_from_blob_c

Called by

proc~~torch_tensor_from_blob~~CalledByGraph proc~torch_tensor_from_blob torch_tensor_from_blob proc~torch_tensor_from_array_int16_1d torch_tensor_from_array_int16_1d proc~torch_tensor_from_array_int16_1d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_1d_legacy torch_tensor_from_array_int16_1d_legacy proc~torch_tensor_from_array_int16_1d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_2d torch_tensor_from_array_int16_2d proc~torch_tensor_from_array_int16_2d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_2d_legacy torch_tensor_from_array_int16_2d_legacy proc~torch_tensor_from_array_int16_2d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_3d torch_tensor_from_array_int16_3d proc~torch_tensor_from_array_int16_3d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_3d_legacy torch_tensor_from_array_int16_3d_legacy proc~torch_tensor_from_array_int16_3d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_4d torch_tensor_from_array_int16_4d proc~torch_tensor_from_array_int16_4d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_4d_legacy torch_tensor_from_array_int16_4d_legacy proc~torch_tensor_from_array_int16_4d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_5d torch_tensor_from_array_int16_5d proc~torch_tensor_from_array_int16_5d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int16_5d_legacy torch_tensor_from_array_int16_5d_legacy proc~torch_tensor_from_array_int16_5d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_1d torch_tensor_from_array_int32_1d proc~torch_tensor_from_array_int32_1d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_1d_legacy torch_tensor_from_array_int32_1d_legacy proc~torch_tensor_from_array_int32_1d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_2d torch_tensor_from_array_int32_2d proc~torch_tensor_from_array_int32_2d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_2d_legacy torch_tensor_from_array_int32_2d_legacy proc~torch_tensor_from_array_int32_2d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_3d torch_tensor_from_array_int32_3d proc~torch_tensor_from_array_int32_3d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_3d_legacy torch_tensor_from_array_int32_3d_legacy proc~torch_tensor_from_array_int32_3d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_4d torch_tensor_from_array_int32_4d proc~torch_tensor_from_array_int32_4d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_4d_legacy torch_tensor_from_array_int32_4d_legacy proc~torch_tensor_from_array_int32_4d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_5d torch_tensor_from_array_int32_5d proc~torch_tensor_from_array_int32_5d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int32_5d_legacy torch_tensor_from_array_int32_5d_legacy proc~torch_tensor_from_array_int32_5d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_1d torch_tensor_from_array_int64_1d proc~torch_tensor_from_array_int64_1d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_1d_legacy torch_tensor_from_array_int64_1d_legacy proc~torch_tensor_from_array_int64_1d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_2d torch_tensor_from_array_int64_2d proc~torch_tensor_from_array_int64_2d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_2d_legacy torch_tensor_from_array_int64_2d_legacy proc~torch_tensor_from_array_int64_2d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_3d torch_tensor_from_array_int64_3d proc~torch_tensor_from_array_int64_3d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_3d_legacy torch_tensor_from_array_int64_3d_legacy proc~torch_tensor_from_array_int64_3d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_4d torch_tensor_from_array_int64_4d proc~torch_tensor_from_array_int64_4d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_4d_legacy torch_tensor_from_array_int64_4d_legacy proc~torch_tensor_from_array_int64_4d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_5d torch_tensor_from_array_int64_5d proc~torch_tensor_from_array_int64_5d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int64_5d_legacy torch_tensor_from_array_int64_5d_legacy proc~torch_tensor_from_array_int64_5d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_1d torch_tensor_from_array_int8_1d proc~torch_tensor_from_array_int8_1d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_1d_legacy torch_tensor_from_array_int8_1d_legacy proc~torch_tensor_from_array_int8_1d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_2d torch_tensor_from_array_int8_2d proc~torch_tensor_from_array_int8_2d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_2d_legacy torch_tensor_from_array_int8_2d_legacy proc~torch_tensor_from_array_int8_2d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_3d torch_tensor_from_array_int8_3d proc~torch_tensor_from_array_int8_3d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_3d_legacy torch_tensor_from_array_int8_3d_legacy proc~torch_tensor_from_array_int8_3d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_4d torch_tensor_from_array_int8_4d proc~torch_tensor_from_array_int8_4d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_4d_legacy torch_tensor_from_array_int8_4d_legacy proc~torch_tensor_from_array_int8_4d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_5d torch_tensor_from_array_int8_5d proc~torch_tensor_from_array_int8_5d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_int8_5d_legacy torch_tensor_from_array_int8_5d_legacy proc~torch_tensor_from_array_int8_5d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_1d torch_tensor_from_array_real32_1d proc~torch_tensor_from_array_real32_1d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_1d_legacy torch_tensor_from_array_real32_1d_legacy proc~torch_tensor_from_array_real32_1d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_2d torch_tensor_from_array_real32_2d proc~torch_tensor_from_array_real32_2d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_2d_legacy torch_tensor_from_array_real32_2d_legacy proc~torch_tensor_from_array_real32_2d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_3d torch_tensor_from_array_real32_3d proc~torch_tensor_from_array_real32_3d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_3d_legacy torch_tensor_from_array_real32_3d_legacy proc~torch_tensor_from_array_real32_3d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_4d torch_tensor_from_array_real32_4d proc~torch_tensor_from_array_real32_4d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_4d_legacy torch_tensor_from_array_real32_4d_legacy proc~torch_tensor_from_array_real32_4d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_5d torch_tensor_from_array_real32_5d proc~torch_tensor_from_array_real32_5d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real32_5d_legacy torch_tensor_from_array_real32_5d_legacy proc~torch_tensor_from_array_real32_5d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_1d torch_tensor_from_array_real64_1d proc~torch_tensor_from_array_real64_1d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_1d_legacy torch_tensor_from_array_real64_1d_legacy proc~torch_tensor_from_array_real64_1d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_2d torch_tensor_from_array_real64_2d proc~torch_tensor_from_array_real64_2d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_2d_legacy torch_tensor_from_array_real64_2d_legacy proc~torch_tensor_from_array_real64_2d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_3d torch_tensor_from_array_real64_3d proc~torch_tensor_from_array_real64_3d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_3d_legacy torch_tensor_from_array_real64_3d_legacy proc~torch_tensor_from_array_real64_3d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_4d torch_tensor_from_array_real64_4d proc~torch_tensor_from_array_real64_4d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_4d_legacy torch_tensor_from_array_real64_4d_legacy proc~torch_tensor_from_array_real64_4d_legacy->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_5d torch_tensor_from_array_real64_5d proc~torch_tensor_from_array_real64_5d->proc~torch_tensor_from_blob proc~torch_tensor_from_array_real64_5d_legacy torch_tensor_from_array_real64_5d_legacy proc~torch_tensor_from_array_real64_5d_legacy->proc~torch_tensor_from_blob interface~torch_tensor_from_array torch_tensor_from_array interface~torch_tensor_from_array->proc~torch_tensor_from_array_int16_1d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int16_2d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int16_3d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int16_4d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int16_5d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int32_1d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int32_2d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int32_3d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int32_4d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int32_5d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int64_1d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int64_2d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int64_3d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int64_4d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int64_5d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int8_1d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int8_2d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int8_3d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int8_4d interface~torch_tensor_from_array->proc~torch_tensor_from_array_int8_5d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real32_1d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real32_2d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real32_3d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real32_4d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real32_5d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real64_1d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real64_2d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real64_3d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real64_4d interface~torch_tensor_from_array->proc~torch_tensor_from_array_real64_5d interface~torch_tensor_from_array_legacy torch_tensor_from_array_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int16_1d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int16_2d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int16_3d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int16_4d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int16_5d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int32_1d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int32_2d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int32_3d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int32_4d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int32_5d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int64_1d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int64_2d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int64_3d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int64_4d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int64_5d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int8_1d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int8_2d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int8_3d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int8_4d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_int8_5d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real32_1d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real32_2d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real32_3d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real32_4d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real32_5d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real64_1d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real64_2d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real64_3d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real64_4d_legacy interface~torch_tensor_from_array_legacy->proc~torch_tensor_from_array_real64_5d_legacy

Source Code

  subroutine torch_tensor_from_blob(tensor, data, ndims, tensor_shape, tensor_strides, dtype, &
                                    device_type, device_index, &
                                    requires_grad)
    use, intrinsic :: iso_c_binding, only : c_bool, c_int, c_int64_t, c_ptr
    type(torch_tensor), intent(out) :: tensor     !! Returned tensor
    type(c_ptr), intent(in)         :: data       !! Pointer to data
    integer(int32), intent(in)      :: ndims      !! Number of dimensions of the tensor
    integer(int64), intent(in)      :: tensor_shape(ndims)  !! Shape of the returned tensor
    integer(int64), intent(in)      :: tensor_strides(ndims)
        !! Strides for accessing data in the returned tensor. Note that these are integers
        !! representing the number of items of type `dtype` and NOT bytes/memory.
    integer(c_int), intent(in)      :: dtype      !! Data type of the input data and tensor
    integer(c_int), intent(in)      :: device_type
        !! Device type the tensor will live on (`torch_kCPU` or a GPU device type)
    integer, optional, intent(in) :: device_index   !! Device index for GPU devices
    logical, optional, intent(in) :: requires_grad
        !! Whether gradients need to be computed for the created tensor

    ! local data
    integer(c_int)                  :: ndims_c            !! C-type ndims
    integer(c_int64_t)              :: tensor_shape_c(ndims)  !! C-type tensor_shape
    integer(c_int64_t)              :: tensor_strides_c(ndims)  !! C-type strides
    integer(c_int)                  :: device_index_value   !! device index used
    logical(c_bool)                 :: requires_grad_value
        !! Whether gradients need to be computed for the created tensor

    ! Process optional arguments
    if (.not. present(requires_grad)) then
      requires_grad_value = logical(.false., c_bool)
    else
      requires_grad_value = requires_grad
    end if

    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
    end if

    ! Convert public arguments to C-types
    ndims_c = ndims
    tensor_shape_c(:) = tensor_shape(:)
    tensor_strides_c(:) = tensor_strides(:)

    tensor%p = torch_from_blob_c(data, ndims_c, tensor_shape_c, tensor_strides_c, dtype, &
                                 device_type, device_index_value,              &
                                 requires_grad_value)
  end subroutine torch_tensor_from_blob