| 1 |
|
|---|
| 2 | #include <iostream>
|
|---|
| 3 | #include <boost/numeric/ublas/symmetric.hpp>
|
|---|
| 4 | #include <boost/numeric/ublas/triangular.hpp>
|
|---|
| 5 | using namespace std;
|
|---|
| 6 | namespace ublas = boost::numeric::ublas;
|
|---|
| 7 |
|
|---|
| 8 | int main(int argc, char* argv[])
|
|---|
| 9 | {
|
|---|
| 10 | int sz = 4;
|
|---|
| 11 | ublas::symmetric_matrix<int, ublas::upper, ublas::column_major> UpCol (sz, sz);
|
|---|
| 12 | ublas::symmetric_matrix<int, ublas::upper, ublas::row_major> UpRow (sz, sz);
|
|---|
| 13 | ublas::symmetric_matrix<int, ublas::lower, ublas::column_major> LoCol (sz, sz);
|
|---|
| 14 | ublas::symmetric_matrix<int, ublas::lower, ublas::row_major> LoRow (sz, sz);
|
|---|
| 15 |
|
|---|
| 16 | ublas::triangular_matrix<int, ublas::upper, ublas::column_major> TrUpCol (sz, sz);
|
|---|
| 17 | ublas::triangular_matrix<int, ublas::upper, ublas::row_major> TrUpRow (sz, sz);
|
|---|
| 18 | ublas::triangular_matrix<int, ublas::lower, ublas::column_major> TrLoCol (sz, sz);
|
|---|
| 19 | ublas::triangular_matrix<int, ublas::lower, ublas::row_major> TrLoRow (sz, sz);
|
|---|
| 20 |
|
|---|
| 21 | for(int i=0; i<sz; ++i)
|
|---|
| 22 | for(int j=i; j<sz; ++j)
|
|---|
| 23 | {
|
|---|
| 24 | // Symmetric
|
|---|
| 25 | UpCol(i,j) = 10*i + j;
|
|---|
| 26 | UpRow(i,j) = 10*i + j;
|
|---|
| 27 | LoCol(i,j) = 10*i + j;
|
|---|
| 28 | LoRow(i,j) = 10*i + j;
|
|---|
| 29 | // Triangular
|
|---|
| 30 | TrUpCol(i,j) = 10*i + j;
|
|---|
| 31 | TrUpRow(i,j) = 10*i + j;
|
|---|
| 32 | TrLoCol(j,i) = 10*i + j;
|
|---|
| 33 | TrLoRow(j,i) = 10*i + j;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | //get pointers to data
|
|---|
| 37 | int* uc = &(UpCol.data()[0]);
|
|---|
| 38 | int* ur = &(UpRow.data()[0]);
|
|---|
| 39 | int* lc = &(LoCol.data()[0]);
|
|---|
| 40 | int* lr = &(LoRow.data()[0]);
|
|---|
| 41 | int* tuc = &(TrUpCol.data()[0]);
|
|---|
| 42 | int* tur = &(TrUpRow.data()[0]);
|
|---|
| 43 | int* tlc = &(TrLoCol.data()[0]);
|
|---|
| 44 | int* tlr = &(TrLoRow.data()[0]);
|
|---|
| 45 |
|
|---|
| 46 | // upper, column_major
|
|---|
| 47 | // storage should be: 0 1 11 2 12 22 3 13 23 33
|
|---|
| 48 | int uc_correct[] = {0, 1, 11, 2, 12, 22, 3, 13, 23, 33};
|
|---|
| 49 |
|
|---|
| 50 | // upper, row_major
|
|---|
| 51 | // storage should be: 0 1 2 3 11 12 13 22 23 33
|
|---|
| 52 | int ur_correct[] = {0, 1, 2, 3, 11, 12, 13, 22, 23, 33};
|
|---|
| 53 |
|
|---|
| 54 | // lower, column_major
|
|---|
| 55 | // storage should be: 0 1 2 3 11 12 13 22 23 33
|
|---|
| 56 | int lc_correct[] = {0, 1, 2, 3, 11, 12, 13, 22, 23, 33};
|
|---|
| 57 |
|
|---|
| 58 | // lower, row_major
|
|---|
| 59 | // storage should be: 0 1 11 2 12 22 3 13 23 33
|
|---|
| 60 | int lr_correct[] = {0, 1, 11, 2, 12, 22, 3, 13, 23, 33};
|
|---|
| 61 |
|
|---|
| 62 | // Test Symmetric
|
|---|
| 63 | for(int i=0; i<sz*(sz+1)/2; ++i)
|
|---|
| 64 | if(uc[i] != uc_correct[i])
|
|---|
| 65 | {
|
|---|
| 66 | cout << "Storage error (Symmetric, Upper, Column major)" << endl;
|
|---|
| 67 | break;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | for(int i=0; i<sz*(sz+1)/2; ++i)
|
|---|
| 71 | if(ur[i] != ur_correct[i])
|
|---|
| 72 | {
|
|---|
| 73 | cout << "Storage error (Symmetric, Upper, Row major)" << endl;
|
|---|
| 74 | break;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | for(int i=0; i<sz*(sz+1)/2; ++i)
|
|---|
| 78 | if(lc[i] != lc_correct[i])
|
|---|
| 79 | {
|
|---|
| 80 | cout << "Storage error (Symmetric, Lower, Column major)" << endl;
|
|---|
| 81 | break;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | for(int i=0; i<sz*(sz+1)/2; ++i)
|
|---|
| 85 | if(lr[i] != lr_correct[i])
|
|---|
| 86 | {
|
|---|
| 87 | cout << "Storage error (Symmetric, Lower, Row major)" << endl;
|
|---|
| 88 | break;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // Test Triangular
|
|---|
| 92 | for(int i=0; i<sz*(sz+1)/2; ++i)
|
|---|
| 93 | if(tuc[i] != uc_correct[i])
|
|---|
| 94 | {
|
|---|
| 95 | cout << "Storage error (Triangular, Upper, Column major)" << endl;
|
|---|
| 96 | break;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | for(int i=0; i<sz*(sz+1)/2; ++i)
|
|---|
| 100 | if(tur[i] != ur_correct[i])
|
|---|
| 101 | {
|
|---|
| 102 | cout << "Storage error (Triangular, Upper, Row major)" << endl;
|
|---|
| 103 | break;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | for(int i=0; i<sz*(sz+1)/2; ++i)
|
|---|
| 107 | if(tlc[i] != lc_correct[i])
|
|---|
| 108 | {
|
|---|
| 109 | cout << "Storage error (Triangular, Lower, Column major)" << endl;
|
|---|
| 110 | break;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | for(int i=0; i<sz*(sz+1)/2; ++i)
|
|---|
| 114 | if(tlr[i] != lr_correct[i])
|
|---|
| 115 | {
|
|---|
| 116 | cout << "Storage error (Triangular, Lower, Row major)" << endl;
|
|---|
| 117 | break;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 | return 0;
|
|---|
| 122 | }
|
|---|