torch_tensor_negative Function

public function torch_tensor_negative(tensor) result(output)

Overloads negative operator for a single tensor.

Arguments

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

Return Value type(torch_tensor)


Source Code

  function torch_tensor_negative(tensor) result(output)
    use, intrinsic :: iso_c_binding, only : c_associated
    type(torch_tensor), intent(in) :: tensor
    type(torch_tensor) :: output

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

    if (.not. c_associated(output%p)) then
      call torch_tensor_empty(output, tensor%get_rank(), tensor%get_shape(), tensor%get_dtype(), &
                              tensor%get_device_type(), device_index=tensor%get_device_index(), &
                              requires_grad=tensor%requires_grad())
    end if
    call torch_tensor_negative_c(output%p, tensor%p)
  end function torch_tensor_negative