Skip to content

Commit 48387ab

Browse files
committed
Add (passing) test_to_dense2 to test to_dense when the tensor has a virtual dimension that uses a physical dimension multiple times.
1 parent 3dffd1e commit 48387ab

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tests/unit/sparse/test_diagonal_sparse_tensor.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pytest import mark
33
from torch.ops import aten # type: ignore
44
from torch.testing import assert_close
5-
from utils.tensors import randn_, zeros_
5+
from utils.tensors import randn_, tensor_, zeros_
66

77
from torchjd.sparse._diagonal_sparse_tensor import (
88
_IN_PLACE_POINTWISE_FUNCTIONS,
@@ -28,6 +28,14 @@ def test_to_dense():
2828
assert c[i, j, j, i] == a[i, j]
2929

3030

31+
def test_to_dense2():
32+
a = tensor_([1.0, 2.0, 3.0])
33+
b = DiagonalSparseTensor(a, [[0, 0]])
34+
c = b.to_dense()
35+
expected = tensor_([1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0])
36+
assert torch.all(torch.eq(c, expected))
37+
38+
3139
@mark.parametrize(
3240
["a_pshape", "a_v_to_ps", "b_pshape", "b_v_to_ps", "a_indices", "b_indices", "output_indices"],
3341
[

0 commit comments

Comments
 (0)