I found a few references to something called a "pattern sparse array" that does not contain any values, only positions. What is this data structure? How and when do I use it?
From the documentation of MSparseArray_getExplicitValues:
For a pattern sparse array where only positions are stored and there are no values, the result will point to a null (0)
MTensor
.
Some graph objects also contain a sparse array like this. The FullForm of e.g. SeedRandom[42]; RandomGraph[{5, 6}]
contains
SparseArray[Automatic, {5, 5}, 0, {1, {{0, 1, 4, 7, 9, 12}, {{2}, {1}, {3}, {5}, {2}, {4}, {5}, {3}, {5}, {2}, {3}, {4}}}, Pattern}]
The ArrayRules of this array are
{{1, 2} -> _, {2, 1} -> _, {2, 3} -> _, {2, 5} -> _, {3, 2} -> _, {3,
4} -> _, {3, 5} -> _, {4, 3} -> _, {4, 5} -> _, {5, 2} -> _, {5,
3} -> _, {5, 4} -> _, {_, _} -> 0}
Finally, a regular sparse array has a method called PatternArray
, which appears to create the equivalent sparse array with no values.
In[33]:= SparseArray[{0, 0, 1, 2, 0, 0, 3}] // InputForm
Out[33]//InputForm=
SparseArray[Automatic, {7}, 0, {1, {{0, 3}, {{3}, {4}, {7}}}, {1, 2, 3}}]
In[34]:= SparseArray[{0, 0, 1, 2, 0, 0, 3}]["PatternArray"] // InputForm
Out[34]//InputForm=
SparseArray[Automatic, {7}, 0, {1, {{0, 3}, {{3}, {4}, {7}}}, Pattern}]
NDSolve`StructuralIncidenceArray
-- I don't have M access right now, but can you create aGraph
from a pattern sparse array? $\endgroup$AdjacencyGraph@SparseArray[{{1, 1}, {2, 3}} -> _, {3, 3}]
. $\endgroup$NDSolve
link). $\endgroup$"PatternArray"
in the "Brusselator PDE" example of the LibraryLink tutorial Numerical Examples. $\endgroup$