<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - comments on Post, Sparse Matrix-Vector product using evaluation</title>
    <link>http://www.mapleprimes.com/posts/42963-Sparse-MatrixVector-Product-Using-Evaluation</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Tue, 09 Jun 2026 13:23:09 GMT</lastBuildDate>
    <pubDate>Tue, 09 Jun 2026 13:23:09 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest comments added to the Post, Sparse Matrix-Vector product using evaluation</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - comments on Post, Sparse Matrix-Vector product using evaluation</title>
      <link>http://www.mapleprimes.com/posts/42963-Sparse-MatrixVector-Product-Using-Evaluation</link>
    </image>
    <item>
      <title>Sparse Matrix-Vector Product: Application and Timing Comparison</title>
      <link>http://www.mapleprimes.com/posts/42963-Sparse-MatrixVector-Product-Using-Evaluation?ref=Feed:MaplePrimes:Sparse Matrix-Vector product using evaluation:Comments#comment79966</link>
      <itunes:summary>This is an interesting technique.  To see a benefit, I presume, the multiplication by the matrix must be done repeatedly for different vectors, otherwise the start-up cost is prohibitive.  An obvious application is Matrix-Matrix multiplication.  I put together a small procedure to test this:
&lt;pre&gt;
MatrixMultiply := proc(A,B)
local m,n,p,X,Ax,i,j,x,col;
uses LinearAlgebra:-LA_Main;
    m := op([1,1],A);
    (n,p) := op(1,B);
    X := rtable( 1..n
                 , i -&gt; x[i]
                 , 'subtype' = 'Vector'['column']
               );
    Ax := convert(MatrixVectorMultiply(A, X, 'outputoptions' = [])
                  , list);
    for j to p do
        for i to m do
            x[i] := B[i,j];
        end do;
        col[j] := eval(Ax);
        x := 'x';
    end do;
    rtable( 1..m, 1..p
            , ListTools:-Transpose([seq](col[j],j=1..p))
            , 'subtype' = 'Matrix'
          );
end proc:
&lt;/pre&gt;
&lt;b&gt;Timing&lt;/b&gt;

Here is a direct comparison with Matrix multiplication using the LA:-Main subpackage (to avoid the minor overhead of type checking, etc):
&lt;pre&gt;
with(LinearAlgebra):
(m,n,p) := (100,100,1000);
B := RandomMatrix(n,p):
A := RandomMatrix(m,n,density=1):
time(MatrixMultiply(A,B));
time(LinearAlgebra:-LA_Main:-MatrixMatrixMultiply(A,B,'inplace'=false,'outputoptions'=[]));
A := RandomMatrix(m,n,density=1/10):
time(MatrixMultiply(A,B));
time(LinearAlgebra:-LA_Main:-MatrixMatrixMultiply(A,B,'inplace'=false,'outputoptions'=[]));
A := RandomMatrix(m,n,density=1/100):
time(MatrixMultiply(A,B));
time(LinearAlgebra:-LA_Main:-MatrixMatrixMultiply(A,B,'inplace'=false,'outputoptions'=[]));
&lt;/pre&gt;

The times were&lt;pre&gt;
density     MatrixMultiply   LA_Main
------------------------------------
   1            5.340         4.269 
  1/10          0.910         3.949
  1/100         0.450         3.840
&lt;/pre&gt;
For dense Matrices there is a minor penalty to this technique.  For sparse Matrices there can be a considerable time saving.

&lt;b&gt;Follow up&lt;/b&gt;
I corrected a bug in the code.  A for-loop over an rtable, in the previous version, &lt;b&gt;for v in B[1..-1,j]&lt;/b&gt; is not guaranteed to loop sequentially through the elements.  It gets all the elements, but not necessarily in order of increasing index.  If the selected element were not equal to B[i,j], then an incorrect result would be returned. There was no clear change in the execution time.</itunes:summary>
      <description>The latest comments added to the Post, Sparse Matrix-Vector product using evaluation</description>
      <guid>79966</guid>
      <pubDate>Thu, 13 Apr 2006 18:50:59 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>Actually I was thinking...</title>
      <link>http://www.mapleprimes.com/posts/42963-Sparse-MatrixVector-Product-Using-Evaluation?ref=Feed:MaplePrimes:Sparse Matrix-Vector product using evaluation:Comments#comment86535</link>
      <itunes:summary>Actually I was thinking more along the lines of using this as a new matrix data structure...</itunes:summary>
      <description>The latest comments added to the Post, Sparse Matrix-Vector product using evaluation</description>
      <guid>86535</guid>
      <pubDate>Fri, 28 Apr 2006 10:32:00 Z</pubDate>
      <itunes:author>roman_pearce</itunes:author>
      <author>roman_pearce</author>
    </item>
  </channel>
</rss>