Skip to content

Commit

Permalink
fix regression caused by PR #659
Browse files Browse the repository at this point in the history
By not resetting the offset here, operating on a Tensor view without
cloning could cause undefined behavior, because we would be accessing
elements outside the tensor buffer.
  • Loading branch information
Vindaar committed Sep 20, 2024
1 parent 5a28ccf commit 93a6506
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/arraymancer/tensor/private/p_shapeshifting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ proc reshape_no_copy*(t: AnyTensor, new_shape: varargs[int]|Metadata|seq[int], r
proc reshape_with_copy*[T](t: Tensor[T], new_shape: varargs[int]|Metadata|seq[int], result: var Tensor[T]) =
contiguousImpl(t, rowMajor, result)
reshape_no_copy(t, new_shape, result, rowMajor)
result.offset = 0 # Offset needs to be reset! Copy is a new tensor of `new_shape`

proc infer_shape*(t: Tensor, new_shape: varargs[int]): seq[int] {.noinit.} =
## Replace the single -1 value on `new_shape` with the value that
Expand Down

0 comments on commit 93a6506

Please sign in to comment.