dgl.sparse_v0.rst 2.15 KB
Newer Older
1
2
.. _apibackend:

3
🆕 dgl.sparse
4
5
=================================

6
`dgl.sparse` is a library for sparse operators that are commonly used in GNN models.
7
8
9

Sparse matrix class
-------------------------
10
.. currentmodule:: dgl.sparse
11

Israt Nisa's avatar
Israt Nisa committed
12
13
.. class:: SparseMatrix

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
14
15
    A SparseMatrix can be created from Coordinate format indices using the
    :func:`spmatrix` constructor:
Israt Nisa's avatar
Israt Nisa committed
16

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
17
18
19
        >>> indices = torch.tensor([[1, 1, 2],
        >>>                         [2, 4, 3]])
        >>> A = dglsp.spmatrix(indices)
Israt Nisa's avatar
Israt Nisa committed
20
21
22
23
24
        SparseMatrix(indices=tensor([[1, 1, 2],
                                     [2, 4, 3]]),
                     values=tensor([1., 1., 1.]),
                     shape=(3, 5), nnz=3)

25
Creation Ops
26
````````
Israt Nisa's avatar
Israt Nisa committed
27
28

.. autosummary::
29
30
    :toctree: ../../generated/

31
32
    spmatrix
    val_like
33
34
35
    from_coo
    from_csr
    from_csc
36
37
    diag
    identity
38
39
40
41
42
43

Attributes and methods
``````````````````````

.. autosummary::
    :toctree: ../../generated/
Israt Nisa's avatar
Israt Nisa committed
44
45
46
47
48

    SparseMatrix.shape
    SparseMatrix.nnz
    SparseMatrix.dtype
    SparseMatrix.device
49
    SparseMatrix.val
Israt Nisa's avatar
Israt Nisa committed
50
51
52
53
54
    SparseMatrix.row
    SparseMatrix.col
    SparseMatrix.coo
    SparseMatrix.csr
    SparseMatrix.csc
55
56
    SparseMatrix.coalesce
    SparseMatrix.has_duplicate
57
    SparseMatrix.to_dense
58
59
60
61
62
63
64
    SparseMatrix.to
    SparseMatrix.cuda
    SparseMatrix.cpu
    SparseMatrix.float
    SparseMatrix.double
    SparseMatrix.int
    SparseMatrix.long
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
65
66
67
68
    SparseMatrix.transpose
    SparseMatrix.t
    SparseMatrix.T
    SparseMatrix.neg
Israt Nisa's avatar
Israt Nisa committed
69
70
71
72
73
74
    SparseMatrix.reduce
    SparseMatrix.sum
    SparseMatrix.smax
    SparseMatrix.smin
    SparseMatrix.smean
    SparseMatrix.softmax
75

76
77
Operators
---------
78
.. currentmodule:: dgl.sparse
79

80
81
82
83
84
85
86
87
Elementwise Operators
````````

.. autosummary::
    :toctree: ../../generated/

    add
    sub
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
88
89
    mul
    div
90
91
92
93
94
    power

Matrix Multiplication
````````

95
96
97
.. autosummary::
    :toctree: ../../generated/

98
    matmul
99
100
    spmm
    bspmm
101
    spspmm
102
    sddmm
103
    bsddmm
104
105
106
107
108
109
110

Non-linear activation functions
````````

.. autosummary::
    :toctree: ../../generated/

111
    softmax
112
113
114
115
116
117
118
119
120
121
122
123

Broadcast operators
````````

.. autosummary::
    :toctree: ../../generated/

    sp_broadcast_v
    sp_add_v
    sp_sub_v
    sp_mul_v
    sp_div_v