Here it is some code that should do the trick. I tested it with boost 1.32, 1.37 and 1.38. It fails on 1.37 and 1.38.
-----------------------------------------------------------------------------------------
#include <iostream>
#include <boost/numeric/ublas/symmetric.hpp>
using namespace std;
namespace ublas = boost::numeric::ublas;
int main(int argc, char* argv[])
{
int sz = 4;
ublas::symmetric_matrix<int, ublas::upper, ublas::column_major> UpCol (sz, sz);
ublas::symmetric_matrix<int, ublas::upper, ublas::row_major> UpRow (sz, sz);
ublas::symmetric_matrix<int, ublas::lower, ublas::column_major> LoCol (sz, sz);
ublas::symmetric_matrix<int, ublas::lower, ublas::row_major> LoRow (sz, sz);
for(int i=0; i<sz; ++i)
{
for(int j=i; j<sz; ++j)
{
UpCol(i,j) = 10*i + j;
UpRow(i,j) = 10*i + j;
LoCol(i,j) = 10*i + j;
LoRow(i,j) = 10*i + j;
}
}
//get pointers to data
int* uc = &(UpCol.data()[0]);
int* ur = &(UpRow.data()[0]);
int* lc = &(LoCol.data()[0]);
int* lr = &(LoRow.data()[0]);
// upper, column_major
// storage should be: 0 1 11 2 12 22 3 13 23 33
int uc_correct[] = {0, 1, 11, 2, 12, 22, 3, 13, 23, 33};
// upper, row_major
// storage should be: 0 1 2 3 11 12 13 22 23 33
int ur_correct[] = {0, 1, 2, 3, 11, 12, 13, 22, 23, 33};
// lower, column_major
// storage should be: 0 1 2 3 11 12 13 22 23 33
int lc_correct[] = {0, 1, 2, 3, 11, 12, 13, 22, 23, 33};
// lower, row_major
// storage should be: 0 1 11 2 12 22 3 13 23 33
int lr_correct[] = {0, 1, 11, 2, 12, 22, 3, 13, 23, 33};
// Test
for(int i=0; i<sz*(sz+1)/2; ++i)
if(uc[i] != uc_correct[i])
{
cout << "Storage error (Upper, Column major)" << endl;
break;
}
for(int i=0; i<sz*(sz+1)/2; ++i)
if(ur[i] != ur_correct[i])
{
cout << "Storage error (Upper, Row major)" << endl;
break;
}
for(int i=0; i<sz*(sz+1)/2; ++i)
if(lc[i] != lc_correct[i])
{
cout << "Storage error (Lower, Column major)" << endl;
break;
}
for(int i=0; i<sz*(sz+1)/2; ++i)
if(lr[i] != lr_correct[i])
{
cout << "Storage error (Lower, Row major)" << endl;
break;
}
return 0;
}
-----------------------------------------------------------------------------------------
Tiago Requeijo schrieb:
> I'm having a problem with row and column major in symmetric matrices.It would be very helpful if you could write a short example program that
> I'm probably not understanding correctly how the storage takes place
> in memory. I assumed upper+column_major storage was the same as
> lower+row_major. Here's an example:
>
compares the actual storage with the expected one. I can add this
program to the set of unit tests and fix the problem.
mfg
Gunter
_______________________________________________
ublas mailing list
ublas@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/ublas