dgl.sparse_v0.rst 2.17 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
    SparseMatrix.row
    SparseMatrix.col
52
    SparseMatrix.indices
Israt Nisa's avatar
Israt Nisa committed
53
54
55
    SparseMatrix.coo
    SparseMatrix.csr
    SparseMatrix.csc
56
57
    SparseMatrix.coalesce
    SparseMatrix.has_duplicate
58
    SparseMatrix.to_dense
59
60
61
62
63
64
65
    SparseMatrix.to
    SparseMatrix.cuda
    SparseMatrix.cpu
    SparseMatrix.float
    SparseMatrix.double
    SparseMatrix.int
    SparseMatrix.long
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
66
67
68
69
    SparseMatrix.transpose
    SparseMatrix.t
    SparseMatrix.T
    SparseMatrix.neg
Israt Nisa's avatar
Israt Nisa committed
70
71
72
73
74
75
    SparseMatrix.reduce
    SparseMatrix.sum
    SparseMatrix.smax
    SparseMatrix.smin
    SparseMatrix.smean
    SparseMatrix.softmax
76

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

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

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

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

Matrix Multiplication
````````

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

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

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

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

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

Broadcast operators
````````

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

    sp_broadcast_v
    sp_add_v
    sp_sub_v
    sp_mul_v
    sp_div_v