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

[Doc] Update with Mono font to keep doc string consistent. (#5213)



* part1

* more

* more

* spmatrix

* code
Co-authored-by: default avatarSteve <ubuntu@ip-172-31-34-29.ap-northeast-1.compute.internal>
parent d61012e0
...@@ -181,7 +181,7 @@ class DiagMatrix: ...@@ -181,7 +181,7 @@ class DiagMatrix:
>>> val = torch.ones(2) >>> val = torch.ones(2)
>>> D = dglsp.diag(val) >>> D = dglsp.diag(val)
>>> D.to(device='cuda:0', dtype=torch.int32) >>> D.to(device="cuda:0", dtype=torch.int32)
DiagMatrix(values=tensor([1, 1], device='cuda:0', dtype=torch.int32), DiagMatrix(values=tensor([1, 1], device='cuda:0', dtype=torch.int32),
shape=(2, 2)) shape=(2, 2))
""" """
...@@ -198,7 +198,7 @@ class DiagMatrix: ...@@ -198,7 +198,7 @@ class DiagMatrix:
def cuda(self): def cuda(self):
"""Moves the matrix to GPU. If the matrix is already on GPU, the """Moves the matrix to GPU. If the matrix is already on GPU, the
original matrix will be returned. If multiple GPU devices exist, original matrix will be returned. If multiple GPU devices exist,
'cuda:0' will be selected. ``cuda:0`` will be selected.
Returns Returns
------- -------
...@@ -383,7 +383,7 @@ def identity( ...@@ -383,7 +383,7 @@ def identity(
Shape of the matrix. Shape of the matrix.
d : int, optional d : int, optional
If None, the diagonal entries will be scaler 1. Otherwise, the diagonal If None, the diagonal entries will be scaler 1. Otherwise, the diagonal
entries will be a 1-valued tensor of shape (d). entries will be a 1-valued tensor of shape ``(d)``.
dtype : torch.dtype, optional dtype : torch.dtype, optional
The data type of the matrix The data type of the matrix
device : torch.device, optional device : torch.device, optional
...@@ -399,9 +399,11 @@ def identity( ...@@ -399,9 +399,11 @@ def identity(
Case1: 3-by-3 matrix with scaler diagonal values Case1: 3-by-3 matrix with scaler diagonal values
[[1, 0, 0], .. code::
[0, 1, 0],
[0, 0, 1]] [[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]
>>> dglsp.identity(shape=(3, 3)) >>> dglsp.identity(shape=(3, 3))
DiagMatrix(val=tensor([1., 1., 1.]), DiagMatrix(val=tensor([1., 1., 1.]),
...@@ -409,9 +411,11 @@ def identity( ...@@ -409,9 +411,11 @@ def identity(
Case2: 3-by-5 matrix with scaler diagonal values Case2: 3-by-5 matrix with scaler diagonal values
[[1, 0, 0, 0, 0], .. code::
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0]] [[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0]]
>>> dglsp.identity(shape=(3, 5)) >>> dglsp.identity(shape=(3, 5))
DiagMatrix(val=tensor([1., 1., 1.]), DiagMatrix(val=tensor([1., 1., 1.]),
......
...@@ -254,10 +254,9 @@ def matmul( ...@@ -254,10 +254,9 @@ def matmul(
* The operator supports batched sparse-dense matrix multiplication. In \ * The operator supports batched sparse-dense matrix multiplication. In \
this case, the sparse or diagonal matrix :attr:`A` should have shape \ this case, the sparse or diagonal matrix :attr:`A` should have shape \
:math:`(L, M)`, where the non-zero values have a batch dimension \ ``(L, M)``, where the non-zero values have a batch dimension ``K``. \
:math:`K`. The dense matrix :attr:`B` should have shape \ The dense matrix :attr:`B` should have shape ``(M, N, K)``. The output \
:math:`(M, N, K)`. The output is a dense matrix of shape \ is a dense matrix of shape ``(L, N, K)``.
:math:`(L, N, K)`.
* Sparse-sparse matrix multiplication does not support batched computation. * Sparse-sparse matrix multiplication does not support batched computation.
......
...@@ -9,8 +9,8 @@ from .sparse_matrix import SparseMatrix ...@@ -9,8 +9,8 @@ from .sparse_matrix import SparseMatrix
def reduce(input: SparseMatrix, dim: Optional[int] = None, rtype: str = "sum"): def reduce(input: SparseMatrix, dim: Optional[int] = None, rtype: str = "sum"):
"""Computes the reduction of non-zero values of the ``input`` sparse matrix """Computes the reduction of non-zero values of the :attr:`input` sparse
along the given dimension :attr:`dim`. matrix along the given dimension :attr:`dim`.
The reduction does not count zero elements. If the row or column to be The reduction does not count zero elements. If the row or column to be
reduced does not have any non-zero elements, the result will be 0. reduced does not have any non-zero elements, the result will be 0.
...@@ -83,8 +83,8 @@ def reduce(input: SparseMatrix, dim: Optional[int] = None, rtype: str = "sum"): ...@@ -83,8 +83,8 @@ def reduce(input: SparseMatrix, dim: Optional[int] = None, rtype: str = "sum"):
def sum(input: SparseMatrix, dim: Optional[int] = None): def sum(input: SparseMatrix, dim: Optional[int] = None):
"""Computes the sum of non-zero values of the ``input`` sparse matrix along """Computes the sum of non-zero values of the :attr:`input` sparse matrix
the given dimension :attr:`dim`. along the given dimension :attr:`dim`.
Parameters Parameters
---------- ----------
...@@ -137,8 +137,8 @@ def sum(input: SparseMatrix, dim: Optional[int] = None): ...@@ -137,8 +137,8 @@ def sum(input: SparseMatrix, dim: Optional[int] = None):
def smax(input: SparseMatrix, dim: Optional[int] = None): def smax(input: SparseMatrix, dim: Optional[int] = None):
"""Computes the maximum of non-zero values of the ``input`` sparse matrix """Computes the maximum of non-zero values of the :attr:`input` sparse
along the given dimension :attr:`dim`. matrix along the given dimension :attr:`dim`.
The reduction does not count zero values. If the row or column to be The reduction does not count zero values. If the row or column to be
reduced does not have any non-zero value, the result will be 0. reduced does not have any non-zero value, the result will be 0.
...@@ -195,8 +195,8 @@ def smax(input: SparseMatrix, dim: Optional[int] = None): ...@@ -195,8 +195,8 @@ def smax(input: SparseMatrix, dim: Optional[int] = None):
def smin(input: SparseMatrix, dim: Optional[int] = None): def smin(input: SparseMatrix, dim: Optional[int] = None):
"""Computes the minimum of non-zero values of the ``input`` sparse matrix """Computes the minimum of non-zero values of the :attr:`input` sparse
along the given dimension :attr:`dim`. matrix along the given dimension :attr:`dim`.
The reduction does not count zero values. If the row or column to be reduced The reduction does not count zero values. If the row or column to be reduced
does not have any non-zero value, the result will be 0. does not have any non-zero value, the result will be 0.
...@@ -257,8 +257,8 @@ def smin(input: SparseMatrix, dim: Optional[int] = None): ...@@ -257,8 +257,8 @@ def smin(input: SparseMatrix, dim: Optional[int] = None):
def smean(input: SparseMatrix, dim: Optional[int] = None): def smean(input: SparseMatrix, dim: Optional[int] = None):
"""Computes the mean of non-zero values of the ``input`` sparse matrix along """Computes the mean of non-zero values of the :attr:`input` sparse matrix
the given dimension :attr:`dim`. along the given dimension :attr:`dim`.
The reduction does not count zero values. If the row or column to be reduced The reduction does not count zero values. If the row or column to be reduced
does not have any non-zero value, the result will be 0. does not have any non-zero value, the result will be 0.
...@@ -319,8 +319,8 @@ def smean(input: SparseMatrix, dim: Optional[int] = None): ...@@ -319,8 +319,8 @@ def smean(input: SparseMatrix, dim: Optional[int] = None):
def sprod(input: SparseMatrix, dim: Optional[int] = None): def sprod(input: SparseMatrix, dim: Optional[int] = None):
"""Computes the product of non-zero values of the ``input`` sparse matrix """Computes the product of non-zero values of the :attr:`input` sparse
along the given dimension :attr:`dim`. matrix along the given dimension :attr:`dim`.
The reduction does not count zero values. If the row or column to be reduced The reduction does not count zero values. If the row or column to be reduced
does not have any non-zero value, the result will be 0. does not have any non-zero value, the result will be 0.
......
...@@ -14,7 +14,7 @@ def softmax(input: SparseMatrix) -> SparseMatrix: ...@@ -14,7 +14,7 @@ def softmax(input: SparseMatrix) -> SparseMatrix:
Equivalently, applies softmax to the non-zero elements of the sparse Equivalently, applies softmax to the non-zero elements of the sparse
matrix along the column (``dim=1``) dimension. matrix along the column (``dim=1``) dimension.
If :attr:`input.val` takes shape :attr:`(nnz, D)`, then the output matrix If :attr:`input.val` takes shape ``(nnz, D)``, then the output matrix
:attr:`output` and :attr:`output.val` take the same shape as :attr:`input` :attr:`output` and :attr:`output.val` take the same shape as :attr:`input`
and :attr:`input.val`. :attr:`output.val[:, i]` is calculated based on and :attr:`input.val`. :attr:`output.val[:, i]` is calculated based on
:attr:`input.val[:, i]`. :attr:`input.val[:, i]`.
......
...@@ -246,7 +246,7 @@ class SparseMatrix: ...@@ -246,7 +246,7 @@ class SparseMatrix:
>>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]]) >>> indices = torch.tensor([[1, 1, 2], [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],
[1, 2, 0]], device='cuda:0'), [1, 2, 0]], device='cuda:0'),
values=tensor([1, 1, 1], device='cuda:0', values=tensor([1, 1, 1], device='cuda:0',
...@@ -274,7 +274,7 @@ class SparseMatrix: ...@@ -274,7 +274,7 @@ class SparseMatrix:
def cuda(self): def cuda(self):
"""Moves the matrix to GPU. If the matrix is already on GPU, the """Moves the matrix to GPU. If the matrix is already on GPU, the
original matrix will be returned. If multiple GPU devices exist, original matrix will be returned. If multiple GPU devices exist,
'cuda:0' will be selected. ``cuda:0`` will be selected.
Returns Returns
------- -------
...@@ -308,6 +308,7 @@ class SparseMatrix: ...@@ -308,6 +308,7 @@ class SparseMatrix:
>>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]]).to("cuda") >>> indices = torch.tensor([[1, 1, 2], [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],
[1, 2, 0]]), [1, 2, 0]]),
...@@ -466,12 +467,12 @@ def spmatrix( ...@@ -466,12 +467,12 @@ def spmatrix(
which should have shape of ``(2, N)`` where the first row is the row which should have shape of ``(2, N)`` where the first row is the row
indices and the second row is the column indices of non-zero elements. indices and the second row is the column indices of non-zero elements.
val : tensor.Tensor, optional val : tensor.Tensor, optional
The values of shape (nnz) or (nnz, D). If None, it will be a tensor of The values of shape ``(nnz)`` or ``(nnz, D)``. If None, it will be a
shape (nnz) filled by 1. tensor of shape ``(nnz)`` filled by 1.
shape : tuple[int, int], optional shape : tuple[int, int], optional
If not specified, it will be inferred from :attr:`row` and :attr:`col`, If not specified, it will be inferred from :attr:`row` and :attr:`col`,
i.e., (row.max() + 1, col.max() + 1). Otherwise, :attr:`shape` should i.e., ``(row.max() + 1, col.max() + 1)``. Otherwise, :attr:`shape`
be no smaller than this. should be no smaller than this.
Returns Returns
------- -------
...@@ -540,16 +541,16 @@ def from_coo( ...@@ -540,16 +541,16 @@ def from_coo(
Parameters Parameters
---------- ----------
row : torch.Tensor row : torch.Tensor
The row indices of shape (nnz) The row indices of shape ``(nnz)``
col : torch.Tensor col : torch.Tensor
The column indices of shape (nnz) The column indices of shape ``(nnz)``
val : torch.Tensor, optional val : torch.Tensor, optional
The values of shape (nnz) or (nnz, D). If None, it will be a tensor of The values of shape ``(nnz)`` or ``(nnz, D)``. If None, it will be a
shape (nnz) filled by 1. tensor of shape ``(nnz)`` filled by 1.
shape : tuple[int, int], optional shape : tuple[int, int], optional
If not specified, it will be inferred from :attr:`row` and :attr:`col`, If not specified, it will be inferred from :attr:`row` and :attr:`col`,
i.e., (row.max() + 1, col.max() + 1). Otherwise, :attr:`shape` should i.e., ``(row.max() + 1, col.max() + 1)``. Otherwise, :attr:`shape`
be no smaller than this. should be no smaller than this.
Returns Returns
------- -------
...@@ -630,17 +631,17 @@ def from_csr( ...@@ -630,17 +631,17 @@ def from_csr(
Parameters Parameters
---------- ----------
indptr : torch.Tensor indptr : torch.Tensor
Pointer to the column indices of shape (N + 1), where N is the number Pointer to the column indices of shape ``(N + 1)``, where ``N`` is the
of rows number of rows
indices : torch.Tensor indices : torch.Tensor
The column indices of shape (nnz) The column indices of shape ``(nnz)``
val : torch.Tensor, optional val : torch.Tensor, optional
The values of shape (nnz) or (nnz, D). If None, it will be a tensor of The values of shape ``(nnz)`` or ``(nnz, D)``. If None, it will be a
shape (nnz) filled by 1. tensor of shape ``(nnz)`` filled by 1.
shape : tuple[int, int], optional shape : tuple[int, int], optional
If not specified, it will be inferred from :attr:`indptr` and If not specified, it will be inferred from :attr:`indptr` and
:attr:`indices`, i.e., (len(indptr) - 1, indices.max() + 1). Otherwise, :attr:`indices`, i.e., ``(len(indptr) - 1, indices.max() + 1)``.
:attr:`shape` should be no smaller than this. Otherwise, :attr:`shape` should be no smaller than this.
Returns Returns
------- -------
...@@ -652,9 +653,11 @@ def from_csr( ...@@ -652,9 +653,11 @@ def from_csr(
Case1: Sparse matrix without values Case1: Sparse matrix without values
[[0, 1, 0], .. code::
[0, 0, 1],
[1, 1, 1]] [[0, 1, 0],
[0, 0, 1],
[1, 1, 1]]
>>> indptr = torch.tensor([0, 1, 2, 5]) >>> indptr = torch.tensor([0, 1, 2, 5])
>>> indices = torch.tensor([1, 2, 0, 1, 2]) >>> indices = torch.tensor([1, 2, 0, 1, 2])
...@@ -725,12 +728,12 @@ def from_csc( ...@@ -725,12 +728,12 @@ def from_csc(
indices : torch.Tensor indices : torch.Tensor
The row indices of shape nnz The row indices of shape nnz
val : torch.Tensor, optional val : torch.Tensor, optional
The values of shape (nnz) or (nnz, D). If None, it will be a tensor of The values of shape ``(nnz)`` or ``(nnz, D)``. If None, it will be a
shape (nnz) filled by 1. tensor of shape ``(nnz)`` filled by 1.
shape : tuple[int, int], optional shape : tuple[int, int], optional
If not specified, it will be inferred from :attr:`indptr` and If not specified, it will be inferred from :attr:`indptr` and
:attr:`indices`, i.e., (indices.max() + 1, len(indptr) - 1). Otherwise, :attr:`indices`, i.e., ``(indices.max() + 1, len(indptr) - 1)``.
:attr:`shape` should be no smaller than this. Otherwise, :attr:`shape` should be no smaller than this.
Returns Returns
------- -------
...@@ -742,9 +745,11 @@ def from_csc( ...@@ -742,9 +745,11 @@ def from_csc(
Case1: Sparse matrix without values Case1: Sparse matrix without values
[[0, 1, 0], .. code::
[0, 0, 1],
[1, 1, 1]] [[0, 1, 0],
[0, 0, 1],
[1, 1, 1]]
>>> indptr = torch.tensor([0, 1, 3, 5]) >>> indptr = torch.tensor([0, 1, 3, 5])
>>> indices = torch.tensor([2, 0, 2, 1, 2]) >>> indices = torch.tensor([2, 0, 2, 1, 2])
...@@ -801,7 +806,8 @@ def val_like(mat: SparseMatrix, val: torch.Tensor) -> SparseMatrix: ...@@ -801,7 +806,8 @@ def val_like(mat: SparseMatrix, val: torch.Tensor) -> SparseMatrix:
mat : SparseMatrix mat : SparseMatrix
An existing sparse matrix with non-zero values An existing sparse matrix with non-zero values
val : torch.Tensor val : torch.Tensor
The new values of the non-zero elements, a tensor of shape (nnz) or (nnz, D) The new values of the non-zero elements, a tensor of shape ``(nnz)`` or
``(nnz, D)``
Returns Returns
------- -------
......
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