r"""Class for sparse matrix.
| 6 | |
| 7 | |
| 8 | class 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 |
no outgoing calls
no test coverage detected