Unverified Commit 4b5fa83b authored by Hongzhi (Steve), Chen's avatar Hongzhi (Steve), Chen Committed by GitHub
Browse files

[Sparse] Swap examples of from_coo and spmatrix. (#5228)



* swap-example

* size-shape
Co-authored-by: default avatarSteve <ubuntu@ip-172-31-34-29.ap-northeast-1.compute.internal>
parent 387ae76d
...@@ -484,15 +484,14 @@ def spmatrix( ...@@ -484,15 +484,14 @@ def spmatrix(
Case1: Sparse matrix with row and column indices without values. Case1: Sparse matrix with row and column indices without values.
>>> dst = torch.tensor([1, 1, 2]) >>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]])
>>> src = torch.tensor([2, 4, 3]) >>> A = dglsp.spmatrix(indices)
>>> A = dglsp.from_coo(dst, src)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]), [2, 4, 3]]),
values=tensor([1., 1., 1.]), values=tensor([1., 1., 1.]),
shape=(3, 5), nnz=3) shape=(3, 5), nnz=3)
>>> # Specify shape >>> # Specify shape
>>> A = dglsp.from_coo(dst, src, shape=(5, 5)) >>> A = dglsp.spmatrix(indices, shape=(5, 5))
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]), [2, 4, 3]]),
values=tensor([1., 1., 1.]), values=tensor([1., 1., 1.]),
...@@ -512,10 +511,9 @@ def spmatrix( ...@@ -512,10 +511,9 @@ def spmatrix(
Case3: Sparse matrix with vector values. Case3: Sparse matrix with vector values.
>>> dst = torch.tensor([1, 1, 2]) >>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]])
>>> src = torch.tensor([2, 4, 3])
>>> val = torch.tensor([[1., 1.], [2., 2.], [3., 3.]]) >>> val = torch.tensor([[1., 1.], [2., 2.], [3., 3.]])
>>> A = dglsp.from_coo(dst, src, val) >>> A = dglsp.spmatrix(indices, val)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]), [2, 4, 3]]),
values=tensor([[1., 1.], values=tensor([[1., 1.],
...@@ -562,14 +560,15 @@ def from_coo( ...@@ -562,14 +560,15 @@ def from_coo(
Case1: Sparse matrix with row and column indices without values. Case1: Sparse matrix with row and column indices without values.
>>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]]) >>> dst = torch.tensor([1, 1, 2])
>>> A = dglsp.spmatrix(indices) >>> src = torch.tensor([2, 4, 3])
>>> A = dglsp.from_coo(dst, src)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]), [2, 4, 3]]),
values=tensor([1., 1., 1.]), values=tensor([1., 1., 1.]),
shape=(3, 5), nnz=3) shape=(3, 5), nnz=3)
>>> # Specify shape >>> # Specify shape
>>> A = dglsp.spmatrix(indices, shape=(5, 5)) >>> A = dglsp.from_coo(dst, src, shape=(5, 5))
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]), [2, 4, 3]]),
values=tensor([1., 1., 1.]), values=tensor([1., 1., 1.]),
...@@ -585,13 +584,14 @@ def from_coo( ...@@ -585,13 +584,14 @@ def from_coo(
values=tensor([[1.], values=tensor([[1.],
[2.], [2.],
[3.]]), [3.]]),
size=(3, 5), nnz=3, val_size=(1,)) shape=(3, 5), nnz=3, val_size=(1,))
Case3: Sparse matrix with vector values. Case3: Sparse matrix with vector values.
>>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]]) >>> dst = torch.tensor([1, 1, 2])
>>> src = torch.tensor([2, 4, 3])
>>> val = torch.tensor([[1., 1.], [2., 2.], [3., 3.]]) >>> val = torch.tensor([[1., 1.], [2., 2.], [3., 3.]])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.from_coo(dst, src, val)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]), [2, 4, 3]]),
values=tensor([[1., 1.], values=tensor([[1., 1.],
......
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