torch_tensor_divide Function

public function torch_tensor_divide(tensor1, tensor2) result(output)

Overloads division operator for two tensors.

Arguments

Type IntentOptional Attributes Name
type(torch_tensor), intent(in) :: tensor1

First tensor for the division

type(torch_tensor), intent(in) :: tensor2

Second tensor for the division

Return Value type(torch_tensor)

Tensor to hold the quotient


Source Code

  function torch_tensor_divide(tensor1, tensor2) result(output)
    use, intrinsic :: iso_c_binding, only : c_associated
    type(torch_tensor), intent(in) :: tensor1  !! First tensor for the division
    type(torch_tensor), intent(in) :: tensor2  !! Second tensor for the division
    type(torch_tensor) :: output               !! Tensor to hold the quotient

    if (tensor1%get_device_type() /= tensor2%get_device_type()) then
      write(*,*) "Error :: cannot divide tensors with different device types"
      stop 1
    end if

    if (.not. c_associated(output%p)) then
      call torch_tensor_empty(output, tensor1%get_rank(), tensor1%get_shape(), &
                              tensor1%get_dtype(), tensor1%get_device_type(), &
                              device_index=tensor1%get_device_index(), &
                              requires_grad=tensor1%requires_grad())
    end if
    call torch_tensor_divide_c(output%p, tensor1%p, tensor2%p)
  end function torch_tensor_divide