Return the strides of the tensor
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(torch_tensor), | intent(in) | :: | self |
Tensor to get the strides of |
Array holding the strides of the tensor
function torch_tensor_get_stride(self) result(strides) use, intrinsic :: iso_c_binding, only : c_f_pointer, c_int64_t, c_ptr class(torch_tensor), intent(in) :: self !! Tensor to get the strides of integer(kind=int64), allocatable :: strides(:) !! Array holding the strides of the tensor ! Local data integer(kind=int32) :: ndims(1) integer(kind=c_int64_t), pointer :: strides_c_int64_ptr(:) !! Temporary pointer to Torch-owned memory containing c_int64 type(c_ptr) :: cptr interface function torch_tensor_get_stride_c(tensor_c) result(strides_c) & bind(c, name = "torch_tensor_get_stride") use, intrinsic :: iso_c_binding, only : c_ptr implicit none type(c_ptr), value, intent(in) :: tensor_c type(c_ptr) :: strides_c end function torch_tensor_get_stride_c end interface if (.not. c_associated(self%p)) then write(*,*) "Error :: tensor has not been constructed so its strides are unset" stop 1 end if ndims(1) = self%rank() cptr = torch_tensor_get_stride_c(self%p) call c_f_pointer(cptr, strides_c_int64_ptr, ndims) ! Copy out of the Torch-owned memory so the result remains valid even if ! the tensor is subsequently deleted allocate(strides(ndims(1))) strides(:) = strides_c_int64_ptr(:) end function torch_tensor_get_stride