STAG Python  2.0.2
Spectral Toolkit of Algorithms for Graphs
Loading...
Searching...
No Matches
stag.utility.SprsMat Class Reference

Description

An object representing a sparse matrix for use by the STAG library.

The data is stored natively on the 'C++' side of the library, allowing for fast computation.

The object is designed for easy interoperability with scipy sparse matrix objects. The SprsMat object can be constructed directly from a scipy sparse matrix, and the to_scipy() method can be used to convert back to a scipy matrix.

If they are only used as arguments to STAG library methods, they will be very efficient since the data will stay on the C++ side of the library.

Public Member Functions

def __init__ (self, Union[scipy.sparse.spmatrix, List[List[float]]] matrix)
 Construct a STAG SprsMat.
 
scipy.sparse.csc_matrix to_scipy (self)
 Convert the STAG SprsMat object to a scipy sparse matrix.
 
np.ndarray to_dense (self)
 Convert the STAG SprsMat object to a dense numpy matrix.
 
'SprsMattranspose (self)
 Return the transpose of the matrix.
 
Tuple[int, int] shape (self)
 Return the shape of the matrix.
 

Public Attributes

 scipy_mat
 

Constructor & Destructor Documentation

◆ __init__()

def stag.utility.SprsMat.__init__ (   self,
Union[scipy.sparse.spmatrix, List[List[float]]]  matrix 
)

Construct a STAG SprsMat.

Pass either a scipy sparse matrix object or a List of Lists representing the dense matrix to be stored in sparse format.

For example:

>>> import stag.utility
>>> import stag.graph
>>>
>>> adj_mat = stag.utility.SprsMat([[0, 1, 1, 1],
... [1, 0, 1, 1],
... [1, 1, 0, 1],
... [1, 1, 1, 0]])
>>> g = stag.graph.Graph(adj_mat)
The core object used to represent graphs for use with the library.
Definition: graph.py:300
An object representing a sparse matrix for use by the STAG library.
Definition: utility.py:165
Definition: graph.py:1
Definition: utility.py:1

Member Function Documentation

◆ to_scipy()

scipy.sparse.csc_matrix stag.utility.SprsMat.to_scipy (   self)

Convert the STAG SprsMat object to a scipy sparse matrix.

◆ to_dense()

np.ndarray stag.utility.SprsMat.to_dense (   self)

Convert the STAG SprsMat object to a dense numpy matrix.

◆ transpose()

'SprsMat' stag.utility.SprsMat.transpose (   self)

Return the transpose of the matrix.

◆ shape()

Tuple[int, int] stag.utility.SprsMat.shape (   self)

Return the shape of the matrix.

Member Data Documentation

◆ scipy_mat

stag.utility.SprsMat.scipy_mat