> Most of the basic operations have been extended to handle SparseArray
> objects, so, for example, there is no need to add any fixes to
> LinearAlgebra`MatrixManipulation` to make it compatible with
> SparseArray, because those fixes have already been made to the basic
> Mathematica functions like Part. However, there are a few exceptions:
> in some cases a function has to do the parsing of the input expression
> and forgets about SparseArray; for example:
There are more problems, specifically with MatrixManipulation, where
just making changes to the basic functions like Part wasn't enough. For
example:
In[1]:=
<<LinearAlgebra`MatrixManipulation`
In[2]:=
m={{1,2,3},{4,5,6},{7,8,9}};
In[3]:=
sa=SparseArray[m];
In[4]:=
BlockMatrix[Outer[Times,m,m]]
Out[4]=
{{1,2,3,2,4,6,3,6,9},{4,5,6,8,10,12,12,15,
18},{7,8,9,14,16,18,21,24,27},{4,8,12,5,10,15,6,12,18},{16,
20,24,20,25,30,24,30,36},{28,32,36,35,40,45,42,48,54},{7,14,21,8,16,
24,9,18,27},{28,35,42,32,40,48,36,45,54},{49,56,63,56,64,72,63,72,81}}
In[5]:=
BlockMatrix[Outer[Times,sa,sa]]
Out[5]=
{SparseArray[<9>,{9}],SparseArray[<9>,{9}],SparseArray[<9>,{9}],
SparseArray[<9>,{9}],SparseArray[<9>,{9}],SparseArray[<9>,{9}],
SparseArray[<9>,{9}],SparseArray[<9>,{9}],SparseArray[<9>,{9}]}
In[6]:=
SubMatrix[sa,{1,1},{2,2}]
Out[6]=
SubMatrix[SparseArray[<9>,{3,3}],{1,1},{2,2}]
Here BlockMatrix gives the answer in a peculiar form; a list of
SparseArrays, each representing one row of the answer. This is not
ideal, as it's an extremely inefficient representation, worse even than
as a nested list.
SubMatrix failed simply because it's defined expecting a _List as it's
argument, rather than a _?MatrixQ. These are both easy problems to fix,
but I'd hope Wolfram could release a new MatrixManipulations package
with it all done for us. :-) There are plenty more similar examples.
Scott Morrison