Re: Banded matrix storage
Rutger ter Borg <[email protected]>
| Newsgroups | gmane.comp.lib.boost.ublas |
|---|---|
| Message-ID | <[email protected]> |
On 2012-10-15 18:09, Gunter Winkler wrote: > > Could you please provide a simple test program which checks the storage > format? Then we (or maybe you) can create a new ticket. > > mfg > Gunter > thanks for the response. I've attached a test program, its output is shown below. I haven't created a ticket yet, because I would like to make sure the test is correct first. I double-checked the 'expected data()' values, to me they seem to be correct. Cheers, Rutger Example data taken from http://www.netlib.org/lapack/lug/node124.html Running banded_matrix < column_major > test Full matrix [5,5]((11,12,0,0,0),(21,22,23,0,0),(31,32,33,34,0),(0,42,43,44,45),(0,0,53,54,55)) data() of matrix 0 12 23 34 45 11 22 33 44 55 21 32 43 54 0 31 42 53 0 0 Expected data() of matrix 0 11 21 31 12 22 32 42 23 33 43 53 34 44 54 0 45 55 0 0 Running banded_matrix < row_major > test Full matrix [5,5]((11,12,0,0,0),(21,22,23,0,0),(31,32,33,34,0),(0,42,43,44,45),(0,0,53,54,55)) data() of matrix 0 11 21 31 12 22 32 42 23 33 43 53 34 44 54 0 45 55 0 0 Expected data() of matrix 0 0 11 12 0 21 22 23 31 32 33 34 42 43 44 45 53 54 55 0 _______________________________________________ ublas mailing list [email protected] http://lists.boost.org/mailman/listinfo.cgi/ublas Sent to: [email protected]
test_banded.cpp
(text/x-c++src, 2.4 KB)
#include <iostream>
#include <boost/numeric/ublas/banded.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/operation.hpp>
#include <iomanip>
using namespace boost::numeric::ublas;
int expected_index( int index, column_major tag ) {
// this is the data shown on http://www.netlib.org/lapack/lug/node124.html
// read column-by-column, aka column_major
int mapping[] = { 0, 11, 21, 31, 12, 22, 32, 42, 23, 33, 43, 53, 34, 44, 54, 0, 45, 55, 0, 0 };
return mapping[ index ];
}
int expected_index( int index, row_major tag ) {
// this is the data shown on http://www.netlib.org/lapack/lug/node124.html
// read row-by-row, aka row_major
int mapping[] = { 0, 0, 11, 12, 0, 21, 22, 23, 31, 32, 33, 34, 42, 43, 44, 45, 53, 54, 55, 0 };
return mapping[ index ];
}
template< typename Orientation >
void test_band_storage() {
int m = 5;
int n = 5;
int kl = 2;
int ku = 1;
int band_storage_size = n * (1+kl+ku);
banded_matrix< int, Orientation > test_matrix( m, n, kl, ku );
test_matrix.clear();
test_matrix( 0, 0 ) = 11;
test_matrix( 0, 1 ) = 12;
test_matrix( 1, 0 ) = 21;
test_matrix( 1, 1 ) = 22;
test_matrix( 1, 2 ) = 23;
test_matrix( 2, 0 ) = 31;
test_matrix( 2, 1 ) = 32;
test_matrix( 2, 2 ) = 33;
test_matrix( 2, 3 ) = 34;
test_matrix( 3, 1 ) = 42;
test_matrix( 3, 2 ) = 43;
test_matrix( 3, 3 ) = 44;
test_matrix( 3, 4 ) = 45;
test_matrix( 4, 2 ) = 53;
test_matrix( 4, 3 ) = 54;
test_matrix( 4, 4 ) = 55;
std::cout << "Full matrix" << std::endl;
std::cout << std::setw( 3 ) << test_matrix << std::endl;
std::cout << "data() of matrix" << std::endl;
for ( int i = 0; i < band_storage_size; ++i ) {
std::cout << test_matrix.data()[ i ] << " ";
}
std::cout << std::endl;
std::cout << "Expected data() of matrix" << std::endl;
for ( int i = 0; i < band_storage_size; ++i ) {
std::cout << expected_index( i, Orientation() ) << " ";
}
std::cout << std::endl;
}
int main() {
std::cout << "Example data taken from http://www.netlib.org/lapack/lug/node124.html" << std::endl;
std::cout << "Running banded_matrix < column_major > test" << std::endl;
test_band_storage< column_major >();
std::cout << std::endl << std::endl;
std::cout << "Running banded_matrix < row_major > test" << std::endl;
test_band_storage< row_major >();
}