torch_tensor_assign Subroutine

public subroutine torch_tensor_assign(output, input)

Overloads assignment operator for tensors.

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(inout) :: output
type(torch_tensor), intent(in) :: input

Source Code

  subroutine torch_tensor_assign(output, input)
    use, intrinsic :: iso_c_binding, only : c_associated
    type(torch_tensor), intent(inout) :: output
    type(torch_tensor), intent(in) :: input

    interface
      subroutine torch_tensor_assign_c(output_c, input_c) bind(c, name = 'torch_tensor_assign')
        use, intrinsic :: iso_c_binding, only : c_ptr
        implicit none
        type(c_ptr), value, intent(in) :: output_c
        type(c_ptr), value, intent(in) :: input_c
      end subroutine torch_tensor_assign_c
    end interface

    if (.not. c_associated(output%p)) then
      call torch_tensor_empty(output, input%get_rank(), input%get_shape(), input%get_dtype(), &
                              input%get_device_type(), device_index=input%get_device_index(), &
                              requires_grad=input%requires_grad())
    else if (input%get_device_type() /= output%get_device_type()) then
      write(*,*) "Error :: cannot assign tensors with different device types"
      stop 1
    end if
    call torch_tensor_assign_c(output%p, input%p)
  end subroutine torch_tensor_assign