"SparseArray" (Compiled Type)
"SparseArray"::[type,rank]
represents a sparse array composite type with elements of specified type and rank.
Details
- "SparseArray" can be used in Typed and related constructs to specify a type.
- "SparseArray" objects are automatically memory managed.
Expression Conversions
- SparseArray expressions can be converted into compiled code elements with types created with "SparseArray".
- Compiled code elements with types created with "SparseArray" can be converted into SparseArray expressions.
From Expressions
To Expressions
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
"SparseArray" can be used as an input and output from a CompiledCodeFunction:
In[1]:=1

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-ck3oom
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-fgxe20
Out[2]=2

In[3]:=3

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-b7fs2j

Scope (1)Survey of the scope of standard use cases
SparseArray properties may be used within CompiledCodeFunction:
In[1]:=1

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-fyv32h
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-dr9s82
Out[2]=2

This is equivalent to the "Density" property:
In[3]:=3

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-dp96x
Out[3]=3

The function uses real arithmetic so that it works even when the total number of elements is too large for a machine-sized integer:
In[4]:=4

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-fydpro
Out[4]=4

Neat Examples (1)Surprising or curious use cases
Compute a power series of a sparse matrix:
In[1]:=1

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-ctj6i5
Out[1]=1

This is equivalent to computing the square of a matrix:
In[2]:=2

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-dn18yk
Out[2]=2

Generate coefficients of the exponential function and use them to compute a matrix exponential:
In[3]:=3

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-mxskj3
Out[3]=3

The MatrixExp function is a better way to compute the exponential, but the power series result was close:
In[4]:=4

✖
https://wolfram.com/xid/0kxwryfilf5dyctojyjol8sgq-025noh
Out[4]=4
