Function Repository Resource:

SuiteSparseMatrix

Source Notebook

Import a sparse matrix from the SuiteSparse matrix collection

Contributed by: Igor Bakshee

ResourceFunction["SuiteSparseMatrix"][spec]

imports the specified sparse matrix from the SuiteSparse matrix collection.

ResourceFunction["SuiteSparseMatrix"][spec,prop]

retrieves the meta information property prop of the specified matrix.

ResourceFunction["SuiteSparseMatrix"][cprop]

gives the meta information property cprop of the collection.

ResourceFunction["SuiteSparseMatrix"][]

gives a list {{"name1","group1"},} for all matrices in the collection.

ResourceFunction["SuiteSparseMatrix"][session,]

uses the specified running ExternalSessionObject.

Details

ResourceFunction["SuiteSparseMatrix"][spec] retrieves the specified matrix from the SuiteSparse matrix collection (formerly, the University of Florida Sparse Matrix Collection) using a Python interface and returns a SparseArray object, a Failure object, or $Failed.
The matrix specification spec can be:
"name"matrix name
{"name","group"}name and group
idinteger ID
The property prop of a matrix can be "Matrix" or a meta information property including:
"ID"matrix ID
"Name"name
"Group"group
"Kind"short desription
{"prop1",}list of properties
"MetaInformation"available meta information
Allmeta information and the SparseArray value
ResourceFunction["SuiteSparseMatrix"][spec,"Matrix"] is essentially equivalent to ResourceFunction["SuiteSparseMatrix"][spec].
Collection properties cprop include:
Alla catalog of available matrices
"ContentDate"release date of the collection
"ContentLength"the number of matrices
"StatisticsURL"the default URL of the statistics file
Multiple properties are returned as an Association.
ResourceFunction["SuiteSparseMatrix"] is essentially a shortcut to retrieving a matrix in Python with the resource function ProbNumObject.

Examples

Basic Examples (2) 

Get a SuiteSparse matrix by name:

In[1]:=
ssm = ResourceFunction["SuiteSparseMatrix"]["ash85"]
Out[1]=
In[2]:=
MatrixPlot[ssm]
Out[2]=

Compute the matrix trace:

In[3]:=
Tr[ssm]
Out[3]=

Scope (9) 

Import a matrix by its name:

In[4]:=
ResourceFunction["SuiteSparseMatrix"]["ash85"]
Out[4]=

By the name and group:

In[5]:=
ResourceFunction["SuiteSparseMatrix"][{"ash85", "HB"}]
Out[5]=

By ID:

In[6]:=
ResourceFunction["SuiteSparseMatrix"][11]
Out[6]=

A list of available {"name","group"} pairs:

In[7]:=
ResourceFunction["SuiteSparseMatrix"][]
Out[7]=

Meta information:

In[8]:=
ResourceFunction["SuiteSparseMatrix"]["ash85", "MetaInformation"]
Out[8]=
In[9]:=
ResourceFunction["SuiteSparseMatrix"][11, "MetaInformation"]
Out[9]=

Specified property:

In[10]:=
ResourceFunction["SuiteSparseMatrix"]["ash85", "Kind"]
Out[10]=

Several properties:

In[11]:=
ResourceFunction["SuiteSparseMatrix"][11, {"Name", "Group"}]
Out[11]=

All available properties:

In[12]:=
ResourceFunction["SuiteSparseMatrix"]["ash85", All]
Out[12]=
In[13]:=
ResourceFunction["SuiteSparseMatrix"][11, All]
Out[13]=

Use a specified Python session:

In[14]:=
session = StartExternalSession["Python"]
Out[14]=
In[15]:=
ResourceFunction["SuiteSparseMatrix"][session, 11]
Out[15]=

Close the session:

In[16]:=
DeleteObject[session]

Applications (2) 

Obtain a graph representation of a large sparse matrix:

In[17]:=
m = ResourceFunction["SuiteSparseMatrix"]["diag"]
Out[17]=
In[18]:=
GraphPlot[%]
Out[18]=

3D visualization:

In[19]:=
ResourceFunction["SuiteSparseMatrix"]["3elt"]
Out[19]=
In[20]:=
GraphPlot3D[%]
Out[20]=

Properties and Relations (4) 

The total number of available sparse matrices currently available in the SuiteSparse matrix collection:

In[21]:=
ResourceFunction["SuiteSparseMatrix"]["ContentLength"]
Out[21]=

The latest update date of the content:

In[22]:=
ResourceFunction["SuiteSparseMatrix"]["ContentDate"]
Out[22]=

A catalog of available matrices:

In[23]:=
ResourceFunction["SuiteSparseMatrix"][All] // Dataset
Out[24]=

Some of these matrices are also available in ExampleData:

In[25]:=
ExampleData[{"Matrix", "1138BUS"}]
Out[25]=

The resource function ProbNumObject returns the sparse matrix given its name and group:

In[26]:=
session = StartExternalSession["Python"]
Out[26]=
In[27]:=
p = ResourceFunction["ProbNumObject"][session]
Out[27]=
In[28]:=
p["SuiteSparseMatrix"["bcspwr01", "HB"]]
Out[28]=

Convert to SparseArray:

In[29]:=
Normal[%]
Out[29]=

Obtain the same matrix with SuiteSparseMatrix:

In[30]:=
ResourceFunction["SuiteSparseMatrix"][session, {"bcspwr01", "HB"}]
Out[30]=
In[31]:=
SameQ[%, %%]
Out[31]=
In[32]:=
DeleteObject[session]

Possible Issues (2) 

SuiteSparseMatrix["name"] fails if the same name exists in several groups:

In[33]:=
ResourceFunction["SuiteSparseMatrix"]["barth"]
Out[33]=

Specify the group to retrieve the matrix:

In[34]:=
ResourceFunction["SuiteSparseMatrix"][{"barth", "Nasa"}]
Out[34]=

Neat Examples (1) 

Visualize the first few matrices from the SuiteSparse collection:

In[35]:=
session = StartExternalSession["Python"]
Out[35]=
In[36]:=
data = Table[
  ResourceFunction["SuiteSparseMatrix"][session, i, All], {i, 5}]
Out[37]=
In[38]:=
Dataset[data /. sp_SparseArray :> MatrixPlot[sp]]
Out[38]=
In[39]:=
DeleteObject[session]

Version History

  • 1.0.0 – 06 May 2022

Source Metadata

Related Resources

License Information