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

Fix issue #637 (crash when using append on an empty tensor) #638

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
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 @@ -43,7 +43,7 @@
let d = a.asContiguous(colMajor, force = true)
# this test needs `toRawSeq` due to the changed layout. `toFlatSeq` provides the
# same as for `c` above!
check: d.toRawSeq == @[7, 8, 2, 4, 1, 0, 3, 6, 4, 1, 2, 3, 8, 6, 2, 6, 6, 0]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-c (version-1-6)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-c (version-1-6)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-c (version-1-6)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-c (version-1-6)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-c (version-2-0)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-c (version-2-0)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-c (version-2-0)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-c (version-2-0)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-c (devel)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]

Check warning on line 46 in tests/tensor/test_shapeshifting.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-c (devel)

This proc cannot be reimplemented in a backward compatible way.; toRawSeq is deprecated [Deprecated]


# # Now test with a non contiguous tensor
Expand Down Expand Up @@ -113,6 +113,10 @@
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
Loading