"git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "53895b958a1c2d590033d2f71ddf2e08f8e82201"
Unverified Commit 7cc59bba authored by yxy235's avatar yxy235 Committed by GitHub
Browse files

[Sparse] Modify the test of sparse_matrix_str (#6364)


Co-authored-by: default avatarUbuntu <ubuntu@ip-172-31-0-133.us-west-2.compute.internal>
parent 25209120
...@@ -596,14 +596,50 @@ def test_print(): ...@@ -596,14 +596,50 @@ def test_print():
col = torch.tensor([2, 1, 3]).to(ctx) col = torch.tensor([2, 1, 3]).to(ctx)
val = torch.tensor([1.0, 1.0, 2.0]).to(ctx) val = torch.tensor([1.0, 1.0, 2.0]).to(ctx)
A = from_coo(row, col, val) A = from_coo(row, col, val)
print(A) expected = (
str(
"""SparseMatrix(indices=tensor([[1, 1, 3],
[2, 1, 3]]),
values=tensor([1., 1., 2.]),
shape=(4, 4), nnz=3)"""
)
if str(ctx) == "cpu"
else str(
"""SparseMatrix(indices=tensor([[1, 1, 3],
[2, 1, 3]], device='cuda:0'),
values=tensor([1., 1., 2.], device='cuda:0'),
shape=(4, 4), nnz=3)"""
)
)
assert str(A) == expected, print(A, expected)
# vector-shape non zero # vector-shape non zero
row = torch.tensor([1, 1, 3]).to(ctx) row = torch.tensor([1, 1, 3]).to(ctx)
col = torch.tensor([2, 1, 3]).to(ctx) col = torch.tensor([2, 1, 3]).to(ctx)
val = torch.randn(3, 2).to(ctx) val = torch.tensor(
[[1.3080, 1.5984], [-0.4126, 0.7250], [-0.5416, -0.7022]]
).to(ctx)
A = from_coo(row, col, val) A = from_coo(row, col, val)
print(A) expected = (
str(
"""SparseMatrix(indices=tensor([[1, 1, 3],
[2, 1, 3]]),
values=tensor([[ 1.3080, 1.5984],
[-0.4126, 0.7250],
[-0.5416, -0.7022]]),
shape=(4, 4), nnz=3, val_size=(2,))"""
)
if str(ctx) == "cpu"
else str(
"""SparseMatrix(indices=tensor([[1, 1, 3],
[2, 1, 3]], device='cuda:0'),
values=tensor([[ 1.3080, 1.5984],
[-0.4126, 0.7250],
[-0.5416, -0.7022]], device='cuda:0'),
shape=(4, 4), nnz=3, val_size=(2,))"""
)
)
assert str(A) == expected, print(A, expected)
@unittest.skipIf( @unittest.skipIf(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment