🆕 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. |
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 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 row-wise softmax to the non-zero elements of the sparse matrix. |
Diagonal matrix class¶
Creators¶
|
Creates a diagonal matrix based on the diagonal values. |
|
Creates a diagonal matrix with ones on the diagonal and zeros elsewhere. |
Attributes and methods¶
Returns the shape of the diagonal matrix. |
|
Returns the number of non-zero elements in the diagonal matrix. |
|
Returns the data type of the diagonal matrix. |
|
Returns the device the diagonal matrix is on. |
|
Returns the values of the non-zero elements. |
|
Returns a copy in sparse matrix format of the diagonal matrix. |
|
Returns a copy in dense matrix format of the diagonal 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 a matrix that is a transposed version of the diagonal matrix. |
|
Alias of |
|
Alias of |
|
Returns a new diagonal matrix with the negation of the original nonzero values, equivalent to |
|
Returns the inverse of the diagonal matrix. |
Operators¶
Elementwise Operators¶
|
Elementwise addition for |
|
Elementwise subtraction for |
|
Elementwise multiplication for |
|
Elementwise division for |
|
Elementwise exponentiation for |
Matrix Multiplication¶
|
Multiplies two dense/sparse/diagonal 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. |