Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
17fad103
Unverified
Commit
17fad103
authored
Jan 20, 2023
by
Hongzhi (Steve), Chen
Committed by
GitHub
Jan 20, 2023
Browse files
update (#5215)
Co-authored-by:
Steve
<
ubuntu@ip-172-31-34-29.ap-northeast-1.compute.internal
>
parent
a844d16e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
43 deletions
+5
-43
docs/source/api/python/dgl.sparse_v0.rst
docs/source/api/python/dgl.sparse_v0.rst
+5
-43
No files found.
docs/source/api/python/dgl.sparse_v0.rst
View file @
17fad103
...
@@ -11,55 +11,17 @@ Sparse matrix class
...
@@ -11,55 +11,17 @@ Sparse matrix class
.. class:: SparseMatrix
.. class:: SparseMatrix
Class for creating a sparse matrix representation
A SparseMatrix can be created from Coordinate format indices using the
:func:`spmatrix` constructor:
There are a few ways to create a sparse matrix:
>>> indices = torch.tensor([[1, 1, 2],
>>> [2, 4, 3]])
* In COO format using row and col indices, use :func:`from_coo`.
>>> A = dglsp.spmatrix(indices)
* In CSR format using row pointers and col indices, use :func:`from_csr`.
* In CSC format using col pointers and row indices, use :func:`from_csc`.
For example, one can create COO matrices as follows:
Case1: Sparse matrix with row and column indices without values
>>> row = torch.tensor([1, 1, 2])
>>> col = torch.tensor([2, 4, 3])
>>> A = from_coo(row, col)
>>> A
SparseMatrix(indices=tensor([[1, 1, 2],
SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]),
[2, 4, 3]]),
values=tensor([1., 1., 1.]),
values=tensor([1., 1., 1.]),
shape=(3, 5), nnz=3)
shape=(3, 5), nnz=3)
Case2: Sparse matrix with scalar/vector values
>>> # vector values
>>> val = torch.tensor([[1, 1], [2, 2], [3, 3]])
>>> A = from_coo(row, col, val)
SparseMatrix(indices=tensor([[1, 1, 2],
[2, 4, 3]]),
values=tensor([[1, 1],
[2, 2],
[3, 3]]),
shape=(3, 5), nnz=3)
Similarly, one can create a CSR matrix as follows:
>>> indptr = torch.tensor([0, 1, 2, 5])
>>> indices = torch.tensor([1, 2, 0, 1, 2])
>>> val = torch.tensor([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]])
>>> A = from_csr(indptr, indices, val)
>>> A
SparseMatrix(indices=tensor([[0, 1, 2, 2, 2],
[1, 2, 0, 1, 2]]),
values=tensor([[1, 1],
[2, 2],
[3, 3],
[4, 4],
[5, 5]]),
shape=(3, 3), nnz=5)
Creation Ops
Creation Ops
````````
````````
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment