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

Change example code for indices creation from two line to one line to avoid test break. (#5222)



* add_backslash

* fix

* more

* blabla
Co-authored-by: default avatarSteve <ubuntu@ip-172-31-34-29.ap-northeast-1.compute.internal>
parent 0bdc437b
...@@ -42,8 +42,7 @@ def add( ...@@ -42,8 +42,7 @@ def add(
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 1, 2]])
>>> [0, 1, 2]])
>>> val = torch.tensor([10, 20, 30]) >>> val = torch.tensor([10, 20, 30])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> B = dglsp.diag(torch.arange(1, 4)) >>> B = dglsp.diag(torch.arange(1, 4))
...@@ -89,8 +88,7 @@ def sub( ...@@ -89,8 +88,7 @@ def sub(
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 1, 2]])
>>> [0, 1, 2]])
>>> val = torch.tensor([10, 20, 30]) >>> val = torch.tensor([10, 20, 30])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> B = dglsp.diag(torch.arange(1, 4)) >>> B = dglsp.diag(torch.arange(1, 4))
...@@ -136,8 +134,7 @@ def mul( ...@@ -136,8 +134,7 @@ def mul(
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> [0, 3, 2]])
>>> val = torch.tensor([10, 20, 30]) >>> val = torch.tensor([10, 20, 30])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> dglsp.mul(A, 2) >>> dglsp.mul(A, 2)
...@@ -202,8 +199,7 @@ def div( ...@@ -202,8 +199,7 @@ def div(
DiagMatrix(val=tensor([0.5000, 1.0000, 1.5000]), DiagMatrix(val=tensor([0.5000, 1.0000, 1.5000]),
shape=(3, 3)) shape=(3, 3))
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> [0, 3, 2]])
>>> val = torch.tensor([1, 2, 3]) >>> val = torch.tensor([1, 2, 3])
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
>>> dglsp.div(A, 2) >>> dglsp.div(A, 2)
...@@ -247,8 +243,7 @@ def power( ...@@ -247,8 +243,7 @@ def power(
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> [0, 3, 2]])
>>> val = torch.tensor([10, 20, 30]) >>> val = torch.tensor([10, 20, 30])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> dglsp.power(A, 2) >>> dglsp.power(A, 2)
......
...@@ -30,8 +30,7 @@ def sp_add(A: SparseMatrix, B: SparseMatrix) -> SparseMatrix: ...@@ -30,8 +30,7 @@ def sp_add(A: SparseMatrix, B: SparseMatrix) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> [0, 3, 2]])
>>> val = torch.tensor([10, 20, 30]) >>> val = torch.tensor([10, 20, 30])
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
>>> A + A >>> A + A
...@@ -63,8 +62,7 @@ def sp_sub(A: SparseMatrix, B: SparseMatrix) -> SparseMatrix: ...@@ -63,8 +62,7 @@ def sp_sub(A: SparseMatrix, B: SparseMatrix) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> [0, 3, 2]])
>>> val = torch.tensor([10, 20, 30]) >>> val = torch.tensor([10, 20, 30])
>>> val2 = torch.tensor([5, 10, 15]) >>> val2 = torch.tensor([5, 10, 15])
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
...@@ -99,8 +97,7 @@ def sp_mul(A: SparseMatrix, B: Scalar) -> SparseMatrix: ...@@ -99,8 +97,7 @@ def sp_mul(A: SparseMatrix, B: Scalar) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> [0, 3, 2]])
>>> val = torch.tensor([1, 2, 3]) >>> val = torch.tensor([1, 2, 3])
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
...@@ -142,8 +139,7 @@ def sp_div(A: SparseMatrix, B: Scalar) -> SparseMatrix: ...@@ -142,8 +139,7 @@ def sp_div(A: SparseMatrix, B: Scalar) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> [0, 3, 2]])
>>> val = torch.tensor([1, 2, 3]) >>> val = torch.tensor([1, 2, 3])
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
>>> A / 2 >>> A / 2
...@@ -177,8 +173,7 @@ def sp_power(A: SparseMatrix, scalar: Scalar) -> SparseMatrix: ...@@ -177,8 +173,7 @@ def sp_power(A: SparseMatrix, scalar: Scalar) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 2], >>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> [0, 3, 2]])
>>> val = torch.tensor([10, 20, 30]) >>> val = torch.tensor([10, 20, 30])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> A ** 2 >>> A ** 2
......
...@@ -29,8 +29,7 @@ def spmm(A: Union[SparseMatrix, DiagMatrix], X: torch.Tensor) -> torch.Tensor: ...@@ -29,8 +29,7 @@ def spmm(A: Union[SparseMatrix, DiagMatrix], X: torch.Tensor) -> torch.Tensor:
Examples Examples
-------- --------
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [1, 0, 1]])
>>> [1, 0, 1]])
>>> val = torch.randn(len(row)) >>> val = torch.randn(len(row))
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> X = torch.randn(2, 3) >>> X = torch.randn(2, 3)
...@@ -72,8 +71,7 @@ def bspmm(A: Union[SparseMatrix, DiagMatrix], X: torch.Tensor) -> torch.Tensor: ...@@ -72,8 +71,7 @@ def bspmm(A: Union[SparseMatrix, DiagMatrix], X: torch.Tensor) -> torch.Tensor:
Examples Examples
-------- --------
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [1, 0, 2]])
>>> [1, 0, 2]])
>>> val = torch.randn(len(row), 2) >>> val = torch.randn(len(row), 2)
>>> A = dglsp.spmatrix(indices, val, shape=(3, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(3, 3))
>>> X = torch.randn(3, 3, 2) >>> X = torch.randn(3, 3, 2)
...@@ -197,12 +195,10 @@ def spspmm( ...@@ -197,12 +195,10 @@ def spspmm(
Examples Examples
-------- --------
>>> indices1 = torch.tensor([[0, 1, 1], >>> indices1 = torch.tensor([[0, 1, 1], [1, 0, 1]])
>>> [1, 0, 1]])
>>> val1 = torch.ones(len(row1)) >>> val1 = torch.ones(len(row1))
>>> A = dglsp.spmatrix(indices1, val1) >>> A = dglsp.spmatrix(indices1, val1)
>>> indices2 = torch.tensor([[0, 1, 1], >>> indices2 = torch.tensor([[0, 1, 1], [0, 2, 1]])
>>> [0, 2, 1]])
>>> val2 = torch.ones(len(row2)) >>> val2 = torch.ones(len(row2))
>>> B = dglsp.spmatrix(indices2, val2) >>> B = dglsp.spmatrix(indices2, val2)
>>> dglsp.spspmm(A, B) >>> dglsp.spspmm(A, B)
...@@ -293,8 +289,7 @@ def matmul( ...@@ -293,8 +289,7 @@ def matmul(
Multiplies a sparse matrix with a dense matrix. Multiplies a sparse matrix with a dense matrix.
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [1, 0, 1]])
>>> [1, 0, 1]])
>>> val = torch.randn(len(row)) >>> val = torch.randn(len(row))
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> X = torch.randn(2, 3) >>> X = torch.randn(2, 3)
...@@ -306,12 +301,10 @@ def matmul( ...@@ -306,12 +301,10 @@ def matmul(
Multiplies a sparse matrix with a sparse matrix. Multiplies a sparse matrix with a sparse matrix.
>>> indices1 = torch.tensor([[0, 1, 1], >>> indices1 = torch.tensor([[0, 1, 1], [1, 0, 1]])
>>> [1, 0, 1]])
>>> val1 = torch.ones(len(row1)) >>> val1 = torch.ones(len(row1))
>>> A = dglsp.spmatrix(indices1, val1) >>> A = dglsp.spmatrix(indices1, val1)
>>> indices2 = torch.tensor([[0, 1, 1], >>> indices2 = torch.tensor([[0, 1, 1], [0, 2, 1]])
>>> [0, 2, 1]])
>>> val2 = torch.ones(len(row2)) >>> val2 = torch.ones(len(row2))
>>> B = dglsp.spmatrix(indices2, val2) >>> B = dglsp.spmatrix(indices2, val2)
>>> result = dglsp.matmul(A, B) >>> result = dglsp.matmul(A, B)
......
...@@ -44,8 +44,7 @@ def reduce(input: SparseMatrix, dim: Optional[int] = None, rtype: str = "sum"): ...@@ -44,8 +44,7 @@ def reduce(input: SparseMatrix, dim: Optional[int] = None, rtype: str = "sum"):
Case1: scalar-valued sparse matrix Case1: scalar-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([1, 1, 2]) >>> val = torch.tensor([1, 1, 2])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.reduce(A, rtype='sum') >>> dglsp.reduce(A, rtype='sum')
...@@ -61,8 +60,7 @@ def reduce(input: SparseMatrix, dim: Optional[int] = None, rtype: str = "sum"): ...@@ -61,8 +60,7 @@ def reduce(input: SparseMatrix, dim: Optional[int] = None, rtype: str = "sum"):
Case2: vector-valued sparse matrix Case2: vector-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([[1., 2.], [2., 1.], [2., 2.]]) >>> val = torch.tensor([[1., 2.], [2., 1.], [2., 2.]])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.reduce(A, rtype='sum') >>> dglsp.reduce(A, rtype='sum')
...@@ -113,8 +111,7 @@ def sum(input: SparseMatrix, dim: Optional[int] = None): ...@@ -113,8 +111,7 @@ def sum(input: SparseMatrix, dim: Optional[int] = None):
Case1: scalar-valued sparse matrix Case1: scalar-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([1, 1, 2]) >>> val = torch.tensor([1, 1, 2])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.sum(A) >>> dglsp.sum(A)
...@@ -126,8 +123,7 @@ def sum(input: SparseMatrix, dim: Optional[int] = None): ...@@ -126,8 +123,7 @@ def sum(input: SparseMatrix, dim: Optional[int] = None):
Case2: vector-valued sparse matrix Case2: vector-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([[1, 2], [2, 1], [2, 2]]) >>> val = torch.tensor([[1, 2], [2, 1], [2, 2]])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.sum(A) >>> dglsp.sum(A)
...@@ -172,8 +168,7 @@ def smax(input: SparseMatrix, dim: Optional[int] = None): ...@@ -172,8 +168,7 @@ def smax(input: SparseMatrix, dim: Optional[int] = None):
Case1: scalar-valued sparse matrix Case1: scalar-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([1, 1, 2]) >>> val = torch.tensor([1, 1, 2])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.smax(A) >>> dglsp.smax(A)
...@@ -185,8 +180,7 @@ def smax(input: SparseMatrix, dim: Optional[int] = None): ...@@ -185,8 +180,7 @@ def smax(input: SparseMatrix, dim: Optional[int] = None):
Case2: vector-valued sparse matrix Case2: vector-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([[1, 2], [2, 1], [2, 2]]) >>> val = torch.tensor([[1, 2], [2, 1], [2, 2]])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.smax(A) >>> dglsp.smax(A)
...@@ -232,8 +226,7 @@ def smin(input: SparseMatrix, dim: Optional[int] = None): ...@@ -232,8 +226,7 @@ def smin(input: SparseMatrix, dim: Optional[int] = None):
Case1: scalar-valued sparse matrix Case1: scalar-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([1, 1, 2]) >>> val = torch.tensor([1, 1, 2])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.smin(A) >>> dglsp.smin(A)
...@@ -245,8 +238,7 @@ def smin(input: SparseMatrix, dim: Optional[int] = None): ...@@ -245,8 +238,7 @@ def smin(input: SparseMatrix, dim: Optional[int] = None):
Case2: vector-valued sparse matrix Case2: vector-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([[1, 2], [2, 1], [2, 2]]) >>> val = torch.tensor([[1, 2], [2, 1], [2, 2]])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.smin(A) >>> dglsp.smin(A)
...@@ -296,8 +288,7 @@ def smean(input: SparseMatrix, dim: Optional[int] = None): ...@@ -296,8 +288,7 @@ def smean(input: SparseMatrix, dim: Optional[int] = None):
Case1: scalar-valued sparse matrix Case1: scalar-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([1., 1., 2.]) >>> val = torch.tensor([1., 1., 2.])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.smean(A) >>> dglsp.smean(A)
...@@ -309,8 +300,7 @@ def smean(input: SparseMatrix, dim: Optional[int] = None): ...@@ -309,8 +300,7 @@ def smean(input: SparseMatrix, dim: Optional[int] = None):
Case2: vector-valued sparse matrix Case2: vector-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([[1., 2.], [2., 1.], [2., 2.]]) >>> val = torch.tensor([[1., 2.], [2., 1.], [2., 2.]])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.smean(A) >>> dglsp.smean(A)
...@@ -360,8 +350,7 @@ def sprod(input: SparseMatrix, dim: Optional[int] = None): ...@@ -360,8 +350,7 @@ def sprod(input: SparseMatrix, dim: Optional[int] = None):
Case1: scalar-valued sparse matrix Case1: scalar-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([1, 1, 2]) >>> val = torch.tensor([1, 1, 2])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.sprod(A) >>> dglsp.sprod(A)
...@@ -373,8 +362,7 @@ def sprod(input: SparseMatrix, dim: Optional[int] = None): ...@@ -373,8 +362,7 @@ def sprod(input: SparseMatrix, dim: Optional[int] = None):
Case2: vector-valued sparse matrix Case2: vector-valued sparse matrix
>>> indices = torch.tensor([[0, 1, 1], >>> indices = torch.tensor([[0, 1, 1], [0, 0, 2]])
>>> [0, 0, 2]])
>>> val = torch.tensor([[1, 2], [2, 1], [2, 2]]) >>> val = torch.tensor([[1, 2], [2, 1], [2, 2]])
>>> A = dglsp.spmatrix(indices, val, shape=(4, 3)) >>> A = dglsp.spmatrix(indices, val, shape=(4, 3))
>>> dglsp.sprod(A) >>> dglsp.sprod(A)
......
...@@ -39,8 +39,7 @@ def sddmm(A: SparseMatrix, X1: torch.Tensor, X2: torch.Tensor) -> SparseMatrix: ...@@ -39,8 +39,7 @@ def sddmm(A: SparseMatrix, X1: torch.Tensor, X2: torch.Tensor) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [2, 3, 3]])
>>> [2, 3, 3]])
>>> val = torch.arange(1, 4).float() >>> val = torch.arange(1, 4).float()
>>> A = dglsp.spmatrix(indices, val, (3, 4)) >>> A = dglsp.spmatrix(indices, val, (3, 4))
>>> X1 = torch.randn(3, 5) >>> X1 = torch.randn(3, 5)
...@@ -89,8 +88,7 @@ def bsddmm(A: SparseMatrix, X1: torch.Tensor, X2: torch.Tensor) -> SparseMatrix: ...@@ -89,8 +88,7 @@ def bsddmm(A: SparseMatrix, X1: torch.Tensor, X2: torch.Tensor) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [2, 3, 3]])
>>> [2, 3, 3]])
>>> val = torch.arange(1, 4).float() >>> val = torch.arange(1, 4).float()
>>> A = dglsp.spmatrix(indices, val, (3, 4)) >>> A = dglsp.spmatrix(indices, val, (3, 4))
>>> X1 = torch.arange(0, 3 * 5 * 2).view(3, 5, 2).float() >>> X1 = torch.arange(0, 3 * 5 * 2).view(3, 5, 2).float()
......
...@@ -34,8 +34,7 @@ def softmax(input: SparseMatrix) -> SparseMatrix: ...@@ -34,8 +34,7 @@ def softmax(input: SparseMatrix) -> SparseMatrix:
Case1: matrix with values of shape (nnz) Case1: matrix with values of shape (nnz)
>>> indices = torch.tensor([[0, 0, 1, 2], >>> indices = torch.tensor([[0, 0, 1, 2], [1, 2, 2, 0]])
>>> [1, 2, 2, 0]])
>>> nnz = len(row) >>> nnz = len(row)
>>> val = torch.arange(nnz).float() >>> val = torch.arange(nnz).float()
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
...@@ -47,8 +46,7 @@ def softmax(input: SparseMatrix) -> SparseMatrix: ...@@ -47,8 +46,7 @@ def softmax(input: SparseMatrix) -> SparseMatrix:
Case2: matrix with values of shape (nnz, D) Case2: matrix with values of shape (nnz, D)
>>> indices = torch.tensor([[0, 0, 1, 2], >>> indices = torch.tensor([[0, 0, 1, 2], [1, 2, 2, 0]])
>>> [1, 2, 2, 0]])
>>> val = torch.tensor([[0., 7.], [1., 3.], [2., 2.], [3., 1.]]) >>> val = torch.tensor([[0., 7.], [1., 3.], [2., 2.], [3., 1.]])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> dglsp.softmax(A) >>> dglsp.softmax(A)
......
...@@ -108,8 +108,7 @@ class SparseMatrix: ...@@ -108,8 +108,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 2, 1], >>> indices = torch.tensor([[1, 2, 1], [2, 4, 3]])
>>> [2, 4, 3]])
>>> A = from_coo(dst, src) >>> A = from_coo(dst, src)
>>> A.coo() >>> A.coo()
(tensor([1, 2, 1]), tensor([2, 4, 3])) (tensor([1, 2, 1]), tensor([2, 4, 3]))
...@@ -140,8 +139,7 @@ class SparseMatrix: ...@@ -140,8 +139,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 2, 1], >>> indices = torch.tensor([[1, 2, 1], [2, 4, 3]])
>>> [2, 4, 3]])
>>> A = from_coo(dst, src) >>> A = from_coo(dst, src)
>>> A.csr() >>> A.csr()
(tensor([0, 0, 2, 3]), tensor([2, 3, 4]), tensor([0, 2, 1])) (tensor([0, 0, 2, 3]), tensor([2, 3, 4]), tensor([0, 2, 1]))
...@@ -172,8 +170,7 @@ class SparseMatrix: ...@@ -172,8 +170,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 2, 1], >>> indices = torch.tensor([[1, 2, 1], [2, 4, 3]])
>>> [2, 4, 3]])
>>> A = from_coo(dst, src) >>> A = from_coo(dst, src)
>>> A.csc() >>> A.csc()
(tensor([0, 0, 0, 1, 2, 3]), tensor([1, 1, 2]), tensor([0, 2, 1])) (tensor([0, 0, 0, 1, 2, 3]), tensor([1, 1, 2]), tensor([0, 2, 1]))
...@@ -215,8 +212,7 @@ class SparseMatrix: ...@@ -215,8 +212,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 3], >>> indices = torch.tensor([[1, 1, 3], [2, 1, 3]])
>>> [2, 1, 3]])
>>> val = torch.tensor([1, 1, 2]) >>> val = torch.tensor([1, 1, 2])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> A = A.transpose() >>> A = A.transpose()
...@@ -248,8 +244,7 @@ class SparseMatrix: ...@@ -248,8 +244,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
>>> [1, 2, 0]])
>>> A = dglsp.spmatrix(indices, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, shape=(3, 4))
>>> A.to(device='cuda:0', dtype=torch.int32) >>> A.to(device='cuda:0', dtype=torch.int32)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -289,8 +284,7 @@ class SparseMatrix: ...@@ -289,8 +284,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
>>> [1, 2, 0]])
>>> A = dglsp.spmatrix(indices, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, shape=(3, 4))
>>> A.cuda() >>> A.cuda()
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -312,8 +306,7 @@ class SparseMatrix: ...@@ -312,8 +306,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]]).to("cuda")
>>> [1, 2, 0]]).to("cuda")
>>> A = dglsp.spmatrix(indices, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, shape=(3, 4))
>>> A.cpu() >>> A.cpu()
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -335,8 +328,7 @@ class SparseMatrix: ...@@ -335,8 +328,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
>>> [1, 2, 0]])
>>> val = torch.ones(len(row)).long() >>> val = torch.ones(len(row)).long()
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
>>> A.float() >>> A.float()
...@@ -359,8 +351,7 @@ class SparseMatrix: ...@@ -359,8 +351,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
>>> [1, 2, 0]])
>>> A = dglsp.spmatrix(indices, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, shape=(3, 4))
>>> A.double() >>> A.double()
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -382,8 +373,7 @@ class SparseMatrix: ...@@ -382,8 +373,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
>>> [1, 2, 0]])
>>> A = dglsp.spmatrix(indices, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, shape=(3, 4))
>>> A.int() >>> A.int()
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -405,8 +395,7 @@ class SparseMatrix: ...@@ -405,8 +395,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
>>> [1, 2, 0]])
>>> A = dglsp.spmatrix(indices, shape=(3, 4)) >>> A = dglsp.spmatrix(indices, shape=(3, 4))
>>> A.long() >>> A.long()
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -436,8 +425,7 @@ class SparseMatrix: ...@@ -436,8 +425,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 0, 0, 1], >>> indices = torch.tensor([[1, 0, 0, 0, 1], [1, 1, 1, 2, 2]])
>>> [1, 1, 1, 2, 2]])
>>> val = torch.tensor([0, 1, 2, 3, 4]) >>> val = torch.tensor([0, 1, 2, 3, 4])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> A.coalesce() >>> A.coalesce()
...@@ -453,8 +441,7 @@ class SparseMatrix: ...@@ -453,8 +441,7 @@ class SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 0, 0, 0, 1], >>> indices = torch.tensor([[1, 0, 0, 0, 1], [1, 1, 1, 2, 2]])
>>> [1, 1, 1, 2, 2]])
>>> val = torch.tensor([0, 1, 2, 3, 4]) >>> val = torch.tensor([0, 1, 2, 3, 4])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> A.has_duplicate() >>> A.has_duplicate()
...@@ -512,8 +499,7 @@ def spmatrix( ...@@ -512,8 +499,7 @@ def spmatrix(
Case2: Sparse matrix with scalar values. Case2: Sparse matrix with scalar values.
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]])
>>> [2, 4, 3]])
>>> val = torch.tensor([[1.], [2.], [3.]]) >>> val = torch.tensor([[1.], [2.], [3.]])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -575,8 +561,7 @@ def from_coo( ...@@ -575,8 +561,7 @@ 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], >>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]])
>>> [2, 4, 3]])
>>> A = dglsp.spmatrix(indices) >>> A = dglsp.spmatrix(indices)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]), [2, 4, 3]]),
...@@ -591,8 +576,7 @@ def from_coo( ...@@ -591,8 +576,7 @@ def from_coo(
Case2: Sparse matrix with scalar values. Case2: Sparse matrix with scalar values.
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]])
>>> [2, 4, 3]])
>>> val = torch.tensor([[1.], [2.], [3.]]) >>> val = torch.tensor([[1.], [2.], [3.]])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -604,8 +588,7 @@ def from_coo( ...@@ -604,8 +588,7 @@ def from_coo(
Case3: Sparse matrix with vector values. Case3: Sparse matrix with vector values.
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]])
>>> [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.spmatrix(indices, val)
SparseMatrix(indices=tensor([[1, 1, 2], SparseMatrix(indices=tensor([[1, 1, 2],
...@@ -828,8 +811,7 @@ def val_like(mat: SparseMatrix, val: torch.Tensor) -> SparseMatrix: ...@@ -828,8 +811,7 @@ def val_like(mat: SparseMatrix, val: torch.Tensor) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 2], >>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]])
>>> [2, 4, 3]])
>>> val = torch.ones(3) >>> val = torch.ones(3)
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> A = dglsp.val_like(A, torch.tensor([2, 2, 2])) >>> A = dglsp.val_like(A, torch.tensor([2, 2, 2]))
......
...@@ -14,8 +14,7 @@ def neg(A: SparseMatrix) -> SparseMatrix: ...@@ -14,8 +14,7 @@ def neg(A: SparseMatrix) -> SparseMatrix:
Examples Examples
-------- --------
>>> indices = torch.tensor([[1, 1, 3], >>> indices = torch.tensor([[1, 1, 3], [1, 2, 3]])
>>> [1, 2, 3]])
>>> val = torch.tensor([1., 1., 2.]) >>> val = torch.tensor([1., 1., 2.])
>>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.spmatrix(indices, val)
>>> A = -A >>> A = -A
......
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