Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Sparse Matrix Multiplication Problem

by neversaint (Deacon)
on Feb 02, 2009 at 02:58 UTC ( #740612=note: print w/replies, xml ) Need Help??


in reply to Re: Sparse Matrix Multiplication Problem
in thread Sparse Matrix Multiplication Problem

Dear Oshalla,
Just to let you know. I've ported your ingenious code to C++. They are so indispensable! Thanks a million again.
#include <iostream> #include <vector> #include <boost/assign/std/vector.hpp> #include <vector> #include <stdio.h> #include <stdlib.h> using namespace boost::assign; using namespace std; int main ( int arg_count, char *arg_vec[] ) { vector <double> realValue; realValue += 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; vector<int>rowIndex; rowIndex += 1, 2, 3, 4, 5, 1, 3, 1, 2, 1, 2, 1, 2; vector<int>colIndex; colIndex += 1, 2, 3, 4 ,5, 5, 3, 2, 1, 3, 3, 4, 4; vector<int>matDim; matDim += 5,5; // M always equal to N vector <double> theP; theP += 0.4, 0.2, 0.2, 0.2, 0.2; vector <double> Result; Result.assign(theP.size(), 0); for (int i= 0; i < rowIndex.size(); i++) { Result[rowIndex[i]-1] += realValue[i] * theP[colIndex[i]-1]; } // print it for (int k =0; k < Result.size(); k++){ cout << Result[k] << endl; } return 0; }


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://740612]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2020-02-19 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (80 votes). Check out past polls.

    Notices?