MCPcopy
hub / github.com/dmlc/dgl / SparseMatrix

Class SparseMatrix

python/dgl/sparse/sparse_matrix.py:8–760  ·  view source on GitHub ↗

r"""Class for sparse matrix.

Source from the content-addressed store, hash-verified

6
7
8class SparseMatrix:
9 r"""Class for sparse matrix."""
10
11 def __init__(self, c_sparse_matrix: torch.ScriptObject):
12 self.c_sparse_matrix = c_sparse_matrix
13
14 def __repr__(self):
15 return _sparse_matrix_str(self)
16
17 @property
18 def val(self) -> torch.Tensor:
19 """Returns the values of the non-zero elements.
20
21 Returns
22 -------
23 torch.Tensor
24 Values of the non-zero elements
25 """
26 return self.c_sparse_matrix.val()
27
28 @property
29 def shape(self) -> Tuple[int]:
30 """Returns the shape of the sparse matrix.
31
32 Returns
33 -------
34 Tuple[int]
35 The shape of the sparse matrix
36 """
37 return tuple(self.c_sparse_matrix.shape())
38
39 @property
40 def nnz(self) -> int:
41 """Returns the number of non-zero elements in the sparse matrix.
42
43 Returns
44 -------
45 int
46 The number of non-zero elements of the matrix
47 """
48 return self.c_sparse_matrix.nnz()
49
50 @property
51 def dtype(self) -> torch.dtype:
52 """Returns the data type of the sparse matrix.
53
54 Returns
55 -------
56 torch.dtype
57 Data type of the sparse matrix
58 """
59 return self.c_sparse_matrix.val().dtype
60
61 @property
62 def device(self) -> torch.device:
63 """Returns the device the sparse matrix is on.
64
65 Returns

Callers 15

spsp_addFunction · 0.70
spsp_mulFunction · 0.70
spsp_divFunction · 0.70
sddmmFunction · 0.70
softmaxFunction · 0.70
spspmmFunction · 0.70
transposeMethod · 0.70
coalesceMethod · 0.70
index_selectMethod · 0.70
range_selectMethod · 0.70
sampleMethod · 0.70
compactMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected