Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure strides array initialised to zero #237

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/ftorch.F90
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ subroutine torch_tensor_empty(tensor, ndims, tensor_shape, dtype, &
use, intrinsic :: iso_c_binding, only : c_bool, c_int, c_int64_t
type(torch_tensor), intent(out) :: tensor !! Returned tensor
integer(c_int), intent(in) :: ndims !! Number of dimensions of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(*) !! Shape of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(:) !! Shape of the tensor
integer(c_int), intent(in) :: dtype !! Data type of the tensor
integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
integer, optional, intent(in) :: device_index !! Device index to use for `torch_kCUDA` case
Expand Down Expand Up @@ -304,7 +304,7 @@ subroutine torch_tensor_zeros(tensor, ndims, tensor_shape, dtype, &
use, intrinsic :: iso_c_binding, only : c_bool, c_int, c_int64_t
type(torch_tensor), intent(out) :: tensor !! Returned tensor
integer(c_int), intent(in) :: ndims !! Number of dimensions of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(*) !! Shape of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(:) !! Shape of the tensor
integer(c_int), intent(in) :: dtype !! Data type of the tensor
integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
integer, optional, intent(in) :: device_index !! Device index to use for `torch_kCUDA` case
Expand Down Expand Up @@ -355,7 +355,7 @@ subroutine torch_tensor_ones(tensor, ndims, tensor_shape, dtype, &
use, intrinsic :: iso_c_binding, only : c_bool, c_int, c_int64_t
type(torch_tensor), intent(out) :: tensor !! Returned tensor
integer(c_int), intent(in) :: ndims !! Number of dimensions of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(*) !! Shape of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(:) !! Shape of the tensor
integer(c_int), intent(in) :: dtype !! Data type of the tensor
integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
integer, optional, intent(in) :: device_index !! Device index to use for `torch_kCUDA` case
Expand Down Expand Up @@ -409,8 +409,8 @@ subroutine torch_tensor_from_blob(tensor, data, ndims, tensor_shape, layout, dty
type(torch_tensor), intent(out) :: tensor !! Returned tensor
type(c_ptr), intent(in) :: data !! Pointer to data
integer(c_int), intent(in) :: ndims !! Number of dimensions of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(*) !! Shape of the tensor
integer(c_int), intent(in) :: layout(*) !! Layout for strides for accessing data
integer(c_int64_t), intent(in) :: tensor_shape(:) !! Shape of the tensor
integer(c_int), intent(in) :: layout(:) !! Layout for strides for accessing data
integer(c_int), intent(in) :: dtype !! Data type of the tensor
integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
integer, optional, intent(in) :: device_index !! Device index to use for `torch_kCUDA` case
Expand All @@ -427,6 +427,7 @@ subroutine torch_tensor_from_blob(tensor, data, ndims, tensor_shape, layout, dty
requires_grad_value = requires_grad
end if

strides(:) = 0
do i = 1, ndims
if (i == 1) then
strides(layout(i)) = 1
Expand Down
11 changes: 6 additions & 5 deletions src/ftorch.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ contains
use, intrinsic :: iso_c_binding, only : c_bool, c_int, c_int64_t
type(torch_tensor), intent(out) :: tensor !! Returned tensor
integer(c_int), intent(in) :: ndims !! Number of dimensions of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(*) !! Shape of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(:) !! Shape of the tensor
integer(c_int), intent(in) :: dtype !! Data type of the tensor
integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
integer, optional, intent(in) :: device_index !! Device index to use for `torch_kCUDA` case
Expand Down Expand Up @@ -259,7 +259,7 @@ contains
use, intrinsic :: iso_c_binding, only : c_bool, c_int, c_int64_t
type(torch_tensor), intent(out) :: tensor !! Returned tensor
integer(c_int), intent(in) :: ndims !! Number of dimensions of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(*) !! Shape of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(:) !! Shape of the tensor
integer(c_int), intent(in) :: dtype !! Data type of the tensor
integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
integer, optional, intent(in) :: device_index !! Device index to use for `torch_kCUDA` case
Expand Down Expand Up @@ -310,7 +310,7 @@ contains
use, intrinsic :: iso_c_binding, only : c_bool, c_int, c_int64_t
type(torch_tensor), intent(out) :: tensor !! Returned tensor
integer(c_int), intent(in) :: ndims !! Number of dimensions of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(*) !! Shape of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(:) !! Shape of the tensor
integer(c_int), intent(in) :: dtype !! Data type of the tensor
integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
integer, optional, intent(in) :: device_index !! Device index to use for `torch_kCUDA` case
Expand Down Expand Up @@ -364,8 +364,8 @@ contains
type(torch_tensor), intent(out) :: tensor !! Returned tensor
type(c_ptr), intent(in) :: data !! Pointer to data
integer(c_int), intent(in) :: ndims !! Number of dimensions of the tensor
integer(c_int64_t), intent(in) :: tensor_shape(*) !! Shape of the tensor
integer(c_int), intent(in) :: layout(*) !! Layout for strides for accessing data
integer(c_int64_t), intent(in) :: tensor_shape(:) !! Shape of the tensor
integer(c_int), intent(in) :: layout(:) !! Layout for strides for accessing data
integer(c_int), intent(in) :: dtype !! Data type of the tensor
integer(c_int), intent(in) :: device_type !! Device type the tensor will live on (`torch_kCPU` or `torch_kCUDA`)
integer, optional, intent(in) :: device_index !! Device index to use for `torch_kCUDA` case
Expand All @@ -382,6 +382,7 @@ contains
requires_grad_value = requires_grad
end if

strides(:) = 0
do i = 1, ndims
if (i == 1) then
strides(layout(i)) = 1
Expand Down
Loading