Ublas :

Subject: [ublas] Howto Create Your Own Sparse Matrix by Giving RA/IA/JA Param
From: Gundala Viswanath (gundalav_at_[hidden])
Date: 2009-01-27 09:43:48

Dear all,

Is there a way to do it with Boost's Ublas.

For example given these vectors:

//Begin Assign Var
using namespace boost::assign;
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

One would like to create this matrix:

/*
[ 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 realValue given
the corresponding (rowIndex,colIndex) as coordinate.
For example the value for last element in rowIndex and colIndex is
(2,4). Hence we insert 0.002635231 in row 2 col 4 in above matrix.

In fact other more compact represenation of above matrix
is also welcome.

Thanks and truly hope to hear from you again.

- Gundala Viswanath
Jakarta - Indonesia