dgl.sparse_v0.rst 2.64 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
38
39
40
41

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

.. autosummary::
    :toctree: ../../generated/
Israt Nisa's avatar
Israt Nisa committed
42
43
44
45
46

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

Diagonal matrix class
-------------------------
76
.. currentmodule:: dgl.sparse
77

78
.. class:: DiagMatrix
Israt Nisa's avatar
Israt Nisa committed
79

80
81
Creators
````````
Israt Nisa's avatar
Israt Nisa committed
82
83

.. autosummary::
84
85
86
87
88
89
90
91
92
93
    :toctree: ../../generated/

    diag
    identity

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

.. autosummary::
    :toctree: ../../generated/
Israt Nisa's avatar
Israt Nisa committed
94
95
96
97
98

    DiagMatrix.shape
    DiagMatrix.nnz
    DiagMatrix.dtype
    DiagMatrix.device
99
    DiagMatrix.val
100
101
    DiagMatrix.to_sparse
    DiagMatrix.to_dense
102
103
104
105
106
107
108
    DiagMatrix.to
    DiagMatrix.cuda
    DiagMatrix.cpu
    DiagMatrix.float
    DiagMatrix.double
    DiagMatrix.int
    DiagMatrix.long
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
109
110
111
    DiagMatrix.transpose
    DiagMatrix.t
    DiagMatrix.T
112
    DiagMatrix.neg
Israt Nisa's avatar
Israt Nisa committed
113
    DiagMatrix.inv
114

115
116
Operators
---------
117
.. currentmodule:: dgl.sparse
118

119
120
121
122
123
124
125
126
Elementwise Operators
````````

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

    add
    sub
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
127
128
    mul
    div
129
130
131
132
133
    power

Matrix Multiplication
````````

134
135
136
.. autosummary::
    :toctree: ../../generated/

137
    matmul
138
139
    spmm
    bspmm
140
    spspmm
141
    sddmm
142
    bsddmm
143
144
145
146
147
148
149

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

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

150
    softmax