torch_tensor_zero Subroutine

public subroutine torch_tensor_zero(tensor)

Fills a tensor with the scalar value 0.

Type Bound

torch_tensor

Arguments

Type IntentOptional Attributes Name
class(torch_tensor), intent(inout) :: tensor

Tensor whose values are to be zeroed


Source Code

  subroutine torch_tensor_zero(tensor)
    use, intrinsic :: iso_c_binding, only : c_associated
    class(torch_tensor), intent(inout) :: tensor !! Tensor whose values are to be zeroed

    interface
      subroutine torch_tensor_zero_c(tensor) bind(c, name = 'torch_tensor_zero')
        use, intrinsic :: iso_c_binding, only : c_ptr
        implicit none
        type(c_ptr), value, intent(in) :: tensor
      end subroutine torch_tensor_zero_c
    end interface

    if (.not. c_associated(tensor%p)) then
      write(*,*) "Error :: tensor must be constructed before zeroing values"
      stop 1
    end if
    call torch_tensor_zero_c(tensor%p)
  end subroutine torch_tensor_zero