Skip to content

Commit

Permalink
Fix issue #637 (crash when using append on an empty tensor) (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelEzquerra authored Mar 21, 2024
1 parent 49bf690 commit 454c8fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/arraymancer/tensor/shapeshifting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ proc append*[T](t: Tensor[T], values: varargs[T]): Tensor[T] {.noinit.} =
$t.rank & " (use `concat` for higher rank tensors)"
let result_size = t.size + values.len
result = newTensorUninit[T](result_size)
result[0 ..< t.size] = t
if t.size > 0:
result[0 ..< t.size] = t
result[t.size ..< result.size] = values

func squeeze*(t: AnyTensor): AnyTensor {.noinit.}=
Expand Down
4 changes: 4 additions & 0 deletions tests/tensor/test_shapeshifting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ proc main() =
check: a.append(b) == expected
check: a.append(b.toTensor()) == expected

# Test fix for issue #637 (https://github.com/mratsim/Arraymancer/issues/637)
let c = newTensor[int](0)
check: c.append(1) == [1].toTensor

test "Squeeze":
block:
let a = toSeq(1..12).toTensor().reshape(3,1,2,1,1,2)
Expand Down

0 comments on commit 454c8fe

Please sign in to comment.