"torchvision/vscode:/vscode.git/clone" did not exist on "6434deadb3566999abe97bab963fbdc092d9028c"
Unverified Commit 1a33ee99 authored by Hongzhi (Steve), Chen's avatar Hongzhi (Steve), Chen Committed by GitHub
Browse files

[Sparse] Update doc string of element-wise ops for DiagMatrix and SparseMatrix. (#5136)



* doc

* minor

* black

* no-lint

* reorg
Co-authored-by: default avatarSteve <ubuntu@ip-172-31-34-29.ap-northeast-1.compute.internal>
parent c5119480
...@@ -153,6 +153,19 @@ Operators ...@@ -153,6 +153,19 @@ Operators
--------- ---------
.. currentmodule:: dgl.sparse .. currentmodule:: dgl.sparse
Elementwise Operators
````````
.. autosummary::
:toctree: ../../generated/
add
sub
power
Matrix Multiplication
````````
.. autosummary:: .. autosummary::
:toctree: ../../generated/ :toctree: ../../generated/
...@@ -162,4 +175,11 @@ Operators ...@@ -162,4 +175,11 @@ Operators
mm mm
sddmm sddmm
bsddmm bsddmm
Non-linear activation functions
````````
.. autosummary::
:toctree: ../../generated/
softmax softmax
# pylint: disable=anomalous-backslash-in-string
"""DGL elementwise operator module.""" """DGL elementwise operator module."""
from typing import Union from typing import Union
...@@ -10,7 +11,18 @@ __all__ = ["add", "power"] ...@@ -10,7 +11,18 @@ __all__ = ["add", "power"]
def add( def add(
A: Union[DiagMatrix, SparseMatrix], B: Union[DiagMatrix, SparseMatrix] A: Union[DiagMatrix, SparseMatrix], B: Union[DiagMatrix, SparseMatrix]
) -> Union[DiagMatrix, SparseMatrix]: ) -> Union[DiagMatrix, SparseMatrix]:
"""Elementwise addition """Elementwise additions for `DiagMatrix` and `SparseMatrix`.
The supported combinations are shown as follow.
+--------------+------------+--------------+--------+
| A \ B | DiagMatrix | SparseMatrix | scalar |
+--------------+------------+--------------+--------+
| DiagMatrix | ✅ | ✅ | 🚫 |
+--------------+------------+--------------+--------+
| SparseMatrix | ✅ | ✅ | 🚫 |
+--------------+------------+--------------+--------+
| scalar | 🚫 | 🚫 | 🚫 |
+--------------+------------+--------------+--------+
Parameters Parameters
---------- ----------
...@@ -41,11 +53,58 @@ def add( ...@@ -41,11 +53,58 @@ def add(
return A + B return A + B
def sub(A: Union[DiagMatrix], B: Union[DiagMatrix]) -> Union[DiagMatrix]:
"""Elementwise subtraction for `DiagMatrix` and `SparseMatrix`.
The supported combinations are shown as follow.
+--------------+------------+--------------+--------+
| A \ B | DiagMatrix | SparseMatrix | scalar |
+--------------+------------+--------------+--------+
| DiagMatrix | ✅ | 🚫 | 🚫 |
+--------------+------------+--------------+--------+
| SparseMatrix | 🚫 | 🚫 | 🚫 |
+--------------+------------+--------------+--------+
| scalar | 🚫 | 🚫 | 🚫 |
+--------------+------------+--------------+--------+
Parameters
----------
A : DiagMatrix
Diagonal matrix
B : DiagMatrix
Diagonal matrix
Returns
-------
DiagMatrix
Diagonal matrix
Examples
--------
>>> A = diag(torch.arange(1, 4))
>>> B = diag(torch.arange(10, 13))
>>> A - B
DiagMatrix(val=tensor([-9, -9, -9]),
shape=(3, 3))
"""
return A - B
def power( def power(
A: Union[SparseMatrix, DiagMatrix], scalar: Union[float, int] A: Union[SparseMatrix, DiagMatrix], scalar: Union[float, int]
) -> Union[SparseMatrix, DiagMatrix]: ) -> Union[SparseMatrix, DiagMatrix]:
"""Take the power of each nonzero element and return a matrix with """Elementwise exponentiation for `DiagMatrix` and `SparseMatrix`.
the result.
The supported combinations are shown as follow.
+--------------+------------+--------------+--------+
| A \ B | DiagMatrix | SparseMatrix | scalar |
+--------------+------------+--------------+--------+
| DiagMatrix | 🚫 | 🚫 | ✅ |
+--------------+------------+--------------+--------+
| SparseMatrix | 🚫 | 🚫 | ✅ |
+--------------+------------+--------------+--------+
| scalar | 🚫 | 🚫 | 🚫 |
+--------------+------------+--------------+--------+
Parameters Parameters
---------- ----------
......
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