dgl.sparse
dgl.sparse is a library for sparse operators that are commonly used in GNN models.
Sparse matrix class
- class dgl.sparse.SparseMatrix[source]
A SparseMatrix can be created from Coordinate format indices using the
spmatrix()
constructor:>>> indices = torch.tensor([[1, 1, 2], >>> [2, 4, 3]]) >>> A = dglsp.spmatrix(indices) SparseMatrix(indices=tensor([[1, 1, 2], [2, 4, 3]]), values=tensor([1., 1., 1.]), shape=(3, 5), nnz=3)
Creation Ops
|
Creates a sparse matrix from Coordinate format indices. |
|
Creates a sparse matrix from an existing sparse matrix using new values. |
|
Creates a sparse matrix from a coordinate list (COO), which stores a list of (row, column, value) tuples. |
|
Creates a sparse matrix from compress sparse row (CSR) format. |
|
Creates a sparse matrix from compress sparse column (CSC) format. |
|
Creates a sparse matrix based on the diagonal values. |
|
Creates a sparse matrix with ones on the diagonal and zeros elsewhere. |
Attributes and methods
Returns the shape of the sparse matrix. |
|
Returns the number of non-zero elements in the sparse matrix. |
|
Returns the data type of the sparse matrix. |
|
Returns the device the sparse matrix is on. |
|
Returns the values of the non-zero elements. |
|
Returns the row indices of the non-zero elements. |
|
Returns the column indices of the non-zero elements. |
|
Returns the coordinate list (COO) representation in one tensor with shape |
|
Returns the coordinate list (COO) representation of the sparse matrix. |
|
Returns the compressed sparse row (CSR) representation of the sparse matrix. |
|
Returns the compressed sparse column (CSC) representation of the sparse matrix. |
|
Returns a coalesced sparse matrix. |
|
Returns |
|
Returns a copy in dense matrix format of the sparse matrix. |
|
|
Performs matrix dtype and/or device conversion. |
Moves the matrix to GPU. |
|
Moves the matrix to CPU. |
|
Converts the matrix values to float32 data type. |
|
Converts the matrix values to double data type. |
|
Converts the matrix values to int32 data type. |
|
Converts the matrix values to long data type. |
|
Returns the transpose of this sparse matrix. |
|
Alias of |
|
Alias of |
|
Returns a new sparse matrix with the negation of the original nonzero values, equivalent to |
|
|
Computes the reduction of non-zero values of the |
|
Computes the sum of non-zero values of the |
|
Computes the maximum of non-zero values of the |
|
Computes the minimum of non-zero values of the |
|
Computes the mean of non-zero values of the |
|
Applies softmax to the non-zero elements of the sparse matrix on the dimension :attr: |
Operators
Elementwise Operators
|
Elementwise addition for |
|
Elementwise subtraction for |
|
Elementwise multiplication for |
|
Elementwise division for |
|
Elementwise exponentiation |
Matrix Multiplication
|
Multiplies two dense/sparse matrices, equivalent to |
|
Multiplies a sparse matrix by a dense matrix, equivalent to |
|
Multiplies a sparse matrix by a dense matrix by batches, equivalent to |
|
Multiplies a sparse matrix by a sparse matrix, equivalent to |
|
Sampled-Dense-Dense Matrix Multiplication (SDDMM). |
|
Sampled-Dense-Dense Matrix Multiplication (SDDMM) by batches. |
Non-linear activation functions
|
Applies softmax to the non-zero elements of the sparse matrix on the dimension :attr: |
Broadcast operators
|
Broadcast operator for sparse matrix and vector. |
|
Broadcast addition for sparse matrix and vector. |
|
Broadcast substraction for sparse matrix and vector. |
|
Broadcast multiply for sparse matrix and vector. |
|
Broadcast division for sparse matrix and vector. |