Dear Masters,
Given this sparse matrix representation:
my @realval = ( 0.994704478, 0.989459074, 0.994717023, 1.000000000, 1.000000000, 0.002647761, 0.005282977, 0.000882587, 0.005270463, 0.000882587, 0.002635231, 0.000882587, 0.002635231,); my @row_index = qw( 1 2 3 4 5 1 3 1 2 1 2 1 2); my @col_index = qw(1 2 3 4 5 5 3 2 1 3 3 4 4); my @mat_dim = (5,5); # M always equal to N
I have no problem generating the actual matrix like this:
my @actual_mat = ( [ 0.994704478, 0.000882587, 0.000882587, 0.000882587, 0.002647761], [ 0.005270463, 0.989459074, 0.002635231, 0.002635231, 0.000000000], [ 0.000000000, 0.000000000, 0.005282977, 0.000000000, 0.000000000]. [ 0.000000000, 0.000000000, 0.000000000, 1.000000000, 0.000000000], [ 0.000000000, 0.000000000, 0.000000000, 0.000000000, 1.000000000] ); # It is simply done by assigning the value in @real_value given # the corresponding (@row,@index) as coordinate; # e.g. to assign $real_value[-1] into # $actual_mat[$row_index[-1]-1,$col_index[-1]-1);
My question is: can we do matrix multiplication by just using sparse matrix representation above instead of @actual_mat.
Given the multiplicator
my @p = (0.4,0.2,0.2,0.2,0.2);
we expect to get from p * SparseM
my $result = [ 0.3989409, 0.2010541, 0.2000000, 0.2000000, 0.2000000, ];


---
neversaint and everlastingly indebted.......

In reply to Sparse Matrix Multiplication Problem by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.